Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
—
Local user authentication, registration, email verification, password management, and account settings. Handles traditional Django authentication flows with enhanced email and phone verification capabilities.
Core models for user account management including email addresses, login tracking, and email confirmations.
class EmailAddress(models.Model):
"""
Model for managing user email addresses with verification status.
"""
user: User = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
email: str = models.EmailField(max_length=app_settings.EMAIL_MAX_LENGTH)
verified: bool = models.BooleanField(default=False)
primary: bool = models.BooleanField(default=False)
objects: EmailAddressManager
def send_confirmation(self, request: HttpRequest, signup: bool = False) -> EmailConfirmation: ...
class EmailConfirmation(models.Model):
"""
Model for email confirmation tokens and verification workflow.
"""
email_address: EmailAddress
created: datetime
sent: Optional[datetime]
key: str
objects: EmailConfirmationManager
def confirm(self, request: HttpRequest) -> EmailAddress: ...
def send(self, request: HttpRequest, signup: bool = False) -> None: ...
class Login(models.Model):
"""
Model for tracking user login sessions and device information.
"""
user: User
ip_address: str
user_agent: str
timestamp: datetime
method: strDjango class-based views for authentication flows including login, signup, password management, and email verification.
class LoginView(RedirectAuthenticatedUserMixin, AjaxCapableProcessFormViewMixin, FormView):
"""
User login view with form handling and redirection.
"""
form_class: type = LoginForm
template_name: str = "account/login.html"
def form_valid(self, form: LoginForm) -> HttpResponse: ...
class SignupView(RedirectAuthenticatedUserMixin, CloseableSignupMixin, AjaxCapableProcessFormViewMixin, FormView):
"""
User registration view with form handling and email verification.
"""
form_class: type = SignupForm
template_name: str = "account/signup.html"
def form_valid(self, form: SignupForm) -> HttpResponse: ...
class LogoutView(LogoutFunctionalityMixin, TemplateView):
"""
User logout view with session cleanup.
"""
template_name: str = "account/logout.html"
class PasswordResetView(AjaxCapableProcessFormViewMixin, FormView):
"""
Password reset request view with email sending.
"""
form_class: type = ResetPasswordForm
template_name: str = "account/password_reset.html"
class PasswordResetFromKeyView(AjaxCapableProcessFormViewMixin, FormView):
"""
Password reset confirmation view using token from email.
"""
form_class: type = ResetPasswordKeyForm
template_name: str = "account/password_reset_from_key.html"
class PasswordChangeView(AjaxCapableProcessFormViewMixin, FormView):
"""
Password change view for authenticated users.
"""
form_class: type = ChangePasswordForm
template_name: str = "account/password_change.html"
class EmailView(AjaxCapableProcessFormViewMixin, FormView):
"""
Email management view for adding/removing email addresses.
"""
form_class: type = AddEmailForm
template_name: str = "account/email.html"
class ConfirmEmailView(TemplateView):
"""
Email confirmation view using token from email.
"""
template_name: str = "account/email_confirm.html"
def get(self, request: HttpRequest, key: str) -> HttpResponse: ...
def post(self, request: HttpRequest, key: str) -> HttpResponse: ...Django forms for authentication flows with validation and custom field handling.
class LoginForm(forms.Form):
"""
User login form with email/username and password fields.
"""
login: str = forms.CharField()
password: str = PasswordField()
remember: bool = forms.BooleanField(required=False)
def clean(self) -> Dict[str, Any]: ...
def login(self, request: HttpRequest, redirect_url: str = None) -> User: ...
class SignupForm(forms.Form):
"""
User registration form with username, email, and password fields.
"""
username: str = forms.CharField()
email: str = EmailField()
password1: str = SetPasswordField()
password2: str = PasswordField()
def clean_username(self) -> str: ...
def clean_email(self) -> str: ...
def clean_password2(self) -> str: ...
def save(self, request: HttpRequest) -> User: ...
class ResetPasswordForm(forms.Form):
"""
Password reset request form with email field.
"""
email: str = EmailField()
def clean_email(self) -> str: ...
def save(self, request: HttpRequest) -> None: ...
class ResetPasswordKeyForm(forms.Form):
"""
Password reset confirmation form with new password fields.
"""
password1: str = SetPasswordField()
password2: str = PasswordField()
def __init__(self, user: User, temp_key: str, *args, **kwargs): ...
def clean_password2(self) -> str: ...
def save(self) -> User: ...
class ChangePasswordForm(forms.Form):
"""
Password change form for authenticated users.
"""
oldpassword: str = PasswordField()
password1: str = SetPasswordField()
password2: str = PasswordField()
def __init__(self, user: User, *args, **kwargs): ...
def clean_oldpassword(self) -> str: ...
def clean_password2(self) -> str: ...
def save(self) -> User: ...
class AddEmailForm(forms.Form):
"""
Form for adding new email addresses to user account.
"""
email: str = EmailField()
def __init__(self, user: User, *args, **kwargs): ...
def clean_email(self) -> str: ...
def save(self, request: HttpRequest) -> EmailAddress: ...Customizable adapter classes for extending authentication behavior.
class AccountAdapter:
"""
Adapter class for customizing account-related behavior.
"""
def new_user(self, request: HttpRequest) -> User:
"""Create new user instance."""
def save_user(self, request: HttpRequest, user: User, form: forms.Form, commit: bool = True) -> User:
"""Save user instance with form data."""
def clean_username(self, username: str, shallow: bool = False) -> str:
"""Clean and validate username."""
def clean_email(self, email: str) -> str:
"""Clean and validate email address."""
def clean_password(self, password: str, user: User = None) -> str:
"""Clean and validate password."""
def send_mail(self, template_prefix: str, email: str, context: Dict[str, Any]) -> None:
"""Send email using template."""
def get_login_redirect_url(self, request: HttpRequest) -> str:
"""Get URL to redirect after login."""
def get_logout_redirect_url(self, request: HttpRequest) -> str:
"""Get URL to redirect after logout."""
def is_open_for_signup(self, request: HttpRequest) -> bool:
"""Check if signup is open."""
def get_adapter(request: HttpRequest = None) -> AccountAdapter:
"""
Get account adapter instance.
Parameters:
- request: Optional HTTP request object
Returns:
AccountAdapter instance
"""Account-related utility functions for user management and email handling.
def filter_users_by_email(email: str, is_active: bool = None, prefetch: bool = False) -> QuerySet:
"""
Filter users by email address.
Parameters:
- email: Email address to filter by
- is_active: Optional filter by user active status
- prefetch: Whether to prefetch related data
Returns:
User queryset
"""
def filter_users_by_username(*usernames: str) -> QuerySet:
"""
Filter users by username(s).
Parameters:
- usernames: Username(s) to filter by
Returns:
User queryset
"""
def setup_user_email(request: HttpRequest, user: User, addresses: List[str]) -> None:
"""
Set up user email addresses.
Parameters:
- request: HTTP request object
- user: User instance
- addresses: List of email addresses to add
"""
def user_email(user: User) -> str:
"""
Get primary email address for user.
Parameters:
- user: User instance
Returns:
Primary email address or empty string
"""
def user_username(user: User) -> str:
"""
Get username for user.
Parameters:
- user: User instance
Returns:
Username string
"""
def send_email_confirmation(request: HttpRequest, user: User, signup: bool = False) -> EmailConfirmation:
"""
Send email confirmation to user.
Parameters:
- request: HTTP request object
- user: User instance
- signup: Whether this is during signup flow
Returns:
EmailConfirmation instance
"""from allauth.account.forms import SignupForm
from allauth.account.models import EmailAddress
# Process signup form
form_data = {
'username': 'johndoe',
'email': 'john@example.com',
'password1': 'secure_password123',
'password2': 'secure_password123'
}
form = SignupForm(form_data)
if form.is_valid():
user = form.save(request)
print(f"User {user.username} created")from allauth.account.models import EmailAddress
# Add email address
email_addr = EmailAddress.objects.add_email(request, user, 'new@example.com')
# Send confirmation
confirmation = email_addr.send_confirmation(request)
# Check verification status
if email_addr.verified:
print("Email is verified")
# Set as primary
email_addr.set_as_primary()from allauth.account.forms import ResetPasswordForm, ResetPasswordKeyForm
# Request password reset
reset_form = ResetPasswordForm({'email': 'user@example.com'})
if reset_form.is_valid():
reset_form.save(request)
print("Password reset email sent")
# Handle reset confirmation (from email link)
key_form = ResetPasswordKeyForm(
user=user,
temp_key=temp_key,
data={
'password1': 'new_password123',
'password2': 'new_password123'
}
)
if key_form.is_valid():
user = key_form.save()
print("Password reset successfully")from allauth.account.adapter import DefaultAccountAdapter
class MyAccountAdapter(DefaultAccountAdapter):
def get_login_redirect_url(self, request):
return '/dashboard/'
def is_open_for_signup(self, request):
# Custom signup logic
return request.user.is_staff
def send_mail(self, template_prefix, email, context):
# Custom email sending logic
super().send_mail(template_prefix, email, context)
# In settings.py
ACCOUNT_ADAPTER = 'myapp.adapters.MyAccountAdapter'Install with Tessl CLI
npx tessl i tessl/pypi-django-allauth