Exemplo n.º 1
0
    def get(self):
        try:
            current_user_name = get_jwt_identity()
            if not current_user_name:
                return json.dumps({'message': f'Corresponding token was not found'}, 200)

            current_user = self.model.find_by_username(current_user_name)
            return {'user': current_user.get_user_data()}, 200
        except Exception as e:
            return get_unexpected_error_response(e)
Exemplo n.º 2
0
    def get(self):
        try:
            response_object = {
                'status': 'Success',
                'message': 'Successfully got rooms list',
                'rooms_info': get_all_rooms_list(),
            }
            return response_object, 200

        except Exception as e:
            return get_unexpected_error_response(e)
Exemplo n.º 3
0
    def post(self):
        data = parser.parse_args()
        if self.model.find_by_username(data['username']):
            response_object = {
                'status': 'fail',
                'message': 'User already exists. Please Log in.',
            }
            return json.dumps(response_object), 202

        new_user = self.model(username=data['username'], password=data['password'])
        try:
            new_user.save_to_db()
            return get_token_response(new_user)

        except Exception as e:
            return get_unexpected_error_response(e)
Exemplo n.º 4
0
    def post(self):
        try:
            jti = get_raw_jwt()['jti']
            token_to_revoke = self.model(jti=jti)

            if not token_to_revoke.is_revoked():
                token_to_revoke.revoke()
                response_object = {
                    'status': 'Success',
                    'message': 'Token added to revoked list'
                }
                return json.dumps(response_object), 200

            response_object = {
                'status': 'Fail',
                'message': "Can't revoke revoked token"
            }
            return json.dumps(response_object), 400
        except Exception as e:
            return get_unexpected_error_response(e)
Exemplo n.º 5
0
    def post(self):
        try:
            jti = get_raw_jwt().get('jti')
            if not jti:
                raise Exception('Blank JTI')

            token_to_revoke = self.model(jti=jti)

            if not token_to_revoke.is_revoked():
                token_to_revoke.revoke()
                response_object = {
                    'status': 'Success',
                    'message': 'Token added to revoked list'
                }
                return response_object, 200

            response_object = {
                'status': 'Fail',
                'message': "Can't revoke revoked token"
            }
            return response_object, 400
        except Exception as e:
            return get_unexpected_error_response(e)