Spaces:
Paused
Paused
Download schemas/auth.py from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/schemas/auth.py
- Command line
-
hf download hf://spaces/TeamError404/nexus/schemas/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/TeamError404/nexus/resolve/main/schemas/auth.py
2.32 kB
| """ | |
| Pydantic schemas for authentication and token exchange. | |
| """ | |
| from typing import Optional | |
| from uuid import UUID | |
| from pydantic import BaseModel, EmailStr, field_validator | |
| import re | |
| class Token(BaseModel): | |
| access_token: str | |
| refresh_token: str | |
| token_type: str = "bearer" | |
| class TokenRefreshRequest(BaseModel): | |
| refresh_token: str | |
| class CustomOAuth2PasswordRequestForm(BaseModel): | |
| """Used for custom JSON login if not using standard OAuth2 form encoding.""" | |
| email: EmailStr | |
| password: str | |
| class UserRegister(BaseModel): | |
| """Schema for registering a new user & workspace (if first user).""" | |
| email: EmailStr | |
| password: str | |
| full_name: str | |
| # If workspace_id is omitted, they create a new workspace | |
| workspace_name: Optional[str] = None | |
| workspace_id: Optional[UUID] = None | |
| def validate_password_complexity(cls, v: str) -> str: | |
| if len(v) < 8: | |
| raise ValueError("Password must be at least 8 characters long.") | |
| if not re.search(r"[0-9!@#$%^&*(),.?\":{}|<>]", v): | |
| raise ValueError("Password must contain at least one digit or special character.") | |
| return v | |
| class PasswordChangeRequest(BaseModel): | |
| old_password: str | |
| new_password: str | |
| def validate_new_password_complexity(cls, v: str) -> str: | |
| if len(v) < 8: | |
| raise ValueError("Password must be at least 8 characters long.") | |
| if not re.search(r"[0-9!@#$%^&*(),.?\":{}|<>]", v): | |
| raise ValueError("Password must contain at least one digit or special character.") | |
| return v | |
| class ForgotPasswordRequest(BaseModel): | |
| email: EmailStr | |
| class ResetPasswordRequest(BaseModel): | |
| token: str | |
| new_password: str | |
| def validate_reset_password_complexity(cls, v: str) -> str: | |
| if len(v) < 8: | |
| raise ValueError("Password must be at least 8 characters long.") | |
| if not re.search(r"[0-9!@#$%^&*(),.?\":{}|<>]", v): | |
| raise ValueError("Password must contain at least one digit or special character.") | |
| return v | |
| class TokenRefreshResponse(BaseModel): | |
| access_token: str | |
| token_type: str = "bearer" | |