Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. import os
  2. rootpath = 'UserManagement'
  3. adminlog = rootpath+'/admin.log'
  4. userlog = rootpath+'/users.log'
  5. emaillog = rootpath+'/emails.log'
  6. currentuser = ''
  7.  
  8. if os.path.exists(rootpath) == False:
  9. os.mkdir(rootpath)
  10.  
  11. if os.path.exists(adminlog) == False:
  12. print 'Create a Admin User'
  13. user = raw_input('Enter a username: ')
  14. passw = raw_input('Enter a password: ')
  15. if ' ' in user or ' ' in passw:
  16. print 'No spaces in User/Pass'
  17. else:
  18. f = open(adminlog,'w')
  19. f.write(user+'\n'+passw)
  20. f.close()
  21.  
  22. if os.path.exists(userlog) == False:
  23. open(userlog,'w').close()
  24. if os.path.exists(emaillog) == False:
  25. open(emaillog,'w').close()
  26.  
  27. print 'Welcome to the simple user management system'
  28. l_in = False
  29. a_in = False
  30. while True:
  31. print '\n'
  32. if l_in == True:
  33. print 'You are logged in as',currentuser,'(User)'
  34. elif a_in == True:
  35. print 'You are logged in as',currentuser,'(Admin)'
  36.  
  37. if l_in == False and a_in == False:
  38. print '[1] Login\n[2] Register\n'
  39. _in = int(raw_input('>> '))
  40. if _in == 1:
  41. user = raw_input('User: ')
  42. passw = raw_input('Pass: ')
  43. admin = open(adminlog,'r').readlines()
  44. if admin[0] == user+'\n' and admin[1] == passw:
  45. currentuser = user
  46. print 'Loged in as Admin!'
  47. l_in = False
  48. a_in = True
  49. else:
  50. lines = open(userlog,'r').readlines()
  51. users = list()
  52. for i in lines:
  53. users.append(i.split('\n')[0])
  54.  
  55. for iuser in users:
  56. if iuser != '':
  57. u = iuser.split(' ')[0]
  58. p = iuser.split(' ')[1]
  59.  
  60. if u == user and p == passw:
  61. currentuser = user
  62. print 'Loged in as User'
  63. l_in = True
  64. a_in = False
  65. elif _in == 2:
  66. f = open(userlog,'a')
  67. user = raw_input('User: ')
  68. passw = raw_input('Pass: ')
  69. if ' ' in user or ' ' in passw:
  70. print 'No spaces in User/Pass'
  71. else:
  72. f.write(user + ' ' + passw + '\n')
  73. f.close()
  74.  
  75. elif l_in == True and a_in == False:
  76. print '[1] Add Email\n[2] Get Emails'
  77. _in = int(raw_input('>> '))
  78. if _in == 1:
  79. f = open(emaillog,'a')
  80. e = raw_input("Email to add: ")
  81. f.write(currentuser + ':' + e+'\n')
  82. f.close()
  83. elif _in == 2:
  84. emails = open(emaillog,'r').readlines()
  85. for i in emails:
  86. if i.split('\n')[0].split(':')[0] == currentuser:
  87. print i.split(':')[1][:-1]
  88.  
  89.  
  90. elif a_in == True and l_in == False:
  91. print '[1] Add User'
  92. _in = int(raw_input(">> "))
  93. if _in == 1:
  94. f = open(userlog,'a')
  95. user = raw_input('User: ')
  96. passw = raw_input('Pass: ')
  97. if ' ' in user or ' ' in passw:
  98. print 'No spaces in User/Pass'
  99. else:
  100. f.write(user + ' ' + passw + '\n')
  101. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement