예제 #1
0
def is_self(account_id, token):
    token = Token.objects(token=token).first()
    if token is None:
        return False
    if account_id != token.user_id:
        return False
    return True
예제 #2
0
def is_stuff(token):
    token = Token.objects(token=token).first()
    if token is None:
        return False
    account = Account.objects(id=token.user_id).first()
    if account is None:
        return False
    return True
예제 #3
0
def is_admin(token):
    token = Token.objects(token=token).first()
    if token is None:
        return False
    account = Account.objects(id=token.user_id).first()
    if account is None:
        return False
    if account.role == 'stuff':
        return False
    return True
예제 #4
0
def is_root(token):
    token = Token.objects(token=token).first()
    if token is None:
        return False
    account = Account.objects(id=token.user_id).first()
    if account is None:
        return False
    if account.username == 'root':
        return True
    return False
예제 #5
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.'
        }
예제 #6
0
def logout(token):
    token = Token.objects(token=token).first()
    token.delete()
    return {'success': 1}
예제 #7
0
def logout(token):
    token = Token.objects(token=token).first()
    token.delete()
    return {'success': 1}