From 7c822b715adba612655d70d5063767fb3798c68f Mon Sep 17 00:00:00 2001 From: xithical <86810816+xithical@users.noreply.github.com> Date: Fri, 18 Mar 2022 20:46:56 -0500 Subject: [PATCH] Add functions for importing 3.x users, require passwords when adding users --- app/classes/controllers/users_controller.py | 6 +++++- app/classes/models/users.py | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/classes/controllers/users_controller.py b/app/classes/controllers/users_controller.py index 09adaca7..e073dc12 100644 --- a/app/classes/controllers/users_controller.py +++ b/app/classes/controllers/users_controller.py @@ -96,8 +96,12 @@ class Users_Controller: users_helper.update_user(user_id, up_data) @staticmethod - def add_user(username, password=None, email="default@example.com", enabled: bool = True, superuser: bool = False): + def add_user(username, password, email="default@example.com", enabled: bool = True, superuser: bool = False): return users_helper.add_user(username, password=password, email=email, enabled=enabled, superuser=superuser) + + @staticmethod + def add_rawpass_user(username, password, email="default@example.com", enabled: bool = True, superuser: bool = False): + return users_helper.add_rawpass_user(username, password=password, email=email, enabled=enabled, superuser=superuser) @staticmethod def remove_user(user_id): diff --git a/app/classes/models/users.py b/app/classes/models/users.py index 4c32c538..b99a53fc 100644 --- a/app/classes/models/users.py +++ b/app/classes/models/users.py @@ -147,7 +147,7 @@ class helper_users: return user @staticmethod - def add_user(username: str, password: Optional[str] = None, email: Optional[str] = None, enabled: bool = True, superuser: bool = False) -> str: + def add_user(username: str, password: str = None, email: Optional[str] = None, enabled: bool = True, superuser: bool = False) -> str: if password is not None: pw_enc = helper.encode_pass(password) else: @@ -161,6 +161,17 @@ class helper_users: Users.created: helper.get_time_as_string() }).execute() return user_id + + @staticmethod + def add_rawpass_user(username: str, password: str = None, email: Optional[str] = None, enabled: bool = True, superuser: bool = False) -> str: + user_id = Users.insert({ + Users.username: username.lower(), + Users.password: password, + Users.email: email, + Users.enabled: enabled, + Users.superuser: superuser, + Users.created: helper.get_time_as_string() + }).execute() @staticmethod def update_user(user_id, up_data=None):