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}")
def insert_account_data(session): """Insert data for account Table""" # First check if there's existing data existing_account = session.query(Account).first() if existing_account: return else: for i in accounts_list: account = Account(email=i[0], credit_card=i[1], password=i[2], zip_code=i[3], first_name=i[4], last_name=i[5]) session.add(account) session.commit()
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}")