Improve GrampsWeb admin script: reset password if user exists (STI-90)
When the admin user already exists with an unknown password, the startup script now attempts to reset the password instead of skipping. This handles the case where GrampsWeb was previously set up without tracking the admin credentials. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
14
compose.yml
14
compose.yml
@@ -225,7 +225,7 @@ services:
|
|||||||
python3 << 'PYEOF' 2>&1 | grep -v Gtk
|
python3 << 'PYEOF' 2>&1 | grep -v Gtk
|
||||||
from gramps_webapi.app import create_app
|
from gramps_webapi.app import create_app
|
||||||
from gramps_webapi.auth import add_user, get_number_users, ROLE_OWNER
|
from gramps_webapi.auth import add_user, get_number_users, ROLE_OWNER
|
||||||
import os
|
import os, sqlite3, hashlib
|
||||||
email = os.environ.get('GRAMPSWEB_ADMIN_EMAIL', '')
|
email = os.environ.get('GRAMPSWEB_ADMIN_EMAIL', '')
|
||||||
pw = os.environ.get('GRAMPSWEB_ADMIN_PASSWORD', '')
|
pw = os.environ.get('GRAMPSWEB_ADMIN_PASSWORD', '')
|
||||||
if email and pw:
|
if email and pw:
|
||||||
@@ -235,7 +235,17 @@ services:
|
|||||||
add_user(name='Admin', email=email, password=pw, role=ROLE_OWNER)
|
add_user(name='Admin', email=email, password=pw, role=ROLE_OWNER)
|
||||||
print('[grampsweb] Admin user created')
|
print('[grampsweb] Admin user created')
|
||||||
else:
|
else:
|
||||||
print('[grampsweb] Users already exist, skipping')
|
try:
|
||||||
|
add_user(name='Admin', email=email, password=pw, role=ROLE_OWNER)
|
||||||
|
print('[grampsweb] Admin user created')
|
||||||
|
except Exception:
|
||||||
|
from gramps_webapi.auth import get_user_details, modify_user
|
||||||
|
try:
|
||||||
|
user = get_user_details(name='Admin')
|
||||||
|
modify_user(name='Admin', password=pw, role=ROLE_OWNER)
|
||||||
|
print('[grampsweb] Admin user password reset')
|
||||||
|
except Exception as e:
|
||||||
|
print(f'[grampsweb] Could not update admin user: {e}')
|
||||||
else:
|
else:
|
||||||
print('[grampsweb] No admin credentials configured, skipping')
|
print('[grampsweb] No admin credentials configured, skipping')
|
||||||
PYEOF
|
PYEOF
|
||||||
|
|||||||
Reference in New Issue
Block a user