コード例 #1
0
def add_user(user_name: str, password: str, repo: AbstractRepository):
    # Check that the given username is available and not currently used in repository
    user = repo.get_user(user_name)
    if user is not None:
        raise NameNotUniqueException

    # Encrypt password so that the database doesn't store passwords in plain text format.
    password_hash = generate_password_hash(password)

    # Create and store the new User with an encrypted password
    user = User(user_name, password_hash)
    repo.add_user(user)
コード例 #2
0
ファイル: services.py プロジェクト: NeoXB/CS235Flix-SQL
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)