[rewrite] Implemented login and register

This commit is contained in:
Thastertyn committed 2025-03-12 14:01:13 +01:00
1 parent cd8fdb9c21
commit 20ef2aa4e8
29 files changed
+183 -722

No files matched your search

+18 -7
View File
@@ -1,13 +1,24 @@
from sqlmodel import Field as SqlModelField, SQLModel
from pydantic import EmailStr, Field
import re
from pydantic import EmailStr, model_validator
from sqlmodel import Field, SQLModel
class UserRegister(SQLModel):
username: str = Field(..., min_length=3, max_length=64)
email: EmailStr = Field(...)
phone_number: str = Field(..., min_length=2, max_length=16, pattern=r'^\+[1-9]\d{1,14}$')
password: str = Field(..., min_length=6, max_length=128)
shop_id: int = 0
username: str = Field(min_length=3, max_length=64)
email: EmailStr = Field()
phone_number: str = Field(min_length=2, max_length=16, schema_extra={"pattern": r'^\+[1-9]\d{1,14}$'})
password: str = Field(min_length=8, max_length=128,
description="Password must be at least 8 and at most 128 characters long, contain a lower case, upper case letter, a number and a special character (#?!@$ %^&*-)")
@model_validator(mode="after")
def validate_using_regex(self):
self.__validate_password()
return self
def __validate_password(self):
password_regex = r"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{8,128}$"
if not re.match(password_regex, self.password):
raise ValueError("Password is too weak")
class Token(SQLModel):