def add_user(username: str, password: str, repo: AbstractRepository): if repo.get_user(username): raise DuplicatedUsernameException password_hash = generate_password_hash(password) new_user = User(username, password_hash) repo.add_user(new_user) if has_app_context(): _save_users_to_disk(current_app.config['USER_DATA_PATH'], repo)
def add_user(username: str, password: str, repo: AbstractRepository): # Check that the given username is available. user = repo.get_user(username) if user is not None: raise NameNotUniqueException # Encrypt password so that the database doesn't store passwords 'in the clear'. password_hash = generate_password_hash(password) # Create and store the new User, with password encrypted. user = User(username, password_hash) repo.add_user(user)
def add_user(repo: AbstractRepository, username: str, password: str) -> None: """ Adds the given user to the given repository. """ # Check that the given username is available. if check_if_user_exists(repo, username): raise NameNotUniqueException # Encrypt password so that the database doesn't store passwords 'in the clear'. password_hash = generate_password_hash(password) # Create and store the new User, with password encrypted. user = User(username, password_hash) repo.add_user(user)
def user_register(username: str, password: str, repo: AbstractRepository): user = repo.get_user(username) messages = {'state': False} if user is not None: messages['error'] = 'The user has been registered' return messages else: user = User(username, password) repo.add_user(user) messages['state'] = True messages['error'] = 'register successfully' return messages '''
def add_user(username: str, password: str, repo: AbstractRepository): if repo.get_user(username): raise DuplicatedUsernameException password_hash = generate_password_hash(password) new_user = User(username, password_hash) repo.add_user(new_user)