Пример #1
0
def update_account(account_id,
                   nickname,
                   des,
                   old_password,
                   new_password,
                   confirm,
                   token=None):
    if token is None or not (is_admin(token) or is_self(account_id, token)):
        return abort(403)
    account = Account.objects(id=account_id).first()
    if account is None or account.username == 'root':
        return abort(403)
    if des is None:
        des = ""
    password = account.password
    if new_password or confirm:
        if new_password == confirm:
            if Account.check_password(account, old_password):
                password = Account.create_password(new_password)
            else:
                return {'success': 0, 'message': 'wrong password'}
        else:
            return {'success': 0, 'message': 'pwd != confirm'}
    account.update(
        nickname=nickname,
        description=des,
        password=password,
    )
    account.save()
    return {
        'success': 1,
        'id': account_id,
        'message': 'user\'s profile update successfully!'
    }
Пример #2
0
def update_account(account_id, nickname, des, old_password, new_password, confirm, token=None):
    if token is None or not (is_admin(token) or is_self(account_id, token)):
        return abort(403)
    account = Account.objects(id=account_id).first()
    if account is None or account.username == 'root':
        return abort(403)
    if des is None:
        des = ""
    password = account.password
    if new_password or confirm:
        if new_password == confirm:
            if Account.check_password(account, old_password):
                password = Account.create_password(new_password)
            else:
                return {
                    'success': 0,
                    'message': 'wrong password'
                }
        else:
            return {
                'success': 0,
                'message': 'pwd != confirm'
            }
    account.update(
        nickname=nickname,
        description=des,
        password=password,
    )
    account.save()
    return {
        'success': 1,
        'id': account_id,
        'message': 'user\'s profile update successfully!'
    }
Пример #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 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.'
        }