forked from RunestoneInteractive/RunestoneServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeuser.py
50 lines (42 loc) · 1.3 KB
/
makeuser.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
# running in the context of a web2py shell
import json
import sys
from psycopg2 import IntegrityError
import click
import datetime
def resetpw(username, password):
pw = CRYPT(auth.settings.hmac_key)(password)[0]
db(db.auth_user.username == username).update(password=pw)
### Main ###
if "--userfile" in sys.argv:
# find the file (.csv) iterate over each line and call createUser
pass
userinfo = json.loads(os.environ["RSM_USERINFO"])
if "--resetpw" in sys.argv:
try:
resetpw(userinfo["username"], userinfo["password"])
except Exception as e:
click.echo("Password reset failed for user {}".format(userinfo["username"]))
click.echo("Details: {}".format(e))
else:
try:
createUser(
userinfo["username"],
userinfo["password"],
userinfo["first_name"],
userinfo["last_name"],
userinfo["email"],
userinfo["course"],
userinfo["instructor"],
)
db.commit()
except ValueError as e:
click.echo("Value Error: ", e)
sys.exit(1)
except IntegrityError as e:
click.echo("Caught an integrity error: ", e)
sys.exit(2)
except Exception as e:
click.echo("Unexpected Error: ", e)
sys.exit(3)
click.echo("Exiting normally")