| 1 |
Phone |
| 2 |
===== |
| 3 |
|
| 4 |
Installation |
| 5 |
************ |
| 6 |
|
| 7 |
In addition to following the overall instructions, pay attention to the |
| 8 |
following in the ``settings.py`` of your project:: |
| 9 |
|
| 10 |
# Make sure that the login methods includes "phone" as a method. |
| 11 |
ACCOUNT_LOGIN_METHODS = {"phone", "email"} |
| 12 |
|
| 13 |
# Add a required phone field to the signup fields. |
| 14 |
# ACCOUNT_SIGNUP_FIELDS = [ |
| 15 |
'phone*', |
| 16 |
'email*' # Can be left out if you want to only use 'phone'. |
| 17 |
] |
| 18 |
|
| 19 |
# You will need to provide methods for storing phone numbers, and |
| 20 |
# sending SMS messages in a custom adapter. |
| 21 |
ACCOUNT_ADAPTER = 'project.users.adapter.MyAccountAdapter' |
| 22 |
|
| 23 |
|
| 24 |
Configuration |
| 25 |
============= |
| 26 |
|
| 27 |
Available settings: |
| 28 |
|
| 29 |
``ACCOUNT_PHONE_VERIFICATION_ENABLED`` (default: ``True``) |
| 30 |
Whether or not mandatory verification of phone numbers during login/signup takes place. |
| 31 |
|
| 32 |
``ACCOUNT_PHONE_VERIFICATION_MAX_ATTEMPTS`` (default: ``3``) |
| 33 |
This setting controls the maximum number of attempts the user has at inputting |
| 34 |
a valid code. |
| 35 |
|
| 36 |
``ACCOUNT_PHONE_VERIFICATION_TIMEOUT`` (default: ``900``) |
| 37 |
The code that is sent has a limited life span. It expires this many seconds after |
| 38 |
which it was sent. |
| 39 |
|
| 40 |
``ACCOUNT_PHONE_VERIFICATION_SUPPORTS_CHANGE`` (default: ``False``) |
| 41 |
Whether or not the phone number can be changed after signup at the |
| 42 |
phone number verification stage. |
| 43 |
|
| 44 |
**Warning**: the warning related to enumeration prevent over at |
| 45 |
``ACCOUNT_EMAIL_VERIFICATION_SUPPORTS_CHANGE`` holds here as well. |
| 46 |
|
| 47 |
``ACCOUNT_PHONE_VERIFICATION_SUPPORTS_RESEND`` (default: ``False``) |
| 48 |
Whether or not the user can request a new phone number verification code. |
| 49 |
|
| 50 |
``ACCOUNT_PHONE_VERIFICATION_CODE_FORMAT`` (default: ``settings.ALLAUTH_USER_CODE_FORMAT``) |
| 51 |
Controls the format of the verification code. |
| 52 |
|
| 53 |
|
| 54 |
Form Fields |
| 55 |
*********** |
| 56 |
|
| 57 |
For presenting a phone number form field to the user a basic ``<input type="tel">`` field |
| 58 |
is used that requires input in E164 format. There are various external projects |
| 59 |
that offer more elaborate phone number input fields. You can switch over to |
| 60 |
using the fields provided by those projects, or, tweak the phone number |
| 61 |
validaton logic, by overriding the following adapter methods: |
| 62 |
|
| 63 |
.. autoclass:: allauth.account.adapter.DefaultAccountAdapter |
| 64 |
|
| 65 |
.. automethod:: phone_form_field |
| 66 |
.. automethod:: clean_phone |
| 67 |
|
| 68 |
|
| 69 |
Database Models |
| 70 |
*************** |
| 71 |
|
| 72 |
Out of the box, there are no models provided intended to store the phone numbers |
| 73 |
of users. It is up to the developer to decide where phone numbers are to be |
| 74 |
stored, for example, on a custom user model, or, on a separate `Phone` model of |
| 75 |
its own. Once those the models are setup, the following adapter methods need to |
| 76 |
be populated so that the models will be used: |
| 77 |
|
| 78 |
.. autoclass:: allauth.account.adapter.DefaultAccountAdapter |
| 79 |
|
| 80 |
.. automethod:: get_phone |
| 81 |
.. automethod:: set_phone |
| 82 |
.. automethod:: set_phone_verified |
| 83 |
.. automethod:: get_user_by_phone |
| 84 |
|
| 85 |
|
| 86 |
Sending SMS Messages |
| 87 |
******************** |
| 88 |
|
| 89 |
For sending SMS messages, various external providers and packages are |
| 90 |
available. You can integrate those by overriding the following adapter method: |
| 91 |
|
| 92 |
.. autoclass:: allauth.account.adapter.DefaultAccountAdapter |
| 93 |
|
| 94 |
.. automethod:: send_verification_code_sms |
| 95 |
.. automethod:: send_unknown_account_sms |