def get_user(identifier): """Get user account information for the user with the given email. @param identifier: The email address of the user to get account information for. May also be integer ID. @type identifier: str or int @return: User account info for use with given email address. @rtype: models.User """ return db_util.load_user_model(identifier)
def change_user_password(email, password): """Change a user's account password. @param email: The email of the user to change account passwords for. @type email: str @param password: The new password to use for the account. @type password: str """ email = email.lower() user = db_util.load_user_model(email) user.password_hash = werkzeug.generate_password_hash(password, method="sha512") db_util.save_user_model(user)
def update_user( orig_email, email, can_enter_data, can_delete_data, can_import_data, can_edit_parents, can_access_data, can_change_formats, can_use_api_key, can_admin, ): """Change a user's account. @param orig_email: The email of the user whose account permissions is being changed. @type orig_email: str @param new_email: The new email address to give to this user. @type new_email: str @param can_enter_data: Indicate if the user can enter new data into the lab database. @type can_enter_data: bool @param can_delete_data: Indicate if the user can delete data from the lab database. @type can_delete_data: bool @param can_import_data: Indicate if the user can import data from the lab database. @type can_import_data: bool @param can_access_data: Indicate if the user can access existing lab data. @type can_access_data: bool @param can_change_formats: Indicate if the user can change MCDI forms, CSV presentation formats, and percentile tables. @type can_change_formats: bool @param can_use_api_key: Indicates if this user can use an API key. @type can_use_api_key: bool @param can_admin: Indicates if this user can edit other users' accounts and permissions. @type can_admin: bool """ email = email.lower() user = db_util.load_user_model(orig_email) user.email = email user.can_enter_data = can_enter_data user.can_delete_data = can_delete_data user.can_import_data = can_import_data user.can_edit_parents = can_edit_parents user.can_access_data = can_access_data user.can_change_formats = can_change_formats user.can_use_api_key = can_use_api_key user.can_admin = can_admin db_util.save_user_model(user, existing_email=orig_email)
def check_user_password(email, password): """Check if the given password is correct. @param email: The email of the user to check a password for. @type email: str @param password: The password to check. @type password: str @return: True if the password is correct and False otherwise. @rtype: bool """ email = email.lower() user = db_util.load_user_model(email) if not user: return False pass_hash = str(user.password_hash) try: return werkzeug.check_password_hash(pass_hash, password) except: return False