Skip to main content

Django-User-Email-Extension

codecov

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.activate_user()

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())})
)

Metadata

Release files for django-user-email-extension 2.6.1

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

Built distribution (wheel)

Table of built distributions (wheels) for django-user-email-extension 2.6.1
File Interpreter ABI Platform
django_user_email_extension-2.6.1-py3-none-any.whl Python 3 none any Details

Release files / django_user_email_extension-2.6.1-py3-none-any.whl

Download URL django_user_email_extension-2.6.1-py3-none-any.whl
Size 35.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1aa6faaa58ecbe3e18d6f0428b0d6e915841b43fd422d82064d9b9fa25c8570f
BLAKE2b-256 checksum
How to use checksums
4f86620e524cf1c9fad778d19974cb4c645432a9ba7af8b0428e0a4e9ba9f7af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

2.6.1 This release

1 release file

2.5.1

1 release file

2.4.2

1 release file

2.2.5

2 release files

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.0.1

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.1.2

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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