A Django app to authenticate and register user using phone/email/username.
Project description
django-phone-auth
A Django app to authenticate and register users using phone/email/username. It uses the default User Model.
Installation
pip install django-phone-auth
Add 'phone_auth' in INSTALLED_APPS.
INSTALLED_APPS = [
...
'phone_auth',
...
]
Add 'phone_auth.backend.CustomAuthBackend' in AUTHENTICATION_BACKENDS.
AUTHENTICATION_BACKENDS = [
...
# Needed to login by username in Django admin, regardless of `django-phone-auth`
'django.contrib.auth.backends.ModelBackend',
# `django-phone-auth` specific authentication methods, such as login by phone/email/username.
'phone_auth.backend.CustomAuthBackend',
...
]
Add 'path('accounts/', include('phone_auth.urls'))' in urls.py
urlpatterns = [
...
path('accounts/', include('phone_auth.urls')),
...
]
Now run command -
python manage.py migrate
Usage
On registration page ('/accounts/register/') by default first_name, last_name, email and username is optional. These can be set to required by adding following variables in settings.py
REGISTER_USERNAME_REQUIRED = True
REGISTER_EMAIL_REQUIRED = True
REGISTER_FNAME_REQUIRED = True
REGISTER_LNAME_REQUIRED = True
On login page ('/accounts/login/') by default user can only login with phone. To allow login through username/email/phone add the following in settings.py
LOGIN_METHODS = {'email', 'phone', 'username'}
Note: LOGIN_METHODS can't be empty
Override templates
To override templates, create a folder 'templates' in the base directory (the directory which contains the 'manage.py' file). Now add the path to this folder in settings.py. It will look like this -
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Now in templates folder, you can create file 'register.html', 'login.html' and templates will get overriden.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_phone_auth-0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1b9544d74d06d9c266f5fa74e70b3f542f2e613a6bfe0663b48100b136b519b |
|
MD5 | b96f406178ed9d5522d032c873b17af9 |
|
BLAKE2b-256 | 4d79acc5a6c0b7a885a8da4af171af17c3dc6cf1c52d3ace870d3f231d3c4a9a |