Skip to content

Swapnayg/django-custom-user

 
 

Repository files navigation

django-custom-user

Current Feature

  • Custom user model derived from AbstractBaseUser with email as username field.
  • Custom user model create and change form function for admin.
  • Authentication and edit user profile in the template.
  • Change password and reset with email validation using SendGrid.
  • Account verification when sign up via email SendGrid.
  • Social authentication (GitHub, Google+, Twitter, Facebook)
  • Linking of multiple social account to existing email address (django-allauth)
  • Material Design

Demo link here.

Dependencies

  • python3.x and higher
  • Get pipenv(I recommend this) for virtualenvs and package manager.

Installation

  • Clone repository
  • $ pipenv install
  • $ python manage.py makemigrations && python manage.py migrate && python manage.py runserver
  • To create superuser $ python manage.py createsuperuser
  • Open localhost url.

Creating Social Application

Github

App registration to get your key and secret here.

Add development callback http://127.0.0.1:8000/social-api/auth/github/login/callback/

Use your production domain name for live site http://{{ domain_name }}/social-api/auth/github/login/callback/

Google

App registration to get your key and secret here.

  • Click Create Credentials drop button and choose OAuth Client ID.
  • Select web application for application type.
  • Add name and under Authorized redirect URIs include. http://127.0.0.1:8000/social-api/auth/google/login/callback (Google can provide multiple redirect uris, so you can include as many as you may need.)
  • Click create and you can get your key and secret.

Use your production domain name for live site.

Twitter

App registration to get your key and secret here.

  • Create an app
  • Add this http://127.0.0.1:8000/social-api/auth/twitter/login/callback/ as your for callback uri
  • Twitter doesnt accept localhost domain name http://localhost:8000

Because this application always requires valid email for authentication process, we expect all twitter accounts had their valid email, in order to get the email of your twitter:

  • After creating application click the newly created app and go to Permissions tab, below check the option for Request email address from users. Of course twitter is very strict in this regard and and in order to do so you must provide Privacy Policy URL and Term of Services URL then you are good to go.
  • One more thing is you may need to check Enable Callback Locking (It is recommended to enable callback locking to ensure apps cannot overwrite the callback url) option.

Use your production domain name for live site.

Facebook

App registration to get your key and secret here.

  • Add a new app, enter the required fields and click Create App ID
  • Add product and choose Facebook login
  • Ignore the Quickstart and go to the Settings of Facebook login category.
  • Add http://127.0.0.1:8000/social-api/auth/facebook/login/callback/ in the redirect URIs (You can add multiple uris). Save Changes
  • In order to make your facebook app live you must also provide Privacy Policy URL and Term of Services URL under the Settings > Basic side menu.
  • Go to app review and make your app public. You will see the Approved items is enabled from here your are good to go.

Use your production domain name for live site.

Registering Social Applications

First go to administrator login and enter your credentials as supersuser.

  • Click the Sites and change the example.com domain name to localhost for development or use your production domain name. (You can add as many site including your development domain name localhost and 127.0.0.1)
  • Back to home page and under the Social Account > Social applications add a social application
  • Enter provider, name, client id and secret and select a chosen sites then click save.

Great example can be found here Django Allauth Tutorial by Will Vincent.

Acknowledgement

Will Vincent author of Django for beginners

Raymond Penners author of django-allauth

About

Unleashing Django 2.0 custom user model

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 65.8%
  • HTML 32.5%
  • CSS 1.7%