create, delete, patch user
This commit is contained in:
@@ -2,14 +2,28 @@ from datetime import datetime
|
||||
from typing import Annotated
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field
|
||||
from pydantic import AfterValidator, BaseModel, EmailStr, Field
|
||||
|
||||
|
||||
def validate_password(password: str) -> str:
|
||||
PUNCTUATION: set[str] = {"$", "@", "#", "%", "!", "^", "&", "*", "(", ")", "-", "_", "+", "=", "{", "}", "[", "]"}
|
||||
if len(password) < 8 or len(password) > 72:
|
||||
raise ValueError("Password must be 8-72 characters")
|
||||
if (
|
||||
not any(c.isupper() for c in password)
|
||||
or not any(c.islower() for c in password)
|
||||
or not any(c.isdigit() for c in password)
|
||||
or not any(c in PUNCTUATION for c in password)
|
||||
):
|
||||
raise ValueError("Password must contain uppercase, lowercase, digit and special char")
|
||||
return password
|
||||
|
||||
PasswordStr = Annotated[str, AfterValidator(validate_password)]
|
||||
|
||||
class Base(BaseModel):
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
|
||||
class PermissionsCreate(Base):
|
||||
permission:Annotated[str, Field(..., max_length=30, description="permission name")]
|
||||
|
||||
@@ -35,8 +49,7 @@ class UserCreate(Base):
|
||||
last_name:Annotated[str, Field(...,max_length=64, description="last name of the user")]
|
||||
middle_name:Annotated[str, Field(...,max_length=64, description="middle name of the user")]
|
||||
email:Annotated[EmailStr, Field(...,min_length=5, max_length=255, description="email of the user")]
|
||||
plain_password:Annotated[str, Field(...,min_length=8,max_length=72, description="plain password of the user")]
|
||||
status:Annotated[bool, Field(..., description="status of the user")]
|
||||
plain_password:Annotated[PasswordStr, Field(..., description="plain password of the user")]
|
||||
|
||||
direct_permissions:Annotated[list[str], Field(..., description="permissions of the user")]
|
||||
group:Annotated[list[str], Field(..., description="permissions groups of the user")]
|
||||
@@ -63,6 +76,7 @@ class UserUpdate(Base):
|
||||
last_name:Annotated[str|None, Field(None, max_length=64,description="last name of the user")]
|
||||
middle_name:Annotated[str|None, Field(None, max_length=64,description="middle name of the user")]
|
||||
email:Annotated[EmailStr|None, Field(None, min_length=5, max_length=255, description="email of the user")]
|
||||
plain_password:Annotated[PasswordStr|None, Field(None, description="plain password of the user")]
|
||||
status:Annotated[bool|None, Field(None, description="status of the user")]
|
||||
direct_permissions:Annotated[list[str]|None, Field(None, description="permissions of the user")]
|
||||
group:Annotated[list[str]|None, Field(None, description="permissions groups of the user")]
|
||||
|
||||
Reference in New Issue
Block a user