Fix authentication: allow superusers to bypass email verification and approval

The authentication backend was requiring ALL users (including superusers)
to have email_verified=True and is_approved=True. This created a
chicken-and-egg problem where the first superuser couldn't log in to
approve themselves.

Now superusers bypass these checks and can log in immediately after
creation via createsuperuser command. Regular users still require
email verification and admin approval.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Keith Smith
2025-12-26 17:14:46 -07:00
co-authored by Claude Sonnet 4.5
parent 0459ab7456
commit 6eb277c701
+6 -2
View File
@@ -27,7 +27,11 @@ class EmailVerifiedApprovedBackend(ModelBackend):
if user is None:
return None
# Check email verification
# Superusers bypass email verification and approval checks
if user.is_superuser:
return user
# Check email verification for regular users
if not user.email_verified:
# Store reason for failed login (for web UI)
if request:
@@ -35,7 +39,7 @@ class EmailVerifiedApprovedBackend(ModelBackend):
request.session['login_email'] = user.email
return None
# Check admin approval
# Check admin approval for regular users
if not user.is_approved:
if request:
request.session['login_error'] = 'not_approved'