Files
digiserver/app/models/create_default_user.py
DigiServer Developer 5e4950563c Fix admin authentication and update port mapping
- Fix environment variable mismatch in create_default_user.py
- Now correctly uses ADMIN_USER and ADMIN_PASSWORD from docker-compose
- Maintains backward compatibility with DEFAULT_USER and DEFAULT_PASSWORD
- Change port mapping from 8880 to 80 for easier access
- Resolves login issues with admin user credentials
2025-08-11 17:01:58 +03:00

19 lines
877 B
Python

#from app import app, db, User, bcrypt
import os
def create_default_user(db, User, bcrypt):
# Use ADMIN_USER and ADMIN_PASSWORD to match docker-compose environment variables
username = os.getenv('ADMIN_USER', os.getenv('DEFAULT_USER', 'admin'))
password = os.getenv('ADMIN_PASSWORD', os.getenv('DEFAULT_PASSWORD', '1234'))
hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')
existing_user = User.query.filter_by(username=username).first()
if not existing_user:
default_user = User(username=username, password=hashed_password, role='admin')
db.session.add(default_user)
db.session.commit()
print(f"Default user '{username}' created with password '{password}'")
else:
print(f"Default user '{username}' already exists.")
#with app.app_context():
# create_default_user(db, User, bcrypt)