Advertisement
Guest User

Untitled

a guest
Mar 27th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.07 KB | None | 0 0
  1. #!/usr/local/bin/python3
  2.  
  3. import random, time, os, string
  4.  
  5. #Clear Class Variables
  6. def clearClasses():
  7.     newStaff=None
  8.     newStudent=None
  9.  
  10. #Clear Terminal Screen
  11. def cls():
  12.     os.system('cls' if os.name=='nt' else 'clear')
  13.     pass
  14.  
  15. #Remove punctuation characters from input date
  16. def dateCheck(date):
  17.     if (date.find(string.punctuation)):
  18.         date=date.translate(None, string.punctuation)
  19.         return date
  20.  
  21. #Capitalize Names
  22. def cleanInput(name):
  23.     x=string.upper(name[0])
  24.     name=x+name[1:]
  25.     return name
  26.  
  27. #User selects account type (staff or student)
  28. def typeSelect():
  29.     print("-"*90)
  30.     print("""
  31.    \nPlease select the type of user:
  32.  
  33.    1. Student
  34.    2. Staff
  35.    3. Cancel/Exit
  36.    """)
  37.     userType=input("Your Selection: ")
  38.     if userType==2:
  39.         userType="staff"
  40.     elif userType==1:
  41.         userType="student"
  42.     else:
  43.         print("Ending Script")
  44.         exit()
  45.     return userType
  46.  
  47. #Student user class
  48. class newStudent:
  49.     firstName = ""
  50.     lastName = ""
  51.     birthday = ""
  52.     startDate = ""
  53.  
  54. #staff user class
  55. class newStaff:
  56.     firstName = ""
  57.     lastName = ""
  58.     startdate = ""
  59.  
  60. #New user profile data
  61. def inputInfo(userCheck):
  62.     print("-"*90+"\n")
  63.     print("*"*90)
  64.     print("\n\nPlease enter the user info\n\n")
  65.     print("*"*90+"\n\n")
  66.     if userCheck == "student":
  67.         newStudent.firstName=raw_input("New Student First Name: ")
  68.         newStudent.lastName=raw_input("New Student Last Name: ")
  69.         newStudent.birthday=raw_input("New Student Birthday: ")
  70.         newStudent.birthday=dateCheck(newStudent.birthday)
  71.         newStudent.startDate=raw_input("New Student Start Date: ")
  72.         newStudent.startDate=dateCheck(newStudent.startDate)
  73.         print("\n\n"+"*"*90+"\n")
  74.         time.sleep(1)
  75.         cls()
  76.         return newStudent
  77.     if userCheck == "staff":
  78.         newStaff.firstName=raw_input("New Staff First Name: ")
  79.         newStaff.lastName=raw_input("New Staff Last Name: ")
  80.         newStaff.startDate=raw_input("New Staff Start Date: ")
  81.         print("\n\n"+"*"*90+"\n")
  82.         time.sleep(1)
  83.         cls()
  84.         return newStaff
  85.  
  86. #Generate Student user password FLastnameMMDDYYYY
  87. def studentPasswordGen(firstName, lastName, birthday):
  88.     x= string.upper(firstName[0])
  89.     y= string.upper(lastName[0])
  90.     f= lastName[1:]
  91.     z= str(y)+str(f)
  92.     pw= str(x) + str(z) + str(birthday)
  93.     return pw
  94.  
  95. def staffPasswordGen():
  96.     charSet=string.ascii_uppercase+ string.ascii_lowercase+ string.digits
  97.     return ("".join(random.choice(charSet) for i in range(12)))
  98.  
  99. #Run student user creation script (GAM)
  100. def studentCreation(firstName, lastName, password, startDate):
  101.     print("Running GAM...")
  102.     x=str(random.randint(0,9))+str(random.randint(0,9))+str(random.randint(0,9))+str(random.randint(0,9))
  103.     os.system("~/bin/gam/gam create user "+firstName[0]+lastName[0]+x+" firstname "+firstName+" lastName "+lastName+" password "+password+" org '/kec root/restart/students' changepassword off")
  104.  
  105. #Run staff user creation script (GAM)
  106. def staffCreation(firstName, lastName, password, startDate):
  107.     print("Running GAM...")
  108.     os.system("~/bin/gam/gam create user "+firstName[0]+lastName+" firstname " +firstName+" lastname "+lastName+" password "+password)
  109.  
  110. #Print data input and confirmation request.
  111. def printData(userCheck):
  112.     print("-"*90+"\n")
  113.     print("New Account Info to be Input: \n")
  114.     if userCheck=="student":
  115.         password=studentPasswordGen(newStudent.firstName, newStudent.lastName, newStudent.birthday)
  116.         print("*"*90+"\n\n")
  117.         newStudent.firstName=cleanInput(newStudent.firstName)
  118.         newStudent.lastName=cleanInput(newStudent.lastName)
  119.         print("New Student First Name: "+newStudent.firstName)
  120.         print("New Student Last Name: "+newStudent.lastName)
  121.         print("New Student Password: "+str(password))
  122.         print("New Student Start Date: "+newStudent.startDate)
  123.         print("\n\n"+"*"*90+"\n")
  124.         print("""If this information is correct please make appropriate selection:
  125.            1: Yes this information is correct.
  126.            2: No this information is incorrect.\n""")
  127.         selection=raw_input("Please make selection (1 or 2):    ")
  128.         if selection=="1":
  129.             #move forward
  130.             print("*"*90+"\n\n")
  131.             print("Moving forward...")
  132.             print("\n\n"+"*"*90+"\n")
  133.             studentCreation(newStudent.firstName, newStudent.lastName, password, newStudent.startDate)
  134.         elif selection=="2":
  135.             print("*"*90+"\n\n")
  136.             print("Starting over...")
  137.             print("\n\n"+"*"*90+"\n")
  138.             time.sleep(3)
  139.             Main()
  140.         else:
  141.             printData(userCheck)
  142.     if userCheck=="staff":
  143.         password=staffPasswordGen()
  144.         newStaff.firstName=cleanInput(newStaff.firstName)
  145.         newStaff.lastName=cleanInput(newStaff.lastName)
  146.         print("*"*90+"\n\n")
  147.         print("New Staff First Name: "+newStaff.firstName)
  148.         print("New Staff Last Name: "+newStaff.lastName)
  149.         print("New Staff Password: "+str(password))
  150.         print("New Staff Start Date: "+newStaff.startDate)
  151.         print("\n\n"+"*"*90+"\n")
  152.         print("""If this information is correct please make appropriate selection:
  153.            1: Yes this information is correct.
  154.            2: No this information is incorrect.\n""")
  155.         selection=raw_input("Please make selection (1 or 2):    ")
  156.         if selection=="1":
  157.             #move forward
  158.             print("*"*90+"\n\n")
  159.             print("Moving forward...")
  160.             print("\n\n"+"*"*90+"\n")
  161.             staffCreation(newStaff.firstName, newStaff.lastName, password, newStaff.startDate)
  162.         elif selection=="2":
  163.             print("*"*90+"\n\n")
  164.             print("Starting over...")
  165.             print("\n\n"+"*"*90+"\n")
  166.             time.sleep(3)
  167.             Main()
  168.         else:
  169.             printData(userCheck)
  170.  
  171.  
  172. def Main():
  173.     cls()
  174.     clearClasses()
  175.     userType = typeSelect()
  176.     inputInfo(userType)
  177.     printData(userType)
  178.     clearClasses()
  179.  
  180. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement