Example #1
0
def logout_user(auth_token):
    is_blacklist = Blacklist.check_blacklist(auth_token)
    if is_blacklist:
        return make_response(401, 'fail', "Token Blacklisted, Please log in again")
    ret, token = User.decode_auth_token(auth_token, current_app.config['SECRET_KEY'])
    if not ret:
        return make_response(401, 'fail', token)

    return save_token(token=auth_token)
Example #2
0
def update_password(data):
    token = data['token']
    resp = User.decode_auth_token(token)
    if not isinstance(resp, str):
        user = User().load({'_id': resp['token']})
        user.password = data['password']
        user.modified_on = datetime.datetime.utcnow()
        save_changes(user)
        save_token(token)
        return {
            'status': 'success',
            'message': 'Password Changed.',
        }, 200
    else:
        response_object = {
            'status': 'fail',
            'message': 'No user with provided id found.',
        }
        return response_object, 409
 def logout_user(data: str) -> Tuple[Dict[str, str], int]:
     if data:
         auth_token = data.split(" ")[1]
     else:
         auth_token = ""
     if auth_token:
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             # mark the token as revoked
             return save_token(token=auth_token)
         else:
             response_object = {"status": "fail", "message": resp}
             return response_object, 401
     else:
         response_object = {
             "status": "fail",
             "message": "Provide a valid auth token.",
         }
         return response_object, 403
 def logout_user(data):
     if data:
         auth_token = data.split(" ")[1]
     else:
         auth_token = ''
     if auth_token:
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             # mark the token as blacklisted
             return save_token(token=auth_token)
         else:
             response_object = {'status': 'fail', 'message': resp}
             return response_object, 401
     else:
         response_object = {
             'status': 'fail',
             'message': 'Provide a valid auth token.'
         }
         return response_object, 403
Example #5
0
 def logout_user(data):
     try:
         if data:
             auth_token = data.split(" ")[1]
         else:
             auth_token = None
         if auth_token:
             resp = User.decode_auth_token(auth_token)
             if not isinstance(resp, str):
                 return save_token(auth_token)
             else:
                 return {'status': 'fail', 'message': resp}, 401
         else:
             return {'status': 'fail', 'message': 'invalid token'}, 403
     except Exception as e:
         print(e)
         return {
             'status': 'fail',
             'message': 'try again',
         }, 500
 def test_save_token(self, db_commit):
     db_commit.side_effect = Exception('error')
     self.assertRaises(Exception, save_token('test token'))