class Login(Resource):
    def __init__(self):
        self.user_controller = UserController()
        self.response_creator = ResponseCreator()

    @staticmethod
    def get_tokens_dict(username):
        tokens_dict = {
            'accessToken':
            flask_jwt_extended.create_access_token(identity=username),
            'refreshToken':
            flask_jwt_extended.create_refresh_token(identity=username)
        }

        return tokens_dict

    @errorhandler.invalid_recaptcha
    @errorhandler.internal_server_error
    @errorhandler.bad_login_or_register_request
    @errorhandler.unauthorized
    def post(self):
        request_body_dict = request.json

        username, password = request_body_dict['username'], request_body_dict[
            'password']

        if self.user_controller.is_username_password_valid(username, password):

            tokens_json = json.dumps(self.get_tokens_dict(username))

            self.response_creator.create_response(tokens_json)
            return self.response_creator.response_obj
        return self.response_creator.unauthorized()
    def func_wrapper(*args, **kwargs):
        from app.shared.response import ResponseCreator
        from app.authentication.model import User
        response_creator = ResponseCreator()

        request_body_dict = request.json

        user_object = User.query.filter_by(
            username=request_body_dict['username']).first()

        if user_object is None:
            return response_creator.unauthorized()

        return func(*args, **kwargs)