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() try: User.query.count() return func(*args, **kwargs) except Exception as e: print(e) return response_creator.internal_server_error()
def func_wrapper(*args, **kwargs): from application import recaptcha from app.shared.response import ResponseCreator response_creator = ResponseCreator() if not recaptcha.verify( response=request.json.get('reCaptchaResponse')): return response_creator.invalid_recaptcha() return func(*args, **kwargs)
def func_wrapper(*args, **kwargs): from app.shared.response import ResponseCreator from app.authentication.model import User response_creator = ResponseCreator() api_key = flask.request.args['api-key'] user_object = User.query.filter_by(api_key=api_key).first() if user_object is None: return response_creator.api_key_does_not_exist() return func(*args, **kwargs)
def func_wrapper(*args, **kwargs): from app.shared.response import ResponseCreator from app.authentication.model import User response_creator = ResponseCreator() username = flask_jwt_extended.get_jwt_identity() user_object = User.query.filter_by(username=username).first() if user_object is None: return response_creator.user_does_not_exist() return func(*args, **kwargs)
def func_wrapper(*args, **kwargs): from app.shared.response import ResponseCreator response_creator = ResponseCreator() request_body_dict = request.json if request_body_dict.keys() != { 'username', 'password', 'reCaptchaResponse' }: return response_creator.bad_login_or_register_request() return func(*args, **kwargs)
def func_wrapper(*args, **kwargs): from app.shared.response import ResponseCreator from app.authentication.controller import UserController response_creator = ResponseCreator() api_key = request.headers.get('x-api-key') user_controller = UserController() if not user_controller.is_api_key_valid(api_key): return response_creator.invalid_api_key() return func(*args, **kwargs)
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 try: User.query.filter_by( username=request_body_dict['username']).first() return func(*args, **kwargs) except: return response_creator.user_already_exists()
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)
class Register(Resource): def __init__(self): self.user_controller = UserController() self.response_creator = ResponseCreator() @errorhandler.internal_server_error @errorhandler.bad_login_or_register_request @errorhandler.user_already_exists def post(self): request_body_dict = request.json self.user_controller.create_user(request_body_dict) return self.response_creator.created()
class ApiKey(Resource): decorators = [flask_jwt_extended.jwt_required] def __init__(self): self.user_controller = UserController() self.response_creator = ResponseCreator() @errorhandler.internal_server_error def get(self): current_user = flask_jwt_extended.get_jwt_identity() api_key = self.user_controller.get_api_key_by_username(current_user) return self.response_creator.create_response( json.dumps({"apiKey": api_key}))
class Account(Resource): decorators = [flask_jwt_extended.jwt_required] def __init__(self): self.user_controller = UserController() self.response_creator = ResponseCreator() @errorhandler.internal_server_error @errorhandler.user_does_not_exist def delete(self): username = flask_jwt_extended.get_jwt_identity() self.user_controller.delete_user(username) return self.response_creator.ok()
class RefreshToken(Resource): decorators = [flask_jwt_extended.jwt_refresh_token_required] def __init__(self): self.response_creator = ResponseCreator() def get(self): current_user = flask_jwt_extended.get_jwt_identity() ret = { 'accessToken': flask_jwt_extended.create_access_token(identity=current_user) } return self.response_creator.create_response(json.dumps(ret))
class Videos(Resource): def __init__(self): self.video_controller = VideoController() self.response_creator = ResponseCreator() self.user_controller = UserController() @errorhandler.internal_server_error @errorhandler.invalid_api_key def post(self): api_key = request.headers.get('x-api-key') user = self.user_controller.get_user_by_api_key(api_key) self.video_controller.create_video(request.json, user) return self.response_creator.ok() @flask_jwt_extended.jwt_required @errorhandler.internal_server_error def get(self): username = flask_jwt_extended.get_jwt_identity() videos_dict = self.video_controller.get_videos_by_username(username) videos_json = json.dumps(videos_dict) return self.response_creator.create_response(videos_json)
class LogoutAccess(Resource): decorators = [flask_jwt_extended.jwt_required] def __init__(self): self.response_creator = ResponseCreator() def delete(self): from application import blacklist jti = flask_jwt_extended.get_raw_jwt()['jti'] blacklist.add(jti) message_dict = {"msg": "Successfully logged out access"} message_json = json.dumps(message_dict) return self.response_creator.create_response(message_json)
def __init__(self): self.video_controller = VideoController() self.response_creator = ResponseCreator() self.user_controller = UserController()
def __init__(self): self.response_creator = ResponseCreator()
def setup_class(cls): cls.response_creator = ResponseCreator()