コード例 #1
0
def handleLogin():
    # ask user for email and password
    user_email = input("Email: ")
    user_pw = getpass.getpass()

    # queries
    checkIfUserExists = "SELECT email FROM users WHERE email = '" + user_email + "' AND pass = '******'"
    checkIfAgent = "SELECT email FROM airline_agents WHERE email = '" + user_email + "'"

    # check if user exists
    db = main.getDatabase()
    db.execute(checkIfUserExists)
    user_results = db.cursor.fetchall()

    if len(user_results) > 0: # user exists!
        db.execute(checkIfAgent)
        agent_results = db.cursor.fetchall()
        if len(agent_results) > 0:
             menu = agentMenu.AgentMenu(user_email) # agents should lead to agent menu
        else:
            menu = userMenu.UserMenu(user_email)    # normal users go to user menu
        menu.showMenu()
    else: 
        print("User does not exist or password is incorrect.")
        main.showMainMenu()
コード例 #2
0
def handleRegister():
    # ask for email and password
    print("Please register your email and password.\n")
    user_email = input("Email: ")
    user_pw = getpass.getpass()

    # queries
    checkIfUserExists = "SELECT email FROM users WHERE email = '" + user_email + "'"
    addToUsers = "INSERT INTO users VALUES('" + user_email + "', '" + user_pw + "', SYSDATE)"

    # check if user exists
    db = main.getDatabase()
    db.execute(checkIfUserExists)
    user_results = db.cursor.fetchall()
    if len(user_results) > 0:  # user exists!
        print("User already exists. Please log in.\n")
        main.showMainMenu()

    # valid email check from: http://stackoverflow.com/questions/8022530/python-check-for-valid-email-address
    if not re.match(r"[^@]+@[^@]+\.[^@]+", user_email):
        print("Not a valid email. Please try again.")
        handleRegister()
    if (len(user_pw) > 4):
        print("Password must NOT be more than 4 characters.")
        handleRegister()
    else:  # everything is valid! go ahead and add to user table
        db.execute(addToUsers)
        db.execute("commit")
        print("You've successfully registered! Please log in.\n")
コード例 #3
0
def handleRegister():
    # ask for email and password
    print("Please register your email and password.\n")
    user_email = input("Email: ")
    user_pw = getpass.getpass()

    # queries
    checkIfUserExists = "SELECT email FROM users WHERE email = '" + user_email + "'"
    addToUsers = "INSERT INTO users VALUES('" + user_email + "', '" + user_pw + "', SYSDATE)"

    # check if user exists
    db = main.getDatabase()
    db.execute(checkIfUserExists)
    user_results = db.cursor.fetchall()
    if len(user_results) > 0: # user exists!
        print("User already exists. Please log in.\n")
        main.showMainMenu()
    
    # valid email check from: http://stackoverflow.com/questions/8022530/python-check-for-valid-email-address
    if not re.match(r"[^@]+@[^@]+\.[^@]+", user_email):
        print("Not a valid email. Please try again.")
        handleRegister()
    if (len(user_pw) > 4):
        print("Password must NOT be more than 4 characters.")
        handleRegister()
    else:   # everything is valid! go ahead and add to user table
        db.execute(addToUsers)
        db.execute("commit")   
        print("You've successfully registered! Please log in.\n")
コード例 #4
0
 def showMenu(self):
     # user menu plus more
     while True:
         userInput = input("Search for flights (S) or List existing bookings (B), Logout (L)?  ")
         if (userInput == "S"):
             m = input("Would you like to search for multiple passengers? (y/n): ")
             if m == 'y' or m == 'Yes' or m =='yes':
                 self.promptAndSearchForFlights(True)
             else:
                 self.promptAndSearchForFlights()
         elif (userInput == "B"):
             self.showExistingBookings()
             self.promptForBooking()
         elif (userInput == "RD"):
             print("Recording flight departure. ")
             (fno, date) = self.findFlight()
             update = self.promptUpdate()
             self.recordDep(fno, date, update)
         elif (userInput == "RA"):
             print("Recording flight arrival. ")
             (fno, date) = self.findFlight()
             update = self.promptUpdate()
             self.recordArr(fno, date, update)
         elif (userInput == "L"):
             self.setLastLogin()
             main.showMainMenu()
         else: 
             print("Pick a valid option. \n")
コード例 #5
0
 def showMenu(self):
     """
     This shows the user menu for searching flights, listing existing bookings or logging out.
     """
     while True:
         userInput = input("Search for flights (S) or List existing bookings (B), Logout (L)?  ")
         if (userInput == "S"):
             m = input("Would you like to search for multiple passengers? (y/n): ")
             if m == 'y' or m == 'Yes' or m =='yes':
                 self.promptAndSearchForFlights(True)
             else:
                 self.promptAndSearchForFlights()
         elif (userInput == "B"):
             self.showExistingBookings()
             self.promptForBooking()
         elif (userInput == "L"):
             self.setLastLogin()
             main.showMainMenu()
         else: 
             print("Pick a valid option. \n")
コード例 #6
0
 def showMenu(self):
     """
     This shows the user menu for searching flights, listing existing bookings or logging out.
     """
     while True:
         userInput = input(
             "Search for flights (S) or List existing bookings (B), Logout (L)?  "
         )
         if (userInput == "S"):
             m = input(
                 "Would you like to search for multiple passengers? (y/n): "
             )
             if m == 'y' or m == 'Yes' or m == 'yes':
                 self.promptAndSearchForFlights(True)
             else:
                 self.promptAndSearchForFlights()
         elif (userInput == "B"):
             self.showExistingBookings()
             self.promptForBooking()
         elif (userInput == "L"):
             self.setLastLogin()
             main.showMainMenu()
         else:
             print("Pick a valid option. \n")