This module handles user authentication and authorization for access to the server. It provides functionality for user registration, login, password changes, and managing user roles.
- Description
- Required environment variables
- Main Classes and Methods
- Form Endpoints
- Run Server
- Run Tests
Before starting the application, make sure you have set the following variables in your environment or .env file:
SECRET_KEY="your-secret-key" # Secret key for Django application
EMAIL_HOST_USER="your-email" # Your email address
EMAIL_HOST_PASSWORD="your-email-password" # Your email password
These variables are optional and control the behavior of the application:
ALLOWED_HOSTS="host1,host2" # Comma-separated list of allowed hosts
DEBUG="True" # Set to False in production environment for security
EMAIL_HOST="smtp.gmail.com" # SMTP server for sending emails (default: smtp.gmail.com)
EMAIL_PORT="587" # Port for SMTP (default: 587)
EMAIL_USE_TLS="True" # Whether to use TLS for email (default: True)
Explanation of the module's classes and functions:
A custom manager to handle user creation and management.
Custom user model that uses email as a unique identifier, with fields for personal details and timestamps.
Extends the default group model to include a description field.
This module also includes custom management commands for creating users interactively from the command line.
This command allows you to create a new regular user interactively. When running python manage.py createuser, the system will prompt you to input the user's details (email, username, first name, last name, and password) one by one, securely masking the password as you type it.
Example usage:
python manage.py createuser
It will prompt you for the following inputs:
- Email address
- Username
- First name
- Last name
- Password (masked input)
Similar to createuser, this command will create a staff user interactively. The only difference is that the user will have staff permissions.
Example usage:
python manage.py createstaffuser
It will prompt you for the same details as createuser, but it will create a staff user.
This is the default Django command for creating a superuser interactively, with admin permissions.
The following are the main endpoints for user-related actions:
GET /- Sample home page.GET /register/- Page for user registration.POST /register/- Submit registration form.GET /resend-verification/- Page to resend the activation email.POST /resend-verification/- Submit the form to resend the email.GET /verify/<uidb64>/<token>/- Account activation point.GET /login/- Page for user login.POST /login/- Submit login form.POST /logout/- Logs out the current user.GET /profile/- Page to view profile data.GET /profile/update/- Page to update profile data.POST /profile/update/- Submit profile update form.GET /profile/delete/- Page to disable profile.POST /profile/delete/- Submit deactivation confirmation form.GET /password/change/- Page to change the user's password.POST /password/change/- Submit the password change form.
GET /password_reset/- Page to request a password reset.POST /password_reset/- Submit the email to reset the password.GET /password_reset/done/- Page indicating that the reset email has been sent.GET /reset/<uidb64>/<token>/- Page to confirm the password reset with the provided token.POST /reset/<uidb64>/<token>/- Submit the new password after confirmation.GET /reset/done/- Page indicating that the password has been successfully reset.
To start the server, run:
python manage.py runserverTo run the unit tests:
python manage.py test