Internal
Public Access
Add email verification, admin approval, and user profile enhancements
Implement comprehensive email verification and admin approval system for user registration. Users must verify their email before logging in, and admins must approve new users before they can access the system. Major features: - Email verification with UUID tokens (24hr expiry, one-time use) - Admin approval workflow via Django admin interface - Custom authentication backend enforcing verification and approval - Password change functionality for authenticated users - Enhanced profile page with proper styling and theme support - Collect first name, last name, and timezone during registration - Profile link added to header navigation Email notifications: - Verification email sent after registration - Admin notification when users need approval - Approval notification sent to users Security features: - Cryptographically secure UUID tokens - Token expiration and one-time use enforcement - Email enumeration protection - Custom JWT token validation for API access - Existing users auto-approved via data migration Templates added: - Email templates (verification, approval, admin notification) - Web templates (password change, verification pages) - Enhanced profile page with dark/light mode support 🤖 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
87afc4e80c
commit
21d9d01885
+53
-3
@@ -11,16 +11,30 @@ from .models import User, DeviceToken
|
||||
class UserAdmin(BaseUserAdmin):
|
||||
"""Admin configuration for User model."""
|
||||
|
||||
list_display = ['email', 'username', 'first_name', 'last_name', 'is_staff', 'created_at']
|
||||
list_filter = ['is_staff', 'is_superuser', 'is_active', 'created_at']
|
||||
list_display = [
|
||||
'email', 'username', 'first_name', 'last_name',
|
||||
'email_verified', 'is_approved', 'is_staff', 'created_at'
|
||||
]
|
||||
list_filter = [
|
||||
'email_verified', 'is_approved', 'is_staff',
|
||||
'is_superuser', 'is_active', 'created_at'
|
||||
]
|
||||
search_fields = ['email', 'username', 'first_name', 'last_name']
|
||||
ordering = ['-created_at']
|
||||
actions = ['approve_users', 'unapprove_users']
|
||||
|
||||
fieldsets = BaseUserAdmin.fieldsets + (
|
||||
('Profile', {'fields': ('timezone', 'avatar')}),
|
||||
('Preferences', {'fields': ('default_reminder_minutes', 'email_notifications', 'push_notifications')}),
|
||||
('Preferences', {
|
||||
'fields': ('default_reminder_minutes', 'email_notifications', 'push_notifications')
|
||||
}),
|
||||
('Verification & Approval', {
|
||||
'fields': ('email_verified', 'email_verified_at', 'is_approved', 'approved_by', 'approved_at')
|
||||
}),
|
||||
)
|
||||
|
||||
readonly_fields = ['email_verified_at', 'approved_by', 'approved_at']
|
||||
|
||||
add_fieldsets = (
|
||||
(None, {
|
||||
'classes': ('wide',),
|
||||
@@ -28,6 +42,42 @@ class UserAdmin(BaseUserAdmin):
|
||||
}),
|
||||
)
|
||||
|
||||
def approve_users(self, request, queryset):
|
||||
"""Approve selected users."""
|
||||
from django.utils import timezone
|
||||
from .utils import send_approval_notification
|
||||
|
||||
count = 0
|
||||
for user in queryset.filter(is_approved=False):
|
||||
user.is_approved = True
|
||||
user.approved_by = request.user
|
||||
user.approved_at = timezone.now()
|
||||
user.save(update_fields=['is_approved', 'approved_by', 'approved_at'])
|
||||
|
||||
# Send notification email
|
||||
if user.email_notifications:
|
||||
try:
|
||||
send_approval_notification(user)
|
||||
except Exception:
|
||||
pass # Don't fail approval if email fails
|
||||
|
||||
count += 1
|
||||
|
||||
self.message_user(request, f'{count} user(s) approved successfully.')
|
||||
|
||||
approve_users.short_description = "Approve selected users"
|
||||
|
||||
def unapprove_users(self, request, queryset):
|
||||
"""Remove approval from selected users."""
|
||||
count = queryset.filter(is_approved=True).update(
|
||||
is_approved=False,
|
||||
approved_by=None,
|
||||
approved_at=None
|
||||
)
|
||||
self.message_user(request, f'{count} user(s) unapproved.')
|
||||
|
||||
unapprove_users.short_description = "Remove approval from selected users"
|
||||
|
||||
|
||||
@admin.register(DeviceToken)
|
||||
class DeviceTokenAdmin(admin.ModelAdmin):
|
||||
|
||||
Reference in New Issue
Block a user