File size: 1,502 Bytes
2f43b92
0359012
d1d97b7
2f43b92
d1d97b7
0359012
4e4ad14
 
 
2f43b92
4e4ad14
2f43b92
4e4ad14
15ea62b
 
 
4e4ad14
 
 
 
d1d97b7
0359012
d1d97b7
0359012
 
 
15ea62b
 
35e685d
 
 
 
 
f1cd69e
 
 
 
 
 
 
 
 
15ea62b
4e4ad14
 
0359012
 
 
 
 
 
 
 
 
 
 
 
 
4e4ad14
 
 
 
0359012
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import uuid
import re
from datetime import datetime


from pydantic import ConfigDict, BaseModel, Field, field_validator
from typing import Optional

from sqlalchemy import Column, Integer, String, Boolean

from app.core.database import Base
from sqlalchemy.orm import Mapped, mapped_column, relationship


class UserBase(BaseModel):
    email: str
    username: str


class UserResponse(UserBase):
    id: uuid.UUID = Field(..., alias="id")
    is_active: Optional[bool] = None
    created_at: datetime = Field(..., alias="created_at")
    model_config = ConfigDict(
        from_attributes=True,
    )


class PasswordUpdate(BaseModel):
    current_password: str
    new_password: str


class User_GET_TOKEN(BaseModel):
    email: str
    password: str


class Response_Token(BaseModel):
    token: str


class User(UserBase):
    password: str

    @field_validator("email")
    def email_must_be_valid(cls, v):
        if not re.match(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$", v):
            raise ValueError("Invalid email address")
        return v

    @field_validator("password")
    def password_must_be_long(cls, v):
        if len(v) < 6:
            raise ValueError("Password must be at least 6 characters long")
        return v

    model_config = ConfigDict(from_attributes=True)


class UpdateUser(UserBase):
    current_password: str


class UserDeletedResponse(BaseModel):
    detail: str = Field(..., alias="detail")
    model_config = ConfigDict(from_attributes=True)