def post(cls):
     '''post (login) method'''
     data = request.get_json()
     result = validate.check_for_data(data)
     if result:
         return result, 400
     username = data.get("username")
     password = data.get("password")
     if not username or not password:
         return dict(message="Username or password fields missing"), 400
     my_user = User()
     result = my_user.login(username, password)
     if "error" in result:
         return dict(message=result["message"]), result["error"]
     access_token = create_access_token(identity=username)
     return dict(result, token=access_token), 200
Exemple #2
0
 def post(cls):
     '''post (login) method'''
     data = request.get_json()
     result = validate.check_for_data(data)
     if result:
         return result, 400
     username = data.get("username")
     password = data.get("password")
     message = ""
     if not password:
         message = "Please enter password"
     if not username:
         message = "Please enter username"
     if message:
         return dict(message=message), 400
     result = validate.check_for_white_spaces([username, password])
     if result:
         return result, 400
     my_user = User()
     result = my_user.login(username, password)
     if "error" in result:
         return dict(message=result["message"]), result["error"]
     access_token = create_access_token(identity=username)
     return dict(result, token=access_token), 200