コード例 #1
0
ファイル: config.py プロジェクト: Hong5489/Custom-CTFd-Engine
	def patch(self, config_key):
		config = Configs.query.filter_by(key=config_key).first()
		data = request.get_json()
		if config:
			schema = ConfigSchema(instance=config, partial=True)
			response = schema.load(data)
		else:
			schema = ConfigSchema()
			data['key'] = config_key
			response = schema.load(data)
			db.session.add(response.data)

		if response.errors:
			return response.errors, 400

		db.session.commit()

		response = schema.dump(response.data)
		db.session.close()

		clear_config()
		clear_standings()

		return {
			'success': True,
			'data': response.data
		}
コード例 #2
0
    def patch(self):
        req = request.get_json()
        schema = ConfigSchema()

        for key, value in req.items():
            response = schema.load({"key": key, "value": value})
            if response.errors:
                return {"success": False, "errors": response.errors}, 400
            set_config(key=key, value=value)

        clear_config()
        clear_standings()

        return {"success": True}
コード例 #3
0
    def post(self):
        req = request.get_json()
        schema = ConfigSchema()
        response = schema.load(req)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_config()
        clear_standings()

        return {"success": True, "data": response.data}
コード例 #4
0
ファイル: config.py プロジェクト: infosecirvin/CTFd
    def patch(self):
        req = request.get_json()
        schema = ConfigSchema()

        for key, value in req.items():
            response = schema.load({"key": key, "value": value})
            if response.errors:
                # Inject config key into error
                config_key = response.data["key"]
                response.errors["value"][
                    0] = f"{config_key} config is too long"
                return {"success": False, "errors": response.errors}, 400
            set_config(key=key, value=value)

        clear_config()
        clear_standings()

        return {"success": True}
コード例 #5
0
ファイル: config.py プロジェクト: infosecirvin/CTFd
    def post(self):
        req = request.get_json()
        schema = ConfigSchema()
        response = schema.load(req)

        if response.errors:
            # Inject config key into error
            config_key = response.data["key"]
            response.errors["value"][0] = f"{config_key} config is too long"
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_config()
        clear_standings()

        return {"success": True, "data": response.data}