-
Notifications
You must be signed in to change notification settings - Fork 0
/
adduser.py
61 lines (42 loc) · 1.31 KB
/
adduser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from socbot.userdb import UserDB, NoSuchUser
def getInput(prefix):
retn = ""
while not retn:
retn = raw_input(prefix+": ")
return retn
def getBool(prefix):
retn = ""
while not retn.lower() in ["y","n"]:
retn = getInput(prefix+ " [y/n]")
if retn == "y":
return True
return False
network = getInput("User's network")
username = getInput("User's login name").lower()
db = UserDB('conf/%s-users.db' % network.lower())
try:
user = db.getRegistration(username)
except NoSuchUser:
user = None
if user:
print "This user already exists. Continuing with existing user."
else:
# Get password
while True:
password = getInput("User's password")
passconf = getInput("User's password (confirm)")
if password == passconf:
break
print "Unmatched passwords, try again."
# Get email
email = getInput("User's email")
# Create user
user = db.getUser(username)
user = user.register(username, password, email)
# Check if should get * perm
superuser = getBool("Make user a superuser")
if superuser:
if not user.hasPerm("*"):
user.addPerm("*")
db.saveSession()
print "Done."