Skip to main content

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>'

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.

Metadata

Release files for django-custom-user-models 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-custom-user-models 0.2.5
File Size Uploaded Provenance Actions
django-custom-user-models-0.2.5.tar.gz 371.1 kB Without provenance Details for django-custom-user-models-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-custom-user-models 0.2.5
File Interpreter ABI Platform Actions
django_custom_user_models-0.2.5-py3-none-any.whl Python 3 none any Details for django_custom_user_models-0.2.5-py3-none-any.whl

Total release size: 987.2 kB

Release files / django-custom-user-models-0.2.5.tar.gz

Download URL django-custom-user-models-0.2.5.tar.gz
Size 371.1 kB
Tags Source
SHA-256 checksum
How to use checksums
249dfa7c97a580000e937cf0c85207e8212b56c727b2def34b0ebbb0fb49d157
BLAKE2b-256 checksum
How to use checksums
6dff8fa5cfe72e324cff791f96d75336c31dc407bc091a8261e4d44522ffb307
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / django_custom_user_models-0.2.5-py3-none-any.whl

Download URL django_custom_user_models-0.2.5-py3-none-any.whl
Size 616.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1a06cf8f1ace5a10d5f10c6658d664cf52acd07d46d3ae839f19ac2361930d6
BLAKE2b-256 checksum
How to use checksums
4a0d79a1a0eca023b5b1e3e0b668deca22ae541a7ff8f2526b997cb174fccbea
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for django-custom-user-models 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page