Skip to main content

# emailuser is a Django Custom User Module

#Package Version: 1.x emailuser makes it easy to use email address as your identification token instead of a username. emailuser is a custom Django user model (extends AbstractBaseUser) so it takes a tiny amount of effort to use.

The only difference between emailuser and the vanilla Django User is email address is the USERNAME_FIELD (and username also exist, If you not give it in create_user it will generate a random 12 char unique string as username).

emailuser supports Django 2.* to 3.*

When to use emailuser ?

When you need email as username in django project.

Why I have created emailuser?

I have created this custom user package for my university final project where I need to create user using university email also all user must have a profile link using unique username.

I think this package can help me in other application development also it can help other people too. That is why I published it. If you love it you can donate.

Install and setup

  1. Install with pip:
  #Django 2.x, or 3.x

  pip install django-emailuser 
  1. Add emailuser to your INSTALLED_APPS setting:
  
  INSTALLED_APPS = [
      ...
      'emailuser',
  ]
  
  1. Specify the custom model as the default user model for your project using the AUTH_USER_MODEL setting in your setting:
  AUTH_USER_MODEL = "emailuser.User"
  1. Run migrations (Don't do any migrate before emailuser makemigrations).

if you have tables referencing Django User model, you will have to delete those table and migrations, then re-migrate. This will ensure everything is set up correctly from the beginning.

 python manage.py makemigrations emailuser
 python manage.py migrate
  1. Instead of referring to User directly, you should reference the user model using django.contrib.auth.get_user_model()

When you define a foreign key or many-to-many relations to the User model, you should specify the custom model using the AUTH_USER_MODEL setting.

from django.conf import settings
from django.db import models

class Profile(models.Model):
    user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
)

7: For Django Rest Framework

from django.contrib.auth import get_user_model
class  UserSerializer(serializers.ModelSerializer):
  class  Meta:
    model = get_user_model()
    fields = ('id', 'email', 'username', 'first_name', 'last_name')

8: Helper Functions

from django.contrib.auth import get_user_model

get_user_model().objects.get_full_name()  # Return Full Name

/*
For sending email you must configure smtp setting like below
  EMAIL_HOST = 'hostname'
EMAIL_PORT = port
EMAIL_HOST_USER = 'username'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True

*/

get_user_model().objects.send_email(subject, message, from_email)   

this will send email to logged in user

by default it will not show sending error

for showing error extra False argument required like below

get_user_model().objects.send_email(subject, message, from_email, False)

9: Registraion

get_user_model().objects.create_user(email, password, first_name, last_name, username)
#username field is optional. If it's empty a rendom unique username will be created

10: Login

#Required argument
email and password

Note. FOO@example.com will be replaced to foo@example.com automatically

License

Released under the MIT license. See LICENSE for details.

Questions, comments, or anything else?

Give a thanks by Donation

Metadata

Release files for django-emailuser 1.1.2

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-emailuser 1.1.2
File Size Uploaded Provenance Actions
django-emailuser-1.1.2.tar.gz 5.4 kB Without provenance Details for django-emailuser-1.1.2.tar.gz

Release files / django-emailuser-1.1.2.tar.gz

Download URL django-emailuser-1.1.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
99dd061fec95ac0d8fac70d8dd59c1195ad1c8468ce1a4d30af0e6368171d369
BLAKE2b-256 checksum
How to use checksums
dbc793e6f97c5d66c2bd072d481d530d285fb4ff8e03377d274407b878cc8303
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Security for django-emailuser 1.1.2

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.

Release history Release notifications | RSS feed

This release

1.1.2 This release

1 release file No provenance

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