Esempio n. 1
0
 def get(self):
     auth_header = request.headers.get('Authorization')
     if auth_header:
         auth_token = auth_header.split(" ")[1]
     else:
         auth_token = ''
     if auth_token:
         response = User.decode_auth_token(auth_token)
         if not isinstance(response, str):
             user = User.get_user_by_id(response)
             data = json.dumps(dict(encrypted_key=user.encrypted_key))
             return CommonResponseObject.success_response(data)
         return CommonResponseObject.token_response(response)
     else:
         return CommonResponseObject.unauthorized_token_response()
Esempio n. 2
0
 def post(self):
     # get auth token
     auth_token = RequestUtils.get_access_token(request)
     if auth_token:
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             # mark the token as blacklisted
             blacklist_token = BlacklistToken(token=auth_token)
             try:
                 # insert the token
                 db.session.add(blacklist_token)
                 db.session.commit()
                 DatabaseCheck.remove_key_pair(auth_token)
                 return CommonResponseObject.logout_success()
             except Exception as e:
                 return CommonResponseObject.logout_exception(e)
         else:
             return CommonResponseObject.token_response(resp)
     else:
         return CommonResponseObject.forbiden_token_response()