예제 #1
0
def add_user(username: str, password: str, repo: AbstractRepository):
    # check that given username is available
    user = repo.get_user(username)
    if user is not None:
        raise NameNotUniqueException

    # if available generate password hash and store new user with hash
    password_hash = generate_password_hash(password)

    user = User(username, password_hash)
    repo.add_user(user)
예제 #2
0
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)
예제 #3
0
def add_user(username: str, password: str, repo: AbstractRepository):
    # Check that the username is not taken
    user = repo.get_user(username)
    if user is not None:
        raise NameNotUniqueException

    # Encrypt password
    password_hash = generate_password_hash(password)

    # Create and store the new User with encrypted password
    user = User(username, password_hash)
    repo.add_user(user)