-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
executable file
·35 lines (30 loc) · 1.32 KB
/
script.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
from flask.ext.script import Command, prompt, Option
from flask.ext.security.script import CreateUserCommand, AddRoleCommand
from flask_security.utils import encrypt_password
from user.models import Role, User
class InstallCommand(Command):
def run(self, **kwargs):
# check if admin exists
a = Role.objects.filter(name='admin').first()
if a is None:
Role(name='admin').save()
Role(name='manager').save()
Role(name='resident').save()
Role(name='staff').save()
u = prompt('Admin Email?', default='[email protected]')
p = prompt('Admin Password (min 6 characters)?', default='enferno')
CreateUserCommand().run(email=u, password=p, active=1)
AddRoleCommand().run(user_identifier=u, role_name='admin')
else:
print 'Seems like an Admin is already installed'
class ResetUserCommand(Command):
option_list = (
Option('-e', '--email', dest='email', default=None),
Option('-p', '--password', dest='password', default=None),
)
def run(self, **kwargs):
try:
pwd = encrypt_password(kwargs['password'])
User.objects(email=kwargs['email']).first().update(set__password=pwd)
except Exception, e:
print ('Error resetting user password: %s' % e)