first commit
This commit is contained in:
37
server/backend/pydentic.py
Normal file
37
server/backend/pydentic.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from pydantic import BaseModel, Field, EmailStr, constr,validator
|
||||
from typing import List, Optional
|
||||
from enum import IntEnum
|
||||
#Валидация пароля
|
||||
import re
|
||||
def check_password_complexity(cls, password):
|
||||
if password is None:
|
||||
return password
|
||||
if not re.search(r'[A-Za-z]', password):
|
||||
raise ValueError('Password must contain at least one letter')
|
||||
if not re.search(r'\d', password):
|
||||
raise ValueError('Password must contain at least one digit')
|
||||
if not re.search(r'[!@#$%^&*(),.?":{}|<>]', password):
|
||||
raise ValueError('Password must contain at least one special symbol')
|
||||
return password
|
||||
|
||||
#Валидация полей с пользователями
|
||||
class UsersInfo(BaseModel):
|
||||
email:EmailStr = Field(..., min_length=6, max_length=254, description="email of the user")
|
||||
description: str = Field(..., description="description of the user")
|
||||
activated:bool = Field(..., description="Has the user activated their account")
|
||||
password:constr(min_length=8) = Field(..., description="Password with min 8 chars, letters and digits")
|
||||
@validator('password')
|
||||
def password_validator(cls, password):
|
||||
return check_password_complexity(cls, password)
|
||||
class IdofPersons(UsersInfo):
|
||||
id:int = Field(..., description="Unique identifier of the user")
|
||||
class CreateUser(UsersInfo):
|
||||
pass
|
||||
class UserUpdate(BaseModel):
|
||||
email:Optional[EmailStr] = Field(None, min_length=6, max_length=254, description="users' email")
|
||||
description:Optional[str] = Field(None, description="description of the user")
|
||||
activated:Optional[bool] = Field(None, description="Has the user activated their account")
|
||||
password:Optional[constr(min_length=8)] = Field(None, description="Password with min 8 chars, letters and digits")
|
||||
@validator('password')
|
||||
def password_validator(cls, password):
|
||||
return check_password_complexity(cls, password)
|
||||
Reference in New Issue
Block a user