Django-User-Email-Extension
===========================
[![](https://img.shields.io/pypi/l/django-user-email-extension.svg?colorB=blue)](https://pypi.org/project/django-user-email-extension/)
[![](https://img.shields.io/pypi/v/django-user-email-extension.svg)](https://pypi.org/project/django-user-email-extension/)
[![codecov](https://codecov.io/gh/ArieLevs/Django-User-Email-Extension/branch/master/graph/badge.svg?token=BLJTJKHCVY)](https://codecov.io/gh/ArieLevs/Django-User-Email-Extension)
[![](https://img.shields.io/pypi/pyversions/django-user-email-extension.svg)](https://pypi.org/project/django-user-email-extension/)
[![](https://img.shields.io/pypi/djversions/django-user-email-extension.svg)](https://pypi.org/project/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:
```python
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:
```shell script
python3 manage.py makemigrations
python3 manage.py migrate
```
Usage Example
-------------
use:
```python
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)
```python
# 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:
```python
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())})
)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/ArieLevs/Django-User-Email-Extension",
"name": "django-user-email-extension",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Arie Lev",
"author_email": "levinson.arie@gmail.com",
"download_url": null,
"platform": null,
"description": "Django-User-Email-Extension\n===========================\n[![](https://img.shields.io/pypi/l/django-user-email-extension.svg?colorB=blue)](https://pypi.org/project/django-user-email-extension/)\n[![](https://img.shields.io/pypi/v/django-user-email-extension.svg)](https://pypi.org/project/django-user-email-extension/)\n[![codecov](https://codecov.io/gh/ArieLevs/Django-User-Email-Extension/branch/master/graph/badge.svg?token=BLJTJKHCVY)](https://codecov.io/gh/ArieLevs/Django-User-Email-Extension)\n[![](https://img.shields.io/pypi/pyversions/django-user-email-extension.svg)](https://pypi.org/project/django-user-email-extension/)\n[![](https://img.shields.io/pypi/djversions/django-user-email-extension.svg)](https://pypi.org/project/django-user-email-extension/)\n\nDjango application that extends User module, and provides email verification process.\n\nInstall\n-------\n`pip install django-user-email-extension`\n\nAdd to installed apps, and email provider details:\n\n```python\nimport os\n\nINSTALLED_APPS = [\n # ...\n 'django_user_email_extension',\n # ...\n]\n\n###############################\n# Define the default user model \n###############################\nAUTH_USER_MODEL = 'django_user_email_extension.User'\n\n# if set then users age will be validated for minimal age (in years)\nUSER_MINIMAL_AGE = int(os.environ.get('USER_MINIMAL_AGE', None))\n\n# if set, used address cannot be saved with non verified phone number\nENFORCE_USER_ADDRESS_VERIFIED_PHONE = int(os.environ.get('ENFORCE_USER_ADDRESS_VERIFIED_PHONE', False)) \n\nEMAIL_USE_TLS = True\nEMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'\nEMAIL_HOST = os.environ.get('email_host')\nEMAIL_PORT = os.environ.get('email_port')\nEMAIL_HOST_USER = os.environ.get('email_username')\nEMAIL_HOST_PASSWORD = os.environ.get('email_password')\n\n# optional, if not set, verification email will never expire.\nDJANGO_EMAIL_VERIFIER_EXPIRE_TIME = 24 # In Hours\n```\n\nRun migrations:\n```shell script\npython3 manage.py makemigrations\npython3 manage.py migrate\n```\n\nUsage Example\n-------------\nuse:\n\n```python\nfrom django.contrib.auth import get_user_model\n\nUser = get_user_model()\n\nuser_object = User.objects.create_user(\n email='EMAIL',\n password='PASSWORD'\n)\n\n# .save() must be called\n# this option has been modified so extra action could be executed before final user creation\nuser_object.save()\n\n# user is a Django User object\nuser_object.create_verification_email()\n\n# Send the verification email\nuser_object.send_verification_email(\n subject=subject,\n body=body, # *** view body example below to contain the unique UUID\n from_mail=EMAIL_HOST_USER\n)\n```\nThen when user click the link (from the body sent via email)\n```python\n# make sure url is getting a uuid key in urls.py\npath('verify_account/<uuid:verification_uuid>/', views.VerifyEmailUUIDView.as_view(), name='verify_account')\n\n# initiate verification process on the return view\nver_uuid = DjangoEmailVerifier.objects.get(verification_uuid='UUID_FROM_REQUEST')\nver_uuid.activate_user()\n```\n\nThe confirmation uuid can be sent as part of the body for example:\n```python\nbody = 'Follow this link to verify your account: https://nalkins.cloud{}'.format(\n reverse('verify_account', kwargs={'verification_uuid': str(user_object.get_uuid_of_email())})\n)\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "User model extender for django",
"version": "2.6.1",
"project_urls": {
"Homepage": "https://github.com/ArieLevs/Django-User-Email-Extension"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4f86620e524cf1c9fad778d19974cb4c645432a9ba7af8b0428e0a4e9ba9f7af",
"md5": "5a073cae78ee85b33cc898da591312ee",
"sha256": "1aa6faaa58ecbe3e18d6f0428b0d6e915841b43fd422d82064d9b9fa25c8570f"
},
"downloads": -1,
"filename": "django_user_email_extension-2.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5a073cae78ee85b33cc898da591312ee",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 35895,
"upload_time": "2024-09-13T13:56:54",
"upload_time_iso_8601": "2024-09-13T13:56:54.315093Z",
"url": "https://files.pythonhosted.org/packages/4f/86/620e524cf1c9fad778d19974cb4c645432a9ba7af8b0428e0a4e9ba9f7af/django_user_email_extension-2.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-13 13:56:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ArieLevs",
"github_project": "Django-User-Email-Extension",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "django-user-email-extension"
}