-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitdb.py
57 lines (48 loc) · 1.3 KB
/
initdb.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
from lib.api.db import db, Users
from lib.api.auth import UserRoles
from werkzeug.security import generate_password_hash
import logging
import config
print(config.SQLALCHEMY_CONNSTR)
def add_user(username, password, role):
try:
n = Users.query.filter_by(username=username).first()
if n == None:
n = Users(username=username, role=[role.value])
n.set_password(password)
db.session.add(n)
else:
n.role = [role.value]
n.set_password(password)
db.session.flush()
db.session.commit()
except Exception as ex:
logging.error(str(ex))
db.session.rollback()
finally:
db.session.flush()
db.session.commit()
try:
db.create_all()
except:
db.session.rollback()
for key in ['runar', 'antoni']:
add_user(key, key, UserRoles.SUPERADMIN)
for key in ['vidzeme', 'hame', 'galilee']:
add_user(key, key, UserRoles.ADMIN)
for key in ['demo', 'patrick', 'pavel', 'test']:
add_user(key, key, UserRoles.VIEWER)
for key in [
"apulia",
"central_greece",
"central_bohemia",
"flanders",
"galilee",
"gevgelija",
"hame",
"monaghan",
"segobriga",
"slovakia",
"vidzeme"]:
add_user(key, key, UserRoles.VIEWER)
add_user("%s_admin" % key, "%s1234" % key, UserRoles.ADMIN)