|
2 | 2 | Customizing
|
3 | 3 | ===========
|
4 | 4 |
|
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 |
7 | 10 | will need to write a custom login form.
|
8 | 11 |
|
9 | 12 | Custom login form
|
@@ -76,3 +79,46 @@ API documentation
|
76 | 79 |
|
77 | 80 | .. autoclass:: mailauth.forms.BaseLoginForm
|
78 | 81 | :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: |
0 commit comments