Skip to content

Commit d72af77

Browse files
committed
Improve documentation
1 parent abe2491 commit d72af77

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

README.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ Installation
3838

3939
Run this command to install ``django-mail-auth``::
4040

41-
pip install django-mail-auth
42-
41+
python3 -m pip install django-mail-auth[wagtail]
4342

4443
Setup
4544
-----
@@ -50,8 +49,10 @@ First add ``mailauth`` to you installed apps::
5049
# Django's builtin apps…
5150

5251
'mailauth',
52+
5353
'mailauth.contrib.admin', # optional
5454
'mailauth.contrib.user', # optional
55+
5556
# optional, must be included before "wagtail.admin"
5657
'mailauth.contrib.wagtail',
5758

@@ -65,8 +66,14 @@ with token based authentication too.
6566
``mailauth.contrib.user`` is optional and provides a new Django User model.
6667
The new User model needs to be enabled via the ``AUTH_USER_MODEL`` setting::
6768

69+
# This setting should be either "EmailUser" or
70+
# any custom subclass of "AbstractEmailUser"
6871
AUTH_USER_MODEL = 'mailauth_user.EmailUser'
6972

73+
# optional, Wagtail only
74+
WAGTAILUSERS_PASSWORD_ENABLED = False
75+
76+
7077
Next you will need to add the new authentication backend::
7178

7279
AUTHENTICATION_BACKENDS = (
@@ -89,6 +96,7 @@ Last but not least, go to your URL root config ``urls.py`` and add the following
8996

9097
urlpatterns = [
9198
path('accounts/', include('mailauth.urls')),
99+
92100
# optional, must be before "wagtail.admin.urls"
93101
path('', include('mailauth.contrib.wagtail.urls')),
94102
]

docs/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@
2828
'django': ('https://docs.djangoproject.com/en/stable/',
2929
'https://docs.djangoproject.com/en/stable/_objects/'),
3030
}
31+
32+
33+
autodoc_default_options = {
34+
'show-inheritance': True,
35+
}

docs/customizing.rst

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
Customizing
33
===========
44

5-
Django Mail Auth can be easily extend. Besides template adaptations it is
6-
possible to send send different messages like SMS. To make those changes you
5+
Custom login message (like SMS)
6+
_______________________________
7+
8+
Django Mail Auth can be easily extended. Besides template adaptations it is
9+
possible to send different messages like SMS. To make those changes, you
710
will need to write a custom login form.
811

912
Custom login form
@@ -76,3 +79,46 @@ API documentation
7679

7780
.. autoclass:: mailauth.forms.BaseLoginForm
7881
:members:
82+
83+
Custom User Model
84+
_________________
85+
86+
For convenience, Django Mail Auth provides a
87+
:class:`EmailUser<mailauth.contrib.user.models.EmailUser>` which is almost
88+
identical to Django's built in :class:`User<django.contrib.auth.models.User>`
89+
but without the :attr:`password<django.contrib.auth.models.User.password>`
90+
and :attr:`username<django.contrib.auth.models.User.username>` field.
91+
The :attr:`email<mailauth.contrib.user.models.AbstractEmailUser.email>`
92+
field serves as a username and is – different to Django's User –
93+
unique and case insensitive.
94+
95+
Implementing a custom User model
96+
--------------------------------
97+
98+
.. code-block:: python
99+
100+
from mailauth.contrib.user.models import AbstractEmailUser
101+
from phonenumber_field.modelfields import PhoneNumberField
102+
103+
104+
class SMSUser(AbstractEmailUser):
105+
phone_number = phone = PhoneNumberField(_("phone number"), unique=True, db_index=True)
106+
107+
class Meta(AbstractEmailUser.Meta):
108+
verbose_name = _("user")
109+
verbose_name_plural = _("users")
110+
swappable = "AUTH_USER_MODEL"
111+
112+
.. note:: Do not forget to adjust your ``AUTH_USER_MODEL`` to correct ``app_label.ModelName``.
113+
114+
API documentation
115+
-----------------
116+
117+
.. autoclass:: mailauth.contrib.user.models.AbstractEmailUser
118+
:members:
119+
120+
.. autoattribute:: mailauth.contrib.user.models.AbstractEmailUser.email
121+
.. autoattribute:: mailauth.contrib.user.models.AbstractEmailUser.session_salt
122+
123+
.. autoclass:: mailauth.contrib.user.models.EmailUser
124+
:members:

mailauth/contrib/user/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ class AbstractEmailUser(AbstractUser):
4242
USERNAME_FIELD = 'email'
4343
REQUIRED_FIELDS = []
4444

45-
email = CIEmailField(_('email address'), unique=True, db_index=True)
4645
username = None
4746
password = None
47+
48+
email = CIEmailField(_('email address'), unique=True, db_index=True)
49+
"""The field is unique and case insensitive to serve as a better username."""
50+
4851
session_salt = models.CharField(
4952
max_length=12, editable=False,
5053
default=get_random_string,
5154
)
55+
"""Salt for the session hash replacing the password in this function."""
5256

5357
def has_usable_password(self):
5458
return False

0 commit comments

Comments
 (0)