Spaces:
Paused
Paused
Upload app/modules/auth/schemas.py with huggingface_hub
Browse files- app/modules/auth/schemas.py +114 -0
app/modules/auth/schemas.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
|
| 3 |
+
from pydantic import BaseModel, Field
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# Authentication models
|
| 7 |
+
class LoginRequest(BaseModel):
|
| 8 |
+
email: str = Field(pattern=r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")
|
| 9 |
+
password: str = Field(min_length=8)
|
| 10 |
+
mfa_code: str | None = None
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TokenResponse(BaseModel):
|
| 14 |
+
access_token: str
|
| 15 |
+
refresh_token: str
|
| 16 |
+
token_type: str = "bearer"
|
| 17 |
+
expires_in: int = 1800 # 30 minutes
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class UserCreateRequest(BaseModel):
|
| 21 |
+
username: str = Field(min_length=3, max_length=50)
|
| 22 |
+
email: str = Field(pattern=r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")
|
| 23 |
+
full_name: str = Field(min_length=1, max_length=100)
|
| 24 |
+
role: str = Field(pattern=r"^(analyst|senior_analyst|investigator|manager|admin)$")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class RegisterRequest(BaseModel):
|
| 28 |
+
username: str = Field(min_length=3, max_length=50)
|
| 29 |
+
email: str = Field(pattern=r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")
|
| 30 |
+
password: str = Field(min_length=8, max_length=128)
|
| 31 |
+
full_name: str = Field(min_length=1, max_length=100)
|
| 32 |
+
role: str | None = "ANALYST" # Default role
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class UserProfileResponse(BaseModel):
|
| 36 |
+
id: str
|
| 37 |
+
username: str
|
| 38 |
+
email: str
|
| 39 |
+
full_name: str
|
| 40 |
+
role: str
|
| 41 |
+
is_active: bool
|
| 42 |
+
mfa_enabled: bool
|
| 43 |
+
created_at: datetime
|
| 44 |
+
last_login: datetime | None
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class RegisterResponse(BaseModel):
|
| 48 |
+
user_id: str
|
| 49 |
+
username: str
|
| 50 |
+
email: str
|
| 51 |
+
message: str
|
| 52 |
+
created_at: datetime
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class MFAVerifyRequest(BaseModel):
|
| 56 |
+
code: str
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class MFASetupResponse(BaseModel):
|
| 60 |
+
secret: str
|
| 61 |
+
otpauth_url: str
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class MFAVerifyResponse(BaseModel):
|
| 65 |
+
verified: bool
|
| 66 |
+
message: str
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
# Password Reset Schemas
|
| 70 |
+
class PasswordResetRequest(BaseModel):
|
| 71 |
+
email: str = Field(pattern=r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class PasswordResetConfirm(BaseModel):
|
| 75 |
+
token: str = Field(min_length=10)
|
| 76 |
+
password: str = Field(min_length=8, max_length=128)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
# Session Management Schemas
|
| 80 |
+
class SessionInfo(BaseModel):
|
| 81 |
+
id: str
|
| 82 |
+
device_type: str = Field(enum=["desktop", "mobile", "tablet"])
|
| 83 |
+
device_name: str
|
| 84 |
+
browser: str
|
| 85 |
+
ip_address: str
|
| 86 |
+
location: str
|
| 87 |
+
last_active: str
|
| 88 |
+
is_current_session: bool
|
| 89 |
+
is_trusted: bool
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# Security Monitoring Schemas
|
| 93 |
+
class LoginAttempt(BaseModel):
|
| 94 |
+
id: str
|
| 95 |
+
timestamp: str
|
| 96 |
+
email: str
|
| 97 |
+
ip_address: str
|
| 98 |
+
user_agent: str
|
| 99 |
+
location: str
|
| 100 |
+
success: bool
|
| 101 |
+
failure_reason: str | None
|
| 102 |
+
device_type: str = Field(enum=["desktop", "mobile", "tablet"])
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class SecurityMetrics(BaseModel):
|
| 106 |
+
total_attempts: int
|
| 107 |
+
successful_logins: int
|
| 108 |
+
failed_attempts: int
|
| 109 |
+
unique_ips: int
|
| 110 |
+
suspicious_activities: int
|
| 111 |
+
blocked_ips: int
|
| 112 |
+
average_response_time: int
|
| 113 |
+
peak_hours: list[str]
|
| 114 |
+
recent_attempts: list[LoginAttempt]
|