Пример #1
0
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
    }
Пример #2
0
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
Пример #3
0
def login(username, password):
    account = Account.objects(username=username).first()
    if account is None:
        return {'message': 'this account does not exist'}
    if Account.check_password(account, password):
        new_token = create_token()
        token = Token.objects(user_id=str(account.id)).first()
        if token is None:
            Token(user_id=str(account.id), token=new_token).save()
        else:
            token.update(token=new_token)
        return {
            'id': account.id,
            'success': 1,
            'token': new_token
        }
    else:
        return {
            'message': 'password is wrong.'
        }
Пример #4
0
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}