Example #1
0
def add_user_txn(session,
                 city,
                 first_name,
                 last_name,
                 email,
                 username,
                 password,
                 password_hash=None,
                 is_owner=False):
    """
    Insert a new row into the users table. The password passed to the function is not stored. Instead, the `set_password` method hashes the string and stores the hash.

    Arguments:
        session {.Session} -- The active session for the database connection.
        city {String} -- The user's city.
        first_name {String} -- The user's first name.
        last_name {String} -- The user's last name.
        email {String} -- The user's email.
        username {String} -- The user's username.
        password {String} -- The user's unhashed password.

    Keyword Arguments:
        password_hash {String} -- A hash of the password. This is generated by a password hasher. (default: {None})
        is_owner {bool} -- True if the user is a vehicle owner. (default: {False})
    """
    u = User(city=city,
             id=str(uuid.uuid4()),
             first_name=first_name,
             last_name=last_name,
             email=email,
             username=username,
             is_owner=is_owner)
    u.set_password(password)
    session.add(u)
def add_user_txn(session, email, last_name, first_name, phone_numbers):
    """
    Add a new row to the User table.

    Does not currently validate phone numbers, beyond confirming that it's an
        array of strings.

    Arguments:
        email {String} -- The user's email.
        first_name {String} -- The user's first name.
        last_name {String} -- The user's last name.
        phone_numbers {Array} {String} -- The user's phone numbers, stored as
            strings. Empty array is OK.
    """
    phone_numbers = parse_phone_numbers(phone_numbers)
    # FOR THE LAB: ADDING USERS, YOU WILL NEED TO MODIFY THIS FUNCTION TO ADD
    # A NEW ROW TO THE `users` TABLE REPRESENTING THE NEWLY REGISTERED USER.
    # YOU MAY WANT TO CONSULT THE SQLALCHEMY DOCUMENTATION FOR THIS METHOD:
    # https://docs.sqlalchemy.org/en/13/orm/session_api.html#sqlalchemy.orm.session.Session.add
    new_user_row = User(email=email,
                        last_name=last_name,
                        first_name=first_name,
                        phone_numbers=phone_numbers)
    session.add(new_user_row)
    return True
Example #3
0
def add_user_txn(session, email, last_name, first_name, phone_numbers):
    """
    Add a new row to the User table.

    Does not currently validate phone numbers, beyond confirming that it's an
        array of strings.

    Arguments:
        email {String} -- The user's email.
        first_name {String} -- The user's first name.
        last_name {String} -- The user's last name.
        phone_numbers {Array} {String} -- The user's phone numbers, stored as
            strings. Empty array is OK.
    """
    phone_numbers = parse_phone_numbers(phone_numbers)
    user = User(email=email, last_name=last_name, first_name=first_name,
                phone_numbers=phone_numbers)
    session.add(user)

    return True