예제 #1
0
def change_password(*, account: Account, current_password: str,
                    new_password: str) -> Account:
    if account.password != hashed_password(current_password):
        raise InvalidInputFormat("Wrong current password.")
    password_format_check(new_password)
    account.password = hashed_password(new_password)
    account.save()
예제 #2
0
def login_loop():
    views.login_welcome()
    while True:
        views.display_login_menu()
        choice = views.get_login_choice()
        if int(choice) > 3:
            print("That is not an option!")
        #CREATE AN ACCOUNT																					
        elif int(choice) == 1:																										
            print("-----Create an Account-----")																								
            full_name = input("What is your full name?: ")	
            values = {"full_name":full_name, "pin": views.input_new_pin(), "balance": 0.00}		
            new_account = Account(**values)
            new_account.save()													
            print("Account Created! Your account number is:", new_account.account_number)													
            continue
        #LOGIN TO EXISTING ACCOUNT										
        elif int(choice) == 2:	
            account_num = views.get_login_num()
            pin = views.input_pin()
            if Account.validate(account_num, pin) == True: 
                loaded_account = Account.load_account(account_num, pin)
                print("This is your loaded account: ", loaded_account.account_number)
                return loaded_account
        #EXIT PROGRAM
        elif int(choice) == 3:													
            break															
예제 #3
0
def create_account(*, username: str, password: str, email: str,
                   account_type: str) -> Account:
    """
    Create user account if not exist. Return Account object on success, None on failure.
    """
    username_format_check(username)
    password_format_check(password)
    account_type_check(account_type)
    account = Account.objects.filter(username=username).first()
    if account:
        return None
    account = Account(username=username,
                      password=hashed_password(password),
                      account_type=account_type)
    account.save()
    create_email(email=email, account=account)
    return account
예제 #4
0
def create_account(*, username: str, password: str, email: str,
                   account_type: str) -> Account:
    """
    Create user account if not exist. Return Account object on success, None on failure.
    """
    username_format_check(username)
    password_format_check(password)
    account_type_check(account_type)
    account = Account.objects.filter(username=username).first()
    if account:
        user_existed = True
        return user_existed, {
            'access_token': '',
            'account': {
                'id': 0,
                'username': '',
                'account_type': '',
            }
        }
    else:
        user_existed = False
        account = Account(username=username,
                          password=hashed_password(password),
                          account_type=account_type)
        account.save()
        create_email(email=email, account=account)

        account = Account.objects.filter(
            username=username, password=hashed_password(password)).first()
        access_token = generate_access_token(account)
        return user_existed, {
            'access_token': access_token,
            'account': {
                'id': account.id,
                'username': account.username,
                'account_type': account.account_type,
            }
        }