Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. # i made at home and put it in a paste bin
  2. import time
  3.  
  4. # All accounts
  5. users = {
  6. "root": {
  7. "password": "unity",
  8. "group": "admin",
  9. "mail": []
  10. }
  11. }
  12.  
  13. # Form validation
  14. def validate(form):
  15. if len(form) > 0:
  16. return False
  17. return True
  18.  
  19. # Login authorization
  20. def loginauth(username, password):
  21. if username in users:
  22. if password == users[username]["password"]:
  23. print("Login successful")
  24. return True
  25. return False
  26.  
  27. # Login
  28. def login():
  29. while True:
  30. username = input("Username: ")
  31. if not len(username) > 0:
  32. print("Username can't be blank")
  33. else:
  34. break
  35. while True:
  36. password = input("Password: ")
  37. if not len(password) > 0:
  38. print("Password can't be blank")
  39. else:
  40. break
  41.  
  42. if loginauth(username, password):
  43. return session(username)
  44. else:
  45. print("Invalid username or password")
  46.  
  47. # Register
  48. def register():
  49. while True:
  50. username = input("New username: ")
  51. if not len(username) > 0:
  52. print("Username can't be blank")
  53. continue
  54. else:
  55. break
  56. while True:
  57. password = input("New password: ")
  58. if not len(password) > 0:
  59. print("Password can't be blank")
  60. continue
  61. else:
  62. break
  63. print("Creating account...")
  64. users[username] = {}
  65. users[username]["password"] = password
  66. users[username]["group"] = "user"
  67. users[username]["mail"] = []
  68. time.sleep(1)
  69. print("Account has been created")
  70.  
  71. # Send mail
  72. def sendmail(username):
  73. while True:
  74. recipient = input("Recipient > ")
  75. if not len(recipient) > 0:
  76. print("Recipient can't be blank")
  77. continue
  78. elif recipient not in users:
  79. print("There is no account with that username")
  80. continue
  81. else:
  82. break
  83. while True:
  84. subject = input("Subject > ")
  85. if not len(subject) > 0:
  86. print("Subject can't be blank")
  87. continue
  88. else:
  89. break
  90. while True:
  91. context = input("Context > ")
  92. if not len(context) > 0:
  93. print("Context can't be blank")
  94. else:
  95. break
  96. print("Sending mail...")
  97. users[recipient]["mail"].append(["Sender: " + username, "Subject: " + subject, "Context: " + context])
  98. time.sleep(1)
  99. print("Mail has been sent to " + recipient)
  100.  
  101. # User session
  102. def session(username):
  103. print("Welcome to your account " + username)
  104. print("Options: view mail | send mail | logout")
  105. if users[username]["group"] == "admin":
  106. print("")
  107. while True:
  108. option = input(username + " > ")
  109. if option == "logout":
  110. print("Logging out...")
  111. break
  112. elif option == "view mail":
  113. print("Current mail:")
  114. for mail in users[username]["mail"]:
  115. print(mail)
  116. elif option == "send mail":
  117. sendmail(username)
  118. elif users[username]["group"] == "admin":
  119. if option == "user mail":
  120. print("Whos mail would you like to see?")
  121. userinfo = input("> ")
  122. if userinfo in users:
  123. for mail in users[userinfo]["mail"]:
  124. print(mail)
  125. else:
  126. print("There is no account with that username")
  127. elif option == "delete mail":
  128. print("Whos mail would you like to delete?")
  129. userinfo = input("> ")
  130. if userinfo in users:
  131. print("Deleting " + userinfo + "'s mail...")
  132. users[userinfo]["mail"] = []
  133. time.sleep(1)
  134. print(userinfo + "'s mail has been deleted")
  135. else:
  136. print("There is no account with that username")
  137. elif option == "delete account":
  138. print("Whos account would you like to delete?")
  139. userinfo = input("> ")
  140. if userinfo in users:
  141. print("Are you sure you want to delete " + userinfo + "'s account?")
  142. print("Options: yes | no")
  143. while True:
  144. confirm = input("> ")
  145. if confirm == "yes":
  146. print("Deleting " + userinfo + "'s account...")
  147. del users[userinfo]
  148. time.sleep(1)
  149. print(userinfo + "'s account has been deleted")
  150. break
  151. elif confirm == "no":
  152. print("Canceling account deletion...")
  153. time.sleep(1)
  154. print("Account deletion canceled")
  155. break
  156. else:
  157. print(confirm + " is not an option")
  158. else:
  159. print("There is no account with that username")
  160. else:
  161. print(option + " is not an option")
  162.  
  163. # On start
  164. print("Welcome to the system. Please register or login.")
  165. print("Options: register | login | exit")
  166. while True:
  167. option = input("> ")
  168. if option == "login":
  169. login()
  170. elif option == "register":
  171. register()
  172. elif option == "exit":
  173. break
  174. else:
  175. print(option + " is not an option")
  176.  
  177. # On exit
  178. print("Shutting down...")
  179. time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement