creaded correct docker image creation file
This commit is contained in:
@@ -19,16 +19,24 @@ app = create_app()
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
# Create admin user
|
||||
admin = User.query.filter_by(username='admin').first()
|
||||
# Create or update admin user from environment variables
|
||||
import os
|
||||
admin_username = os.getenv('ADMIN_USERNAME', 'admin')
|
||||
admin_password = os.getenv('ADMIN_PASSWORD', 'admin123')
|
||||
|
||||
admin = User.query.filter_by(username=admin_username).first()
|
||||
if not admin:
|
||||
hashed = bcrypt.generate_password_hash('admin123').decode('utf-8')
|
||||
admin = User(username='admin', password=hashed, role='admin')
|
||||
hashed = bcrypt.generate_password_hash(admin_password).decode('utf-8')
|
||||
admin = User(username=admin_username, password=hashed, role='admin')
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
print('✅ Admin user created (admin/admin123)')
|
||||
print(f'✅ Admin user created ({admin_username})')
|
||||
else:
|
||||
print('✅ Admin user already exists')
|
||||
# Update password if it exists
|
||||
hashed = bcrypt.generate_password_hash(admin_password).decode('utf-8')
|
||||
admin.password = hashed
|
||||
db.session.commit()
|
||||
print(f'✅ Admin user password updated ({admin_username})')
|
||||
"
|
||||
echo "Database initialized!"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user