-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04cbe7c
commit e6ef757
Showing
3 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
27 changes: 27 additions & 0 deletions
27
backend/envs/prod/initialization/setup_prod_environment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from databases.database_manager import DatabaseManager | ||
from databases.user_manager import UserManager | ||
from models.user import User | ||
from security import get_password_hash | ||
from utils.utils import get_app_logger | ||
|
||
logger = get_app_logger(__name__) | ||
|
||
|
||
def create_admin_user(): | ||
"""Creates an admin user if it doesn't already exist.""" | ||
admin_user = User( | ||
username="admin", | ||
hashed_password=get_password_hash("admin"), | ||
email="[email protected]", | ||
organization_id=1, | ||
role="admin", | ||
) | ||
|
||
with DatabaseManager() as session: | ||
user_manager = UserManager(session) | ||
existing_user = user_manager.get_user_by_username(admin_user.username) | ||
if not existing_user: | ||
user_manager.create_user(admin_user) | ||
logger.debug("Admin user created.") | ||
else: | ||
logger.debug("Admin user already exists.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters