1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-24 07:19:36 +02:00

feat: enhance superuser creation with email verification and update settings for two-factor authentication

This commit is contained in:
Sean Morley 2025-01-07 10:27:11 -05:00
parent 548702890d
commit f670fbc93a
4 changed files with 35 additions and 9 deletions

View file

@ -20,19 +20,38 @@ done
python manage.py migrate python manage.py migrate
# Create superuser if environment variables are set and there are no users present at all. # Create superuser if environment variables are set and there are no users present at all.
if [ -n "$DJANGO_ADMIN_USERNAME" ] && [ -n "$DJANGO_ADMIN_PASSWORD" ]; then if [ -n "$DJANGO_ADMIN_USERNAME" ] && [ -n "$DJANGO_ADMIN_PASSWORD" ] && [ -n "$DJANGO_ADMIN_EMAIL" ]; then
echo "Creating superuser..." echo "Creating superuser..."
python manage.py shell << EOF python manage.py shell << EOF
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from allauth.account.models import EmailAddress
User = get_user_model() User = get_user_model()
if User.objects.count() == 0:
User.objects.create_superuser('$DJANGO_ADMIN_USERNAME', '$DJANGO_ADMIN_EMAIL', '$DJANGO_ADMIN_PASSWORD') # Check if the user already exists
if not User.objects.filter(username='$DJANGO_ADMIN_USERNAME').exists():
# Create the superuser
superuser = User.objects.create_superuser(
username='$DJANGO_ADMIN_USERNAME',
email='$DJANGO_ADMIN_EMAIL',
password='$DJANGO_ADMIN_PASSWORD'
)
print("Superuser created successfully.") print("Superuser created successfully.")
# Create the EmailAddress object for AllAuth
EmailAddress.objects.create(
user=superuser,
email='$DJANGO_ADMIN_EMAIL',
verified=True,
primary=True
)
print("EmailAddress object created successfully for AllAuth.")
else: else:
print("Superuser already exists.") print("Superuser already exists.")
EOF EOF
fi fi
# Sync the countries and world travel regions # Sync the countries and world travel regions
python manage.py download-countries python manage.py download-countries

View file

@ -42,7 +42,7 @@ INSTALLED_APPS = (
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.sites', 'django.contrib.sites',
"allauth_ui", # "allauth_ui",
'rest_framework', 'rest_framework',
'rest_framework.authtoken', 'rest_framework.authtoken',
'allauth', 'allauth',
@ -59,8 +59,8 @@ INSTALLED_APPS = (
'users', 'users',
'integrations', 'integrations',
'django.contrib.gis', 'django.contrib.gis',
'widget_tweaks', # 'widget_tweaks',
'slippers', # 'slippers',
) )

View file

@ -307,6 +307,7 @@
"settings_page": "Settings Page", "settings_page": "Settings Page",
"account_settings": "User Account Settings", "account_settings": "User Account Settings",
"update": "Update", "update": "Update",
"no_verified_email_warning": "You must have a verified email address to enable two-factor authentication.",
"password_change": "Change Password", "password_change": "Change Password",
"new_password": "New Password", "new_password": "New Password",
"confirm_new_password": "Confirm New Password", "confirm_new_password": "Confirm New Password",

View file

@ -416,9 +416,15 @@
<div class="bg-neutral p-6 rounded-lg shadow-md text-center"> <div class="bg-neutral p-6 rounded-lg shadow-md text-center">
{#if !data.props.authenticators} {#if !data.props.authenticators}
<p class="text-neutral-content">{$t('settings.mfa_not_enabled')}</p> <p class="text-neutral-content">{$t('settings.mfa_not_enabled')}</p>
<button class="btn btn-primary mt-4" on:click={() => (isMFAModalOpen = true)} {#if !emails.some((e) => e.verified)}
>{$t('settings.enable_mfa')}</button <div class="alert alert-warning mt-4">
> {$t('settings.no_verified_email_warning')}
</div>
{:else}
<button class="btn btn-primary mt-4" on:click={() => (isMFAModalOpen = true)}
>{$t('settings.enable_mfa')}</button
>
{/if}
{:else} {:else}
<button class="btn btn-warning mt-4" on:click={disableMfa} <button class="btn btn-warning mt-4" on:click={disableMfa}
>{$t('settings.disable_mfa')}</button >{$t('settings.disable_mfa')}</button