Exemple #1
0
def get_user_data(database_connection):
    """Return user data for profile view"""
    username = userinterface.ask_for('Enter the user you would like to view')
    cursor = database_connection.cursor()
    user_row = cursor.execute('''SELECT * FROM users
                                 WHERE username = ?''', (username, ))

    return user_row
Exemple #2
0
def ask_and_verify_username(database_connection, new_user=False):
    """Ask for a verify user on log in or account creation"""
    username = userinterface.ask_for(f'Please enter a username.')
    username_verified = verify_username(database_connection, username,
                                        new_user)
    if not username_verified:
        return False
    return username
Exemple #3
0
def ask_and_verify_password():
    """Ask new user for password and verify password is
    strong enough"""
    password = userinterface.ask_for('Please enter a new password.')
    password_verified = verify_new_password(password)
    if not password_verified:
        return False
    return password
Exemple #4
0
def new_username_setup(database_connection, signed_in):
    """Change the users username"""
    print(f'Current username: {signed_in.username}')
    new_username = userinterface.ask_for('Please enter a new username')
    userdata.set_new_username(database_connection,
                              signed_in,
                              new_username=new_username)
    signed_in.username = new_username
    print('Username changed!')
Exemple #5
0
def verify_existing_password_for_update(signed_in):
    """Ask user for password to verify"""
    old_password_on_file = signed_in.password
    check_password = userinterface.ask_for(
        'Please enter your current password')
    same_password = old_password_on_file == check_password
    if not same_password:
        print('Incorrect password.')
        return False
    return True
Exemple #6
0
def new_password_setup(database_connection, signed_in):
    """Change the users password"""
    if verify_existing_password_for_update(signed_in):
        new_password = userinterface.ask_for('Please enter a new password')
        password_verified = verify_new_password(new_password)
        if password_verified:
            userdata.set_new_password(database_connection,
                                      signed_in,
                                      new_password=new_password)
            signed_in.password = new_password
            print('Password changed!')
Exemple #7
0
def sign_in(database_connection):
    """Sign in from existing user account"""
    username = ask_and_verify_username(database_connection, new_user=False)
    if not username:
        print('Username does not exist')
        return False
    password = userinterface.ask_for('Please enter your password.')
    signed_in = validate_user_sign_in(database_connection, username, password)
    if not signed_in:
        print('Password incorrect!')
        return False
    return signed_in
Exemple #8
0
def create_account(database_connection):
    """Create a new user account"""
    username = ask_and_verify_username(database_connection, new_user=True)
    if not username:
        return False
    password = ask_and_verify_password()
    if not password:
        return False
    user_id = generate_user_id(username)
    location = userinterface.ask_for('Please enter your location')
    # post_number = ask_and_verify_timeline_preferences()

    user_data = (user_id, username, password, location, 6)
    if not all(user_data):
        print('Something went wrong! Unable to create account.')
        return False
    return confirm_new_user_added_to_database(user_data, database_connection,
                                              username, password)