48 lines
1.0 KiB
Python
48 lines
1.0 KiB
Python
from typing import Optional
|
|
from pydantic import BaseModel, validator
|
|
from services.password import validate_password
|
|
|
|
from database.decorators import as_form
|
|
|
|
|
|
@as_form
|
|
class UserForm(BaseModel):
|
|
username: str
|
|
firstname: Optional[str]
|
|
name: Optional[str]
|
|
email: Optional[str]
|
|
|
|
@as_form
|
|
class User(BaseModel):
|
|
username: str
|
|
password: str
|
|
|
|
|
|
@as_form
|
|
class UserRegister(User):
|
|
password_confirm: str
|
|
|
|
@validator('username')
|
|
def username_alphanumeric(cls, v):
|
|
assert v.isalnum(), 'must be alphanumeric'
|
|
return v
|
|
|
|
@validator('password')
|
|
def password_validation(cls, v):
|
|
is_valid = validate_password(v)
|
|
if is_valid != True:
|
|
raise ValueError(is_valid)
|
|
return v
|
|
|
|
@validator('password_confirm')
|
|
def password_match(cls, v, values):
|
|
if 'password' in values and v != values['password']:
|
|
raise ValueError('Les mots de passe ne correspondent pas')
|
|
return v
|
|
|
|
|
|
@as_form
|
|
class PasswordSet(BaseModel):
|
|
password: str
|
|
password_confirm: str
|