示例#1
0
    def inner(*args, **kwargs):
        response_not_found_user = {
            'status':
            False,
            'code':
            KeyTranslation.USER_NOT_FOUND.value,
            'message':
            get_text(request.headers, KeyTranslation.USER_NOT_FOUND.value)
        }

        try:
            email = request.json.get('email', '')
            password_sended = request.json.get('password', '')
            user = user_repository.get_one({'email': email})
            password_retrieved = user['password']

            if checkpw(password_sended.encode('utf-8'),
                       password_retrieved.encode('utf-8')):
                return fn(*args, **kwargs)

            return jsonify({
                'status':
                False,
                'code':
                KeyTranslation.WRONG_CREDENTIALS.value,
                'message':
                get_text(request.headers,
                         KeyTranslation.WRONG_CREDENTIALS.value)
            }), 400
        except DoesNotExist:
            return jsonify(response_not_found_user), 404
示例#2
0
    def inner(*args, **kwargs):
        paginate = request.args.get('paginate')
        page = request.args.get('page')
        page_size = request.args.get('page_size')

        if not paginate:
            return fn(*args, **kwargs)

        if paginate and (not page or not page_size):
            return jsonify(
                { 
                    'status': False,
                    'code': KeyTranslation.MISSING_PAGINATE_PARAMS.value,
                    'message': get_text(request.headers, KeyTranslation.MISSING_PAGINATE_PARAMS.value)
                }), 400

        if int(page) < 1 or int(page_size) < 1 or int(page_size) > 100:
            return jsonify(
                { 
                    'status': False,
                    'code': KeyTranslation.INVALID_PAGINATION.value,
                    'message': get_text(request.headers, KeyTranslation.INVALID_PAGINATION.value)
                })

        return fn(*args, **kwargs)
示例#3
0
def index():
    return jsonify({
        'status': True,
        'data': {
            'message':
            get_text(request.headers, KeyTranslation.HEALT_MESSAGE.value),
            'date':
            datetime.utcnow()
        }
    })
示例#4
0
 def inner(*args, **kwargs):
     try:
         id = kwargs['todo_id']
         todo_repository.get_by_id(id)
         return fn(*args, **kwargs)
     except DoesNotExist:
         return jsonify({
             'status':
             False,
             'code':
             KeyTranslation.TODO_NOT_FOUND.value,
             'message':
             get_text(request.headers, KeyTranslation.TODO_NOT_FOUND.value)
         }), 404
示例#5
0
        def inner(*args, **kwargs):
            token = request.headers.get('Authorization')
            payload = decode(token.split(' ').pop(), SECRET_KEY, algorithms=['HS256'])
            role = payload['role']

            if role not in roles:
                return jsonify(
                    { 
                        'status': False,
                        'code': KeyTranslation.INVALID_PERMISSIONS.value,
                        'message': get_text(request.headers, KeyTranslation.INVALID_PERMISSIONS.value)
                    })
            
            return fn(*args, **kwargs)
示例#6
0
    def inner(*args, **kwargs):
        response_invalid_token = { 
            'status': False,
            'code': KeyTranslation.INVALID_TOKEN.value,
            'message': get_text(request.headers, KeyTranslation.INVALID_TOKEN.value)
        }

        try:
            token = request.headers.get('Authorization')

            if token is None:
                return jsonify(response_invalid_token), 401

            decode(token.split(' ').pop(), SECRET_KEY, algorithms=['HS256'])
            return fn(*args, **kwargs)
        except Exception:
            return jsonify(response_invalid_token), 401
示例#7
0
    def inner(*args, **kwargs):
        try:
            todo = Todo(**request.json)
            todo.validate()
            return fn(*args, **kwargs)
        except ValidationError as ex:
            dict = ex.__dict__
            errors = ''

            for key, value in dict['errors'].items():
                errors += f'\n {key} {value} \n'

            return jsonify({
                'status':
                False,
                'code':
                KeyTranslation.TODO_NOT_VALID.value,
                'message':
                get_text(request.headers, KeyTranslation.TODO_NOT_VALID.value)
                + ': ' + errors
            })
        def inner(request: any, *args: dict, **kwargs: dict) -> any:
            token = request.headers.get('Authorization')
            payload = decode(token.split(' ').pop(),
                             SECRET_KEY,
                             algorithms=[Encryptor.HS256.value])
            role = payload['role']

            if role not in roles:
                return json(
                    {
                        'status':
                        False,
                        'code':
                        KeyTranslation.INVALID_PERMISSIONS.value,
                        'message':
                        get_text(request.headers,
                                 KeyTranslation.INVALID_PERMISSIONS.value)
                    },
                    status=StatusCode.FORBIDDEN.value)

            return fn(request, *args, **kwargs)
    def inner(request: any, *args: dict, **kwargs: dict) -> any:
        response = {
            'status':
            False,
            'code':
            KeyTranslation.INVALID_TOKEN.value,
            'message':
            get_text(request.headers, KeyTranslation.INVALID_TOKEN.value)
        }

        try:
            token = request.headers.get('Authorization')

            if token is None:
                return json(response, status=StatusCode.UNAUTHORIZED.value)

            decode(token.split(' ').pop(),
                   SECRET_KEY,
                   algorithms=[Encryptor.HS256.value])
            return fn(request, *args, **kwargs)
        except Exception:
            return json(response, status=StatusCode.UNAUTHORIZED.value)