Example #1
0
    def post(self):
        data = parser.parse_args()
        userController = UserController()

        try:
            if (userController.findByUsername(data["username"])) == None:
                return {"message": f"User {data.username} doesn't exist"}

            if userController.login(data["username"],
                                    data["password"]) == True:
                access_token = create_access_token(identity=data["username"])
                refresh_token = create_refresh_token(identity=data["username"])

                return {
                    "message": f"Logged in as {data['username']}",
                    "access_token": access_token,
                    "refresh_token": refresh_token
                }
            else:
                return {"message": "Username or password is incorrect."}

        except:
            return {"message": "Something went wrong, please try again"}
Example #2
0
def login():
    from controllers.UserController import UserController
    return UserController.login()