Skip to content

Svtter/django-login-email

Repository files navigation

Django Login Email

PyPI Documentation Status Downloads

Allow user to login and register with email address.

NOTICE: We are currently in the development stage. If you use this library, please upgrade to the latest version. Issues are welcome.

You can view the documentation here.

Documentation

Install

pip install django-login-email

List of the urls for exmaple project:

  • /home for protected url.
  • /account/login for login.
  • /account/logout for logout.
  • /account/verify for email verify.

Feature

  • The developer could define their own User model.
  • Time-limited of login link.
  • limited of sending email. Using TimeLimt to set minutes.
  • The link could be used for Login once.
  • Register new user.
  • Support multiple user.
  • Ban the IP to send mail frequently without login.
  • Support django-templated-email
  • Support Django Anymail
  • Allow users to change their email address.
  • Enable 2FA.
  • More easier and customizable login link.

Usage

  • add django_login_email to your app settings.py.
INSTALLED_APP = [
    ...,
    'django_login_email',
    ...
]
  • Implement the LoginView, for example, like this:
from django.shortcuts import render
from django.urls import reverse

from django_login_email import email as e
from django_login_email import views as v

# Create your views here.

loginInfo, registerInfo = e.get_info_class("meterhub")


class LoginView(v.EmailLoginView):
  login_info_class = loginInfo
  register_info_class = registerInfo


class VerifyView(v.EmailVerifyView):
  def get_success_url(self):
    return reverse("home")


class LogoutView(v.EmailLogoutView):
  pass

  • set the view in your urls.py.
from django.contrib import admin
from django.urls import path
from <yourapp> import views as v
from django_login_email.views import HomeView

urlpatterns = [
    ...,
    path("account/login", v.LoginView.as_view(), name="login"),
    path("account/verify", v.VerifyView.as_view(), name="verify"),
    path("account/logout", v.LogoutView.as_view(), name="logout"),
    path("", HomeView.as_view(), name="home"),
]

That's all.

Debug the email with docker run -d --name mailhog -p 1025:1025 -p 8025:8025 mailhog/mailhog

Settings

For detailed configuration options, see the Configuration Reference.

Quick settings overview:

  1. Config LoginView.tl to adjust rate limiting (default: 10 minutes between emails)
  2. Configure email server settings in your Django settings.py (see settings/settings.py for examples)
  3. Customize email templates by subclassing EmailLoginInfo and EmailRegisterInfo

Example - Disable rate limiting for development:

class YouLoginView(LoginView):
  def check_could_send(self, email) -> bool:
    # FOR DEBUG
    return True

Compatibility

  • Python: 3.10+ (tested: 3.10, 3.11, 3.12)
  • Django: 5.0.4+ (tested: 5.0.x)
  • Databases: SQLite, PostgreSQL, MySQL/MariaDB

See COMPATIBILITY.md for detailed version support.

Security

This package implements passwordless authentication with the following security features:

  • ✅ AES-encrypted tokens
  • ✅ Time-limited tokens (default: 10 minutes)
  • ✅ One-time use tokens
  • ✅ Rate limiting
  • ✅ IP banning for abuse prevention

See SECURITY.md for security policy and best practices.

Future

  • Academically prove the safety of this method.

Related project

About

A django app for login with email project.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 2

  •  
  •