Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- rootpath = 'UserManagement'
- adminlog = rootpath+'/admin.log'
- userlog = rootpath+'/users.log'
- emaillog = rootpath+'/emails.log'
- currentuser = ''
- if os.path.exists(rootpath) == False:
- os.mkdir(rootpath)
- if os.path.exists(adminlog) == False:
- print 'Create a Admin User'
- user = raw_input('Enter a username: ')
- passw = raw_input('Enter a password: ')
- if ' ' in user or ' ' in passw:
- print 'No spaces in User/Pass'
- else:
- f = open(adminlog,'w')
- f.write(user+'\n'+passw)
- f.close()
- if os.path.exists(userlog) == False:
- open(userlog,'w').close()
- if os.path.exists(emaillog) == False:
- open(emaillog,'w').close()
- print 'Welcome to the simple user management system'
- l_in = False
- a_in = False
- while True:
- print '\n'
- if l_in == True:
- print 'You are logged in as',currentuser,'(User)'
- elif a_in == True:
- print 'You are logged in as',currentuser,'(Admin)'
- if l_in == False and a_in == False:
- print '[1] Login\n[2] Register\n'
- _in = int(raw_input('>> '))
- if _in == 1:
- user = raw_input('User: ')
- passw = raw_input('Pass: ')
- admin = open(adminlog,'r').readlines()
- if admin[0] == user+'\n' and admin[1] == passw:
- currentuser = user
- print 'Loged in as Admin!'
- l_in = False
- a_in = True
- else:
- lines = open(userlog,'r').readlines()
- users = list()
- for i in lines:
- users.append(i.split('\n')[0])
- for iuser in users:
- if iuser != '':
- u = iuser.split(' ')[0]
- p = iuser.split(' ')[1]
- if u == user and p == passw:
- currentuser = user
- print 'Loged in as User'
- l_in = True
- a_in = False
- elif _in == 2:
- f = open(userlog,'a')
- user = raw_input('User: ')
- passw = raw_input('Pass: ')
- if ' ' in user or ' ' in passw:
- print 'No spaces in User/Pass'
- else:
- f.write(user + ' ' + passw + '\n')
- f.close()
- elif l_in == True and a_in == False:
- print '[1] Add Email\n[2] Get Emails'
- _in = int(raw_input('>> '))
- if _in == 1:
- f = open(emaillog,'a')
- e = raw_input("Email to add: ")
- f.write(currentuser + ':' + e+'\n')
- f.close()
- elif _in == 2:
- emails = open(emaillog,'r').readlines()
- for i in emails:
- if i.split('\n')[0].split(':')[0] == currentuser:
- print i.split(':')[1][:-1]
- elif a_in == True and l_in == False:
- print '[1] Add User'
- _in = int(raw_input(">> "))
- if _in == 1:
- f = open(userlog,'a')
- user = raw_input('User: ')
- passw = raw_input('Pass: ')
- if ' ' in user or ' ' in passw:
- print 'No spaces in User/Pass'
- else:
- f.write(user + ' ' + passw + '\n')
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement