Example #1
0
def log_into_account():
    """

    Function to log into account

    :return: state.active_account

    """

    print("****************** LOGIN ******************")

    email = input("Email: ").strip()
    password = getpass().strip()

    account = session.query(Account).filter_by(email=email).first()

    if not account:
        secondary_func.error_msg(
            f"Could not find account with email ({email})")
        return
    elif account.password != password:
        secondary_func.error_msg(f"Password does not match")
        return

    state.active_account = account
    secondary_func.success_msg(f"\nYou are now logged in.")
    # To help with testing in the Python shell
    return state.active_account
Example #2
0
def create_account():
    """

    Function to register a cinephile user

    All inputs are given by the user through a CLI

    """

    print("****************** REGISTER ******************")

    print()
    print("Please provide the following information\n")

    email = input("Email (required): ").strip().lower()
    credit_card = input(
        "Credit-card number (required, i.e. 4444333399993333): ").strip()
    credit_card = int(credit_card)
    password = getpass().strip()
    zip_code = input("Zip-code (required): ").strip()
    zip_code = int(zip_code)
    first_name = input("What is your first name? ").strip()
    last_name = input("What is your last name? ").strip()

    # If an account already exists, tell the user, and go back to menu
    old_account = session.query(Account).filter_by(email=email).first()
    if old_account:
        secondary_func.error_msg(
            f"ERROR: Account with email {email} already exists.")
        return

    # Otherwise create the account
    account = Account(email=email,
                      credit_card=credit_card,
                      password=password,
                      zip_code=zip_code,
                      first_name=first_name,
                      last_name=last_name
                      # exclude theater_owner attribute
                      )
    session.add(account)

    # Flush
    my_account = session.query(Account).filter_by(email=email).first()

    session.commit()

    # Store the account obj as our active account
    state.active_account = account
    secondary_func.success_msg(
        f"\nCreated new account with id {state.active_account.id}")
Example #3
0
def create_account():
    """Violation of DRY principle"""

    print("****************** REGISTER THEATER OWNER ******************")

    print()
    print("Please provide the following information\n")

    email = input("Email (required): ").strip().lower()
    credit_card = input(
        "Credit-card number (required, i.e. 4444333399993333): ").strip()
    credit_card = int(credit_card)
    password = getpass().strip()
    zip_code = input("Zip-code (required): ").strip()
    zip_code = int(zip_code)
    first_name = input("What is your first name? ").strip()
    last_name = input("What is your last name? ").strip()

    old_account = session.query(Account).filter_by(email=email).first()
    if old_account:
        secondary_func.error_msg(
            f"ERROR: Account with email {email} already exists.")
        return

    account = Account(email=email,
                      credit_card=credit_card,
                      password=password,
                      zip_code=zip_code,
                      first_name=first_name,
                      last_name=last_name,
                      theater_owner=True)
    session.add(account)

    # Flush
    my_account = session.query(Account).filter_by(email=email).first()

    session.commit()

    state.active_account = account
    secondary_func.success_msg(
        f"\nCreated new account with id {state.active_account.id}")