1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-24 15:29: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
# 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..."
python manage.py shell << EOF
from django.contrib.auth import get_user_model
from allauth.account.models import EmailAddress
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.")
# 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:
print("Superuser already exists.")
EOF
fi
# Sync the countries and world travel regions
python manage.py download-countries

View file

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

View file

@ -307,6 +307,7 @@
"settings_page": "Settings Page",
"account_settings": "User Account Settings",
"update": "Update",
"no_verified_email_warning": "You must have a verified email address to enable two-factor authentication.",
"password_change": "Change Password",
"new_password": "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">
{#if !data.props.authenticators}
<p class="text-neutral-content">{$t('settings.mfa_not_enabled')}</p>
<button class="btn btn-primary mt-4" on:click={() => (isMFAModalOpen = true)}
>{$t('settings.enable_mfa')}</button
>
{#if !emails.some((e) => e.verified)}
<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}
<button class="btn btn-warning mt-4" on:click={disableMfa}
>{$t('settings.disable_mfa')}</button