File size: 2,572 Bytes
ec145e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
# models.py
from pydantic import BaseModel, EmailStr, Field, validator
from typing import List, Optional

# === Trainer Models ===
class InitializeBotResponse(BaseModel):
    bot_id: str

class DocumentPath(BaseModel):
    bot_id: str
    data_path: str

class NewChatResponse(BaseModel):
    chat_id: str

class QueryRequest(BaseModel):
    bot_id: str
    chat_id: str
    query: str

class QueryResponse(BaseModel):
    response: str
    web_sources: List[str]

# === Authentication Models ===
class User(BaseModel):
    name: str = Field(..., min_length=3, max_length=50)
    email: EmailStr
    password: str

    @validator("password")
    def validate_password(cls, value):
        if len(value) < 8:
            raise ValueError("Password must be at least 8 characters long.")
        if not any(char.isdigit() for char in value):
            raise ValueError("Password must include at least one number.")
        if not any(char.isupper() for char in value):
            raise ValueError("Password must include at least one uppercase letter.")
        if not any(char.islower() for char in value):
            raise ValueError("Password must include at least one lowercase letter.")
        if not any(char in "!@#$%^&*()-_+=<>?/" for char in value):
            raise ValueError("Password must include at least one special character.")
        return value

class UserUpdate(BaseModel):
    name: Optional[str] = Field(None, min_length=3, max_length=50)
    email: Optional[EmailStr]
    password: Optional[str]

    @validator("password")
    def validate_password(cls, value):
        if value is not None:
            if len(value) < 8:
                raise ValueError("Password must be at least 8 characters long.")
            if not any(char.isdigit() for char in value):
                raise ValueError("Password must include at least one number.")
            if not any(char.isupper() for char in value):
                raise ValueError("Password must include at least one uppercase letter.")
            if not any(char.islower() for char in value):
                raise ValueError("Password must include at least one lowercase letter.")
            if not any(char in "!@#$%^&*()-_+=<>?/" for char in value):
                raise ValueError("Password must include at least one special character.")
        return value

class Token(BaseModel):
    access_token: str
    refresh_token: str
    token_type: str

class LoginResponse(Token):
    name: str
    avatar: Optional[str] = None

class TokenData(BaseModel):
    email: Optional[str] = None