def create_root(username='******', password='******', role='admin', nickname='Super'): account = Account( username=username, nickname=nickname, password=create_password(password), role=role, ).save() token = Token( user_id=str(account.id), token=create_token(), ).save() return token.token
def create_account(username, password, confirm, role, nickname, token=None): if token is None or not is_admin(token): return abort(403) if password != confirm: return {"message": "password not conformity"} if Account.objects(username=username).first() is not None: return {"message": "username has been register"} if str(role) == '1': role = 'admin' else: role = 'stuff' account = Account( username=username, nickname=nickname, password=Account.create_password(password), role=role, ).save() token = Token( user_id=str(account.id), token=create_token(), ).save() return {'id': account.id, 'success': 1, 'token': token.token}