Internal
Public Access
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:
co-authored by
Claude Sonnet 4.5
parent
0459ab7456
commit
6eb277c701
+6
-2
@@ -27,7 +27,11 @@ class EmailVerifiedApprovedBackend(ModelBackend):
|
|||||||
if user is None:
|
if user is None:
|
||||||
return 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:
|
if not user.email_verified:
|
||||||
# Store reason for failed login (for web UI)
|
# Store reason for failed login (for web UI)
|
||||||
if request:
|
if request:
|
||||||
@@ -35,7 +39,7 @@ class EmailVerifiedApprovedBackend(ModelBackend):
|
|||||||
request.session['login_email'] = user.email
|
request.session['login_email'] = user.email
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Check admin approval
|
# Check admin approval for regular users
|
||||||
if not user.is_approved:
|
if not user.is_approved:
|
||||||
if request:
|
if request:
|
||||||
request.session['login_error'] = 'not_approved'
|
request.session['login_error'] = 'not_approved'
|
||||||
|
|||||||
Reference in New Issue
Block a user