A custom user model for django authentication
Project description
Django custom user model
A Custom User model for authentication
Requirement
- Python (+3.5)
- Django (+2.0)
Installation
Install using pip
pip install django-custom-user-models
Add to INSTALLED_APPS
setting
INSTALLED_APPS = {
...
'CustomAuth',
...
}
Set AUTH_USER_MODEL
setting before first migrate
AUTH_USER_MODEL = 'CustomAuth.User'
Migrate apps
py manage.py migrate
Usage
Status Handler
Add handler
to yourproject/urls.py
from CustomAuth.urls import handler400, handler401, handler403, handler404, handler500
Authentication template
Add to settings.py
profile url
USER_PROFILE_URL = '<your user profile url>' # default '/profile/'
login redirect url
LOGIN_REDIRECT_URL = '<your login redirect>' # default '/account/profile/'
logout redirect url
LOGOUT_REDIRECT = '<your logout redirect>' # default '/'
signup successfully redirect
SIGNUP_SUCCESSFULLY_URL = '<your signup successfully redirect url>' # default '/profile/'
verification successfully redirect
VERIFY_SUCCESSFULLY = '<your verify successfully redirect url>' # default '/profile/'
verification failed redirect
VERIFY_FAILED = '<your verify failed redirect url>' # default 'Verification link is invalid!'
Email verification config
For verify email you should config email smtp server, example(gmail):
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'your name@gmail.com'
EMAIL_HOST_PASSWORD = 'your password'
EMAIL_USE_TSL = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_FROM = EMAIL_HOST_USER
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
sms verification config
KAVENEGAR_API = '<your api>'
RECEPTOR = '<your receptor>'
Magic Link
Use magic link for auto authentication user.
Add to settings.py
AUTHENTICATION_BACKENDS = (
# ...
'CustomAuth.backends.MagicLinkBackend', # magic backend
# ...
)
MIDDLEWARE = [
# ...
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# ...
'CustomAuth.middleware.magic.MagicMiddleware', # Magic middleware
# ...
]
Run django shell
in root directory (windows)
py manage.py shell
linux
$ python3 manage.py shell
in shell
from CustomAuth.models import User
user = User.objects.create(cellphone='<valid email>', password='<your password>')
user.get_magic_link
JWT Authentication
For get new jwt token with 2 month expire time.
curl -H "jwt-authentication:<your token>" -X GET <your host>/jwt/new
for logged in user.
curl -X GET <your host>/jwt/new
For authenticate with jwt use your token.
curl -H "jwt-authentication:<your token>" -X GET <your host>/<relative path>
Multi database handling
For save user in multiple databases:
AUTH_DATABASES = ['first database name', 'second database name', ... ]
Table show
Add django_tables2
to INSTALLED_APPS and make sure that django.template.context_processors.reques
is added to the context_processors in your template setting OPTIONS
https://<your_domain>/user/list/ # redirect to all user
https://<your_domain>/user/list/all # all user
https://<your_domain>/user/list/superuser # superuser
https://<your_domain>/user/list/staff # staff
Versioning
This project follows Semantic Versioning 2.0.0.
License
This project follows the BSD license. See the LICENSE for details.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file django-custom-user-models-0.2.5.tar.gz
.
File metadata
- Download URL: django-custom-user-models-0.2.5.tar.gz
- Upload date:
- Size: 371.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 249dfa7c97a580000e937cf0c85207e8212b56c727b2def34b0ebbb0fb49d157 |
|
MD5 | 75a04e37279989f294c44e0895a72f5e |
|
BLAKE2b-256 | 6dff8fa5cfe72e324cff791f96d75336c31dc407bc091a8261e4d44522ffb307 |
File details
Details for the file django_custom_user_models-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: django_custom_user_models-0.2.5-py3-none-any.whl
- Upload date:
- Size: 616.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a06cf8f1ace5a10d5f10c6658d664cf52acd07d46d3ae839f19ac2361930d6 |
|
MD5 | cff00fcdae351972099db9575ae2ee07 |
|
BLAKE2b-256 | 4a0d79a1a0eca023b5b1e3e0b668deca22ae541a7ff8f2526b997cb174fccbea |