示例#1
0
class ChangePasswordRequest(JsonSchemaMixin):
    old: Password = field(metadata=JsonSchemaMeta(
        extensions={"label": "Old password"}))
    new: Password = field(metadata=JsonSchemaMeta(
        extensions={"label": "New password"}))

    def __post_init__(self):
        if self.old == self.new:
            raise TypeError(
                "The new password and the old one must be different")
        self.new = generate_password_hash(self.new)
示例#2
0
 class Test(JsonSchemaMixin):
     """Dataclass with field metadata"""
     name: str = field(
         metadata=JsonSchemaMeta(title="Title of the field",
                                 description="Description of the field",
                                 examples=["foo", "bar"],
                                 extensions={'field-group': 1}))
示例#3
0
class ForgotPasswordRequest(JsonSchemaMixin):
    email: Email = field(
        metadata=JsonSchemaMeta(title="Enter your email",
                                extensions={
                                    'label': 'Email',
                                    'placeholder': '*****@*****.**'
                                }))
示例#4
0
class UpdatePermissionRequest(JsonSchemaMixin):
    roles: List[str] = field(metadata=JsonSchemaMeta(
        title="Select no roles give access to everyone",
        extensions={
            "label": False,
            "placeholder": "Select the roles"
        }))
示例#5
0
class HasDepartment:
    department: str = field(metadata=JsonSchemaMeta(
        extensions={
            "label": "Department",
            "options": {
                "opId": "Root/get_departments",
                "model": "Department"
            }
        }))
示例#6
0
class HasAddress:
    address: str = field(metadata=JsonSchemaMeta(extensions={
        "label": "Address",
        "format": "GeoAddress"
    }))

    async def get_near(self, request: Request) -> OkResult:
        """Returns projects and records near by the address"""
        pass
示例#7
0
class HasTags:
    tags: List[str] = field(default_factory=list,
                            metadata=JsonSchemaMeta(
                                extensions={
                                    "label": "Tags",
                                    "options": {
                                        "opId": "Root/get_tags",
                                        "taggable": True
                                    }
                                }))
示例#8
0
class Auth(JsonSchemaMixin):
    """The authentication model"""
    email: Email = field(
        metadata=JsonSchemaMeta(title="Enter your email",
                                extensions={
                                    'label': 'Email',
                                    'placeholder': '*****@*****.**'
                                }))
    password: Password = field(metadata=JsonSchemaMeta(
        title=
        "Enter your password. Click on the eye to reveal it (take care of not revealing it to others)",
        extensions={'label': 'Password'}))

    @classmethod
    def secure(cls, password):
        return password if password.startswith(
            'pbkdf2:sha256:') else generate_password_hash(password)

    async def authorize(self, table, secret, user_class):
        user = await user_class.get(table, email=self.email)
        if user and check_password_hash(user.password, self.password):
            return AuthToken.generate({"user_id": str(user._id)}, secret)
示例#9
0
class HasDeadline:
    deadline: datetime = field(metadata=JsonSchemaMeta(
        extensions={"label": "Deadline"}))
示例#10
0
 class Employee(JsonSchemaMixin):
     name: str
     department: str
     id: int = field(metadata=JsonSchemaMeta(read_only=True))
示例#11
0
 class Employee(JsonSchemaMixin):
     name: str
     department: str
     id: Optional[int] = field(metadata=JsonSchemaMeta(read_only=True),
                               default=None)
示例#12
0
class ShouldBeResolved:
    resolution: str = field(default='',
                            metadata=JsonSchemaMeta(
                                maxLength=5000,
                                extensions={"label": "Resolution"}))
示例#13
0
class ShouldBeRegistrable:
    record: datetime = field(metadata=JsonSchemaMeta(
        extensions={"label": "Record"}))
示例#14
0
class ResetPassword(JsonSchemaMixin):
    code: UUID
    password: Password = field(metadata=JsonSchemaMeta(
        title=
        "Enter the new password. Click on the eye to reveal it (take care of not revealing it to others)",
        extensions={'label': 'Password'}))
示例#15
0
class HasCode:
    code: str = field(metadata=JsonSchemaMeta(extensions={"label": "Code"}))
示例#16
0
class HasEmail:
    email: Email = field(metadata=JsonSchemaMeta(
        extensions={"label": "Email"}))
示例#17
0
class HasNIF:
    nif: str = field(metadata=JsonSchemaMeta(extensions={"label": "NIF"}))
示例#18
0
class HasName:
    name: str = field(metadata=JsonSchemaMeta(extensions={"label": "Name"}))
示例#19
0
class HasDescription:
    description: str = field(metadata=JsonSchemaMeta(
        maxLength=5000, extensions={"label": "Description"}))