User model extender for django
Project description
Django-User-Email-Extension
Django application that extends User module, and provides email verification process.
Install
pip install django-user-email-extension
Add to installed apps, and email provider details:
import os
INSTALLED_APPS = [
# ...
'django_user_email_extension',
# ...
]
###############################
# Define the default user model
###############################
AUTH_USER_MODEL = 'django_user_email_extension.User'
# if set then users age will be validated for minimal age (in years)
USER_MINIMAL_AGE = int(os.environ.get('USER_MINIMAL_AGE', None))
# if set, used address cannot be saved with non verified phone number
ENFORCE_USER_ADDRESS_VERIFIED_PHONE = int(os.environ.get('ENFORCE_USER_ADDRESS_VERIFIED_PHONE', False))
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = os.environ.get('email_host')
EMAIL_PORT = os.environ.get('email_port')
EMAIL_HOST_USER = os.environ.get('email_username')
EMAIL_HOST_PASSWORD = os.environ.get('email_password')
# optional, if not set, verification email will never expire.
DJANGO_EMAIL_VERIFIER_EXPIRE_TIME = 24 # In Hours
Run migrations:
python3 manage.py makemigrations
python3 manage.py migrate
Usage Example
use:
from django.contrib.auth import get_user_model
User = get_user_model()
user_object = User.objects.create_user(
email='EMAIL',
password='PASSWORD'
)
# .save() must be called
# this option has been modified so extra action could be executed before final user creation
user_object.save()
# user is a Django User object
user_object.create_verification_email()
# Send the verification email
user_object.send_verification_email(
subject=subject,
body=body, # *** view body example below to contain the unique UUID
from_mail=EMAIL_HOST_USER
)
Then when user click the link (from the body sent via email)
# make sure url is getting a uuid key in urls.py
path('verify_account/<uuid:verification_uuid>/', views.VerifyEmailUUIDView.as_view(), name='verify_account')
# initiate verification process on the return view
ver_uuid = DjangoEmailVerifier.objects.get(verification_uuid='UUID_FROM_REQUEST')
ver_uuid.verify_record()
The confirmation uuid can be sent as part of the body for example:
body = 'Follow this link to verify your account: https://nalkins.cloud{}'.format(
reverse('verify_account', kwargs={'verification_uuid': str(user_object.get_uuid_of_email())})
)
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
Close
Hashes for django-user-email-extension-2.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34f7f3b0da2553ac082953cd0cb26a4a2b7541caea46f4ee00d98aec7b8cd8f7 |
|
MD5 | 2c3829da3e833589c5be8a4338694d71 |
|
BLAKE2b-256 | 9e50c78f233f75d3778760fdd922594ba2156594f0fc0706fcbd239010d5a704 |
Close
Hashes for django_user_email_extension-2.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5af96a9b49a419295410a574fab9fd0fb9a8372917723158ad4528ef00849544 |
|
MD5 | 0e4e6f642f99fccb7c843e21a86cd621 |
|
BLAKE2b-256 | cf201bd85cec5340fe6895015b25196c1adc8727232a781512854149d115609d |