def add_control(self, ctrl: P2k16Control): self.controls.append(ctrl) return self def to_dict(self) -> Dict[str, Any]: d = {} if len(self.controls): d["_controls"] = [c.to_dict() for c in self.controls] return d core = Blueprint("core", __name__, template_folder="templates") registry = DataServiceTool("CoreDataService", "core-data-service.js", core) @registry.route("/service/authz/log-in", methods=["POST"]) @validate_schema(login_form) def service_authz_login(): username = request.json["username"] account = Account.find_account_by_username(username) password = request.json["password"] if not account: logger.info("Login: Bad login attempt, no such user: {}".format(username)) raise P2k16UserException("Invalid credentials") if not account.valid_password(password): logger.info("Login: Bad login attempt, wrong password: {}".format(username)) raise P2k16UserException("Invalid credentials")
import logging import flask import flask_login import p2k16.core.door from flask import Blueprint, jsonify, request from p2k16.core import P2k16UserException, event_management from p2k16.core.door import DoorClient from p2k16.core.models import db from p2k16.web.utils import validate_schema, DataServiceTool logger = logging.getLogger(__name__) door = Blueprint('door', __name__, template_folder='templates') registry = DataServiceTool("DoorDataService", "door-data-service.js", door) door_form = { "type": "object", "properties": { "doors": { "type": "array", "minLength": 1, "items": { "type": "string" } }, }, "required": ["doors"] }
import logging import flask import flask_login import p2k16.core.door from flask import Blueprint, jsonify, request from p2k16.core import P2k16UserException, event_management from p2k16.core.door import DoorClient from p2k16.core.models import db, ToolDescription, ToolCheckout, Circle from p2k16.web.utils import validate_schema, DataServiceTool, require_circle_membership from p2k16.web.core_blueprint import model_to_json logger = logging.getLogger(__name__) tool = Blueprint('tool', __name__, template_folder='templates') registry = DataServiceTool("ToolDataService", "tool-data-service.js", tool) tool_form = { "type": "object", "properties": { "tool": { "type": "integer" }, }, "required": ["tool"] } @registry.route('/service/tool/recent-events', methods=['GET']) def recent_events(): from datetime import datetime, timedelta
import logging import flask import flask_login from flask import Blueprint, jsonify, request from p2k16.core import P2k16UserException from p2k16.core.models import db, Account from p2k16.web.utils import validate_schema, DataServiceTool logger = logging.getLogger(__name__) label = Blueprint('label', __name__, template_folder='templates') registry = DataServiceTool("LabelService", "label-service.js", label) box_label_form = { "type": "object", "properties": { "user": { "type": "integer" } }, "required": ["user"] } @registry.route('/service/label/print_box_label', methods=['POST']) @validate_schema(box_label_form) @flask_login.login_required def print_box_label(): a = flask_login.current_user.account
id_type = {"type": "number", "min": 1} nonempty_string = {"type": "string", "minLength": 1} create_badge_form = { "type": "object", "properties": { "title": nonempty_string, "recipient": nonempty_string }, "required": ["title"], "additionalProperties": False, } badge = Blueprint('badge', __name__, template_folder='templates') registry = DataServiceTool("BadgeDataService", "badge-data-service.js", badge) def badge_to_json(b: AccountBadge): return { **model_to_json(b), **{ "account_id": b.account_id, "account_username": b.account.username, "awarded_by_id": b.awarded_by_id, "awarded_by_username": b.awarded_by.username if b.awarded_by else None, "description_id": b.description_id } }