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)
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}))
class ForgotPasswordRequest(JsonSchemaMixin): email: Email = field( metadata=JsonSchemaMeta(title="Enter your email", extensions={ 'label': 'Email', 'placeholder': '*****@*****.**' }))
class UpdatePermissionRequest(JsonSchemaMixin): roles: List[str] = field(metadata=JsonSchemaMeta( title="Select no roles give access to everyone", extensions={ "label": False, "placeholder": "Select the roles" }))
class HasDepartment: department: str = field(metadata=JsonSchemaMeta( extensions={ "label": "Department", "options": { "opId": "Root/get_departments", "model": "Department" } }))
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
class HasTags: tags: List[str] = field(default_factory=list, metadata=JsonSchemaMeta( extensions={ "label": "Tags", "options": { "opId": "Root/get_tags", "taggable": True } }))
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)
class HasDeadline: deadline: datetime = field(metadata=JsonSchemaMeta( extensions={"label": "Deadline"}))
class Employee(JsonSchemaMixin): name: str department: str id: int = field(metadata=JsonSchemaMeta(read_only=True))
class Employee(JsonSchemaMixin): name: str department: str id: Optional[int] = field(metadata=JsonSchemaMeta(read_only=True), default=None)
class ShouldBeResolved: resolution: str = field(default='', metadata=JsonSchemaMeta( maxLength=5000, extensions={"label": "Resolution"}))
class ShouldBeRegistrable: record: datetime = field(metadata=JsonSchemaMeta( extensions={"label": "Record"}))
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'}))
class HasCode: code: str = field(metadata=JsonSchemaMeta(extensions={"label": "Code"}))
class HasEmail: email: Email = field(metadata=JsonSchemaMeta( extensions={"label": "Email"}))
class HasNIF: nif: str = field(metadata=JsonSchemaMeta(extensions={"label": "NIF"}))
class HasName: name: str = field(metadata=JsonSchemaMeta(extensions={"label": "Name"}))
class HasDescription: description: str = field(metadata=JsonSchemaMeta( maxLength=5000, extensions={"label": "Description"}))