8000 GitHub - jakiiii/jtroauth: Django authentication boilerplate with custom user model, DRF API, JWT, email verification, and Bootstrap UI. · GitHub
[go: up one dir, main page]

Skip to content
jakiiiiPublic

About

Django authentication boilerplate with custom user model, DRF API, JWT, email verification, and Bootstrap UI.

Resources

Stars

4 stars

Watchers

1 watching

Forks

Repository files navigation

jTroAuth

Reusable Django + DRF authentication starter boilerplate with:

  • Custom User model (PermissionsMixin) with email + username login support
  • Web auth (register, login, logout, profile, password reset/change)
  • Email verification + resend activation flow
  • DRF auth APIs with djangorestframework-simplejwt
  • SQLite default, PostgreSQL-ready via DATABASE_URL
  • Clean project layout (core/, apps/, base/)

Final Project Structure

See structure.md for the full tree.

Key modules:

  • core/ - project config, settings, middleware, root URLs/templates
  • apps/accounts/ - auth domain (models, forms, web views, API, email, tests)
  • apps/home/ - home app
  • base/ - reusable base utilities

Requirements

  • Python 3.12+
  • Virtual environment recommended

Install dependencies:

pip install -r requirements.txt

Environment Configuration

Create local env from example:

cp .env.example .env

Important variables:

  • DEBUG (default: True)
  • SECRET_KEY
  • ALLOWED_HOSTS
  • DATABASE_URL (default fallback: SQLite db.sqlite3)
  • APP_BASE_URL (used for email activation links)
  • EMAIL_* settings

SQLite Quick Start (Default)

python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

PostgreSQL Setup

Set DATABASE_URL in .env:

DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/jtroauth

Then run:

python manage.py migrate
python manage.py runserver

If PostgreSQL is not running, keep SQLite fallback by leaving DATABASE_URL unset or set to SQLite.


Authentication Features

Login accepts either email or username (same password) for:

  • Web login (/accounts/login/)
  • Django admin (/admin/login/)
  • API token endpoints (/api/auth/login/, /api/auth/token/)

Web URLs (/accounts/)

  • login/
  • logout/
  • register/
  • activate/<uidb64>/<token>/
  • email/resend/
  • profile/
  • profile/edit/
  • password/change/
  • password/reset/ and confirm/complete routes

API URLs (/api/auth/)

  • POST register/
  • POST login/
  • POST token/
  • POST token/refresh/
  • POST logout/
  • GET me/
  • POST password/reset/
  • POST password/reset/confirm/
  • POST email/verify/
  • POST email/resend/

Token/login request example:

{
  "identifier": "mohin_or_email@example.com",
  "password": "your-password"
}

email and username keys are still accepted for backward compatibility.


Auth Flow Summary

  1. User registers (is_active=False, email_verified=False)
  2. Username is optional on registration; if omitted it is auto-generated from the email local part
    • policy: lowercase, non-alphanumeric characters converted to _, uniqueness enforced with numeric suffixes
  3. Activation email is sent with signed token link
  4. User verifies email via link or API verify endpoint
  5. Account becomes active and can obtain JWT tokens

Email Configuration

Local default:

  • EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend

SMTP example:

EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.example.com
EMAIL_PORT=587
EMAIL_HOST_USER=your-user
EMAIL_HOST_PASSWORD=your-password
EMAIL_USE_TLS=True
DEFAULT_FROM_EMAIL=no-reply@example.com

Email templates included:

  • Account activation (HTML + text)
  • Password reset (HTML + text + subject)
  • Welcome email (optional)

Quality Checks

Run:

python manage.py check
python manage.py makemigrations --check
python manage.py migrate
python manage.py test

Production Notes

  • Use core.settings.production
  • Set a strong SECRET_KEY
  • Set explicit ALLOWED_HOSTS
  • Use SMTP/backend suitable for production
  • Run behind a proper WSGI/ASGI server (not Django dev server)

Recent Modernization Changes

  • Removed legacy djangorestframework-jwt usage
  • Migrated auth APIs to djangorestframework-simplejwt
  • Moved legacy src/customuserauth layout to root core/apps/base
  • Added .env.example and DATABASE_URL support
  • Rebuilt tests for models, web auth, and API auth flows

About

Django authentication boilerplate with custom user model, DRF API, JWT, email verification, and Bootstrap UI.

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0