Coverage for src/schemas/auth_schema.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Validations with Marshmallow
2from marshmallow import fields
3from marshmallow.validate import Regexp, Length, Email
5from src.utils import DTOSchema
8class LoginSchema(DTOSchema):
9 """ /auth/login [POST]
11 Parameters:
12 - Email
13 - Password (Str)
14 """
16 email = fields.Email(required=True, validate=[Length(min=5, max=64)])
17 password = fields.Str(required=True, validate=[Length(min=8, max=128)])
20class RegisterSchema(DTOSchema):
21 """ /auth/register [POST]
23 Parameters:
24 - Email
25 - Username (Str)
26 - Password (Str)
27 """
29 email = fields.Email(required=True, validate=[Length(min=5, max=64)])
30 username = fields.Str(
31 required=True,
32 validate=[
33 Length(min=4, max=15),
34 Regexp(
35 r"^([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)$",
36 error="Invalid username!",
37 ),
38 ],
39 )
40 password = fields.Str(
41 required=True,
42 validate=[
43 Length(min=8, max=128),
44 Regexp(
45 r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&.+\-#_])[A-Za-z\d@$!%*?&.+\-#_]{8,}",
46 error="Password must contain at least minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character !"
47 ),
48 ],
49 )
52class ResetSchema(DTOSchema):
53 """ /auth/login [POST]
55 Parameters:
56 - Email
57 """
58 password = fields.Str(
59 required=True,
60 validate=[
61 Length(min=8, max=128),
62 Regexp(
63 r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}",
64 error="Password must contain at least minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character !"
65 ),
66 ],
67 )
68 reset_password_token = fields.Str(required=True, validate=[Length(min=50)])
71class ForgetSchema(DTOSchema):
72 """ /auth/login [POST]
74 Parameters:
75 - Email
76 """
77 email = fields.Email(required=True, validate=[Length(min=5, max=64)])