Shop registration works now
This commit is contained in:
1 parent
a0d238c840
commit
d87c280109
15 files changed
+98
-727
No files matched your search
@@ -1,8 +1,14 @@
|
||||
|
||||
from pydantic import EmailStr
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
from app.database.models.shop_model import ShopAddress
|
||||
|
||||
|
||||
class ShopCreate(SQLModel):
|
||||
name: str = Field(max_length=100, nullable=False, unique=True)
|
||||
description: str = Field(max_length=500, nullable=False)
|
||||
currency: str = Field(max_length=3, nullable=False)
|
||||
contact_email: EmailStr = Field()
|
||||
contact_phone_number: str = Field(min_length=2, max_length=16, schema_extra={"pattern": r'^\+[1-9]\d{1,14}$'})
|
||||
address: ShopAddress
|
||||
@@ -1,14 +1,15 @@
|
||||
import re
|
||||
from pydantic import EmailStr, model_validator
|
||||
from sqlmodel import Field, SQLModel
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field, model_validator
|
||||
|
||||
|
||||
class UserRegister(SQLModel):
|
||||
class UserRegister(BaseModel):
|
||||
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 (#?!@$ %^&*-)")
|
||||
phone_number: str = Field(min_length=2, max_length=16, pattern=r'^\+[1-9]\d{1,14}$')
|
||||
password: str = Field(min_length=8, max_length=128, examples=["Abc123#!"],
|
||||
description="Password must conform to this regex: \n```\n^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{8,128}$\n```")
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_using_regex(self):
|
||||
@@ -20,11 +21,29 @@ class UserRegister(SQLModel):
|
||||
if not re.match(password_regex, self.password):
|
||||
raise ValueError("Password is too weak")
|
||||
|
||||
class UserUpdate(BaseModel):
|
||||
username: Optional[str] = Field(None, min_length=3, max_length=64)
|
||||
first_name: Optional[str] = Field(None, max_length=64)
|
||||
last_name: Optional[str] = Field(None, max_length=64)
|
||||
email: Optional[EmailStr] = Field(None)
|
||||
phone_number: Optional[str] = Field(None, min_length=2, max_length=16, pattern=r'^\+[1-9]\d{1,14}$')
|
||||
password: Optional[str] = Field(None, min_length=8, max_length=128, examples=["Abc123#!"],
|
||||
description="Password must conform to this regex: \n```\n^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{8,128}$\n```")
|
||||
|
||||
class Token(SQLModel):
|
||||
@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(BaseModel):
|
||||
access_token: str
|
||||
token_type: str = "bearer"
|
||||
|
||||
|
||||
class TokenPayload(SQLModel):
|
||||
class TokenPayload(BaseModel):
|
||||
sub: str | None = None
|
||||
Reference in new issue
Block a user