feat: add in optional registration (#65)

* feat: add in optional registration

* fix: issue with registration var

* fix: issue with registration var

* fix: issue with registration var
This commit is contained in:
Jayden Pyles
2025-05-11 11:11:19 -05:00
committed by GitHub
parent b40d378bbf
commit 8703f706a1
6 changed files with 88 additions and 8 deletions

View File

@@ -1,6 +1,9 @@
import os
from api.backend.database.common import connect, QUERIES
import logging
from api.backend.auth.auth_utils import get_password_hash
LOG = logging.getLogger(__name__)
@@ -12,4 +15,29 @@ def init_database():
LOG.info(f"Executing query: {query}")
_ = cursor.execute(query)
if os.environ.get("REGISTRATION_ENABLED", "True") == "False":
default_user_email = os.environ.get("DEFAULT_USER_EMAIL")
default_user_password = os.environ.get("DEFAULT_USER_PASSWORD")
default_user_full_name = os.environ.get("DEFAULT_USER_FULL_NAME")
if (
not default_user_email
or not default_user_password
or not default_user_full_name
):
LOG.error(
"DEFAULT_USER_EMAIL, DEFAULT_USER_PASSWORD, or DEFAULT_USER_FULL_NAME is not set!"
)
exit(1)
query = "INSERT INTO users (email, hashed_password, full_name) VALUES (?, ?, ?)"
_ = cursor.execute(
query,
(
default_user_email,
get_password_hash(default_user_password),
default_user_full_name,
),
)
cursor.close()