May-14-2022, 02:25 PM
Hello,
I'm playing around with npyscreen to make my terminal application look nicer and be more user friendly.
I'm trying to take in the user's input from self.user and seld.password and carry them over to my validate function so it can go to the menu screen.
Am I passing the values correctly? If not, how do I?
Thanks I advance.
TUITest.py
This was my working terminal version and I want to carry it over to npyscreen so it looks nicer.
This is what I'm trying to achieve but with a fancy TUI
I'm playing around with npyscreen to make my terminal application look nicer and be more user friendly.
I'm trying to take in the user's input from self.user and seld.password and carry them over to my validate function so it can go to the menu screen.
Am I passing the values correctly? If not, how do I?
Thanks I advance.
TUITest.py
import npyscreen class LoginForm(npyscreen.Form): def afterEditing(self): self.parentApp.setNextForm(None) def create(self): self.user = self.add(npyscreen.TitleText, name='Name:') self.password = self.add(npyscreen.TitleText, name='Password:') user = self.user password = self.password validate(user,password) class MyApplication(npyscreen.NPSAppManaged): def onStart(self): self.addForm('MAIN', LoginForm, name='Log In') if __name__ == '__main__': TestApp = MyApplication().run()My Validate Function
#--------------------------------------------------------------- # Validate Function -> Validates user #--------------------------------------------------------------- #Pass in user and password variables from login function #Check if the user is valid (registered in database) -> Give access to inventory program #close login screen and open menu screen #If user is not valid -> return to login or have invalid credentials popup #-->TODO: Write the user and current date to a file to keep track of logins def validate(user, password): if StandardUsers().get(user) == password: print('Success! You are now logged in as: ' + user) #mainMenu() return True if SuperUsers().get(user) == password: print('Success! You are now logged in as: ' + user) #adminMenu() else: return #---------------------------------------------------------------Side notes:
This was my working terminal version and I want to carry it over to npyscreen so it looks nicer.
This is what I'm trying to achieve but with a fancy TUI
#--------------------------------------------------------------- # Login Menu #--------------------------------------------------------------- def login(): while True: print('=============================\n''\tLogin\n''=============================') user = input("Enter your name (Case Sensitive): ") password = input("Enter your password: ") #If the credentials are validated -> Run validate function -> Go to according menu #Else -> Print error message and show login screen again if validate(user, password): break else: print('You are not registered to use this program') #--------------------------------------------------------------- #--------------------------------------------------------------- # Validate Function -> Validates user #--------------------------------------------------------------- #Pass in user and password variables from login function #Check if the user is valid (registered in database) -> Give access to inventory program #If user is not valid -> return to login #-->TODO: Write the user and current date to a file to keep track of logins def validate(user, password): if StandardUsers().get(user) == password: print('Success! You are now logged in as: ' + user) mainMenu() return True if SuperUsers().get(user) == password: print('Success! You are now logged in as: ' + user) adminMenu() else: return #---------------------------------------------------------------