update cli command
This commit is contained in:
parent
8c31b877f5
commit
1a244b52b9
1 changed files with 18 additions and 5 deletions
|
@ -1,11 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
import argparse
|
||||
import validators
|
||||
from hashlib import md5
|
||||
from uuid import uuid4
|
||||
|
||||
from SWSCloudCore import models
|
||||
|
||||
__author__ = 'vanzhiganov'
|
||||
|
||||
"""
|
||||
Утилита добавления администратора
|
||||
Как использовать:
|
||||
swscloud-admin-add.py --email admin@cloud.com --password qwerty
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(description='')
|
||||
parser.add_argument('--email', dest="email")
|
||||
|
@ -13,12 +19,19 @@ parser.add_argument('--password', dest="password")
|
|||
|
||||
args = parser.parse_args()
|
||||
|
||||
# validate admin email
|
||||
if not validators.email(args.email):
|
||||
sys.exit('invalid email format')
|
||||
|
||||
admin_id = uuid4()
|
||||
# todo: validate admin email
|
||||
admin_email = args.email
|
||||
admin_password = md5(args.password).hexdigest()
|
||||
|
||||
models.database.connect()
|
||||
|
||||
if models.Admins.select().where(models.Admins.email == args.email).count() == 0:
|
||||
models.Admins.create(id=admin_id, email=admin_email, password=admin_password, status=1)
|
||||
else:
|
||||
print "Admin account with email '%s' already exists." % admin_email
|
||||
print "already exists"
|
||||
|
||||
models.database.close()
|
Loading…
Add table
Reference in a new issue