Guest User

Untitled

a guest
Nov 23rd, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. def get_file_contents(file_path):
  2. return [line.strip() for line in open(file_path)]
  3.  
  4. hourslist = get_file_contents(hours_path)
  5.  
  6. def add_file_contents(file_path, contents):
  7. with open(file_path, "a") as file:
  8. file.write(contents)
  9.  
  10. def login_user(new_account=False):
  11. usernameslist = get_file_contents(users_path)
  12. passwordslist = get_file_contents(passwords_path)
  13.  
  14. if new_account:
  15. response = 'y'
  16. else:
  17. print(print_in_yellow)
  18. response = input("-"*50 + "nDo you have an account (y/n)? ")
  19. print("-"*50)
  20. print(print_default)
  21.  
  22. #If user has an account:
  23. if response == "y":
  24. goodlogin = False
  25.  
  26. #Ask user for unsername and password
  27. username = input("-"*50 + "nPlease enter your username: ")
  28. password = input("Please enter your password: ")
  29.  
  30. #For the id in the usernames list: if the index of the id and password match
  31. #and the username and password are correct, there is a good login
  32. for id in range(len(usernameslist)):
  33. if username == usernameslist[id] and password == passwordslist[id]:
  34. goodlogin = True
  35.  
  36. #If their login works:
  37. if goodlogin:
  38. #Tell the user access has been granted
  39. print(print_in_green + "Access granted!" + print_default + "n" + "-"*50)
  40.  
  41. #Part 4:Log user in to practice
  42. #Ask if user is loging into a practice
  43. print(print_in_pink)
  44. practice = input("nnnWould you like to log a practice (y/n)? ")
  45. print(print_default)
  46.  
  47. #If thet want to log in to a practice:
  48. if practice == "y":
  49. practice_hours = input("How many hours are you practing for? (PLEASE ROUND TO THE NEAREST HOUR) ")
  50. add_file_contents(hours_path, practice_hours + "n")
Add Comment
Please, Sign In to add comment