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):
             return save_token(token=auth_token)
         else:
             return error(message=resp)
     else:
         return error(message='Provide a valid auth token')
Exemplo n.º 2
0
 def get_logged_user(new_request):
     auth_token = new_request.headers.get('Authorization')
     if auth_token:
         auth_token = auth_token.split(' ')[1]
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             user = User.query.filter_by(user_id=resp).first()
             print(user)
             res = {
                 'user_id': user.user_id,
                 'email': user.email,
                 'role': user.role,
                 'name': user.name
             }
             return result(data=res)
         return error(message=resp)
     else:
         return error(message='Provide a valid auth token')
 def get_logged_user(new_request):
     auth_token = new_request.headers.get('Authorization')
     if auth_token:
         auth_token = auth_token.split(' ')[1]
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             user = User.query.filter_by(user_id=resp).first()
             return user  # tra lai JSON tương ứng về các roles đang thực hiện và các orders.
             # # print(user)
             # res = {
             #         'user_id': user.user_id,
             #         'email': user.email,
             #         'role': user.role,
             #         'name': user.name
             #         }
             # return result(data=res)
         return None  # error(message=resp)
     else:
         return None  # error(message='Provide a valid auth token')