Add functions for importing 3.x users, require passwords when adding users

This commit is contained in:
xithical 2022-03-18 20:46:56 -05:00
parent ccd0bc8e8f
commit 7c822b715a
2 changed files with 17 additions and 2 deletions

View File

@ -96,9 +96,13 @@ 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):
return users_helper.remove_user(user_id)

View File

@ -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:
@ -162,6 +162,17 @@ class helper_users:
}).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):
if up_data is None: