Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserBase(BaseModel):
- first_name: str = Field(alias="firstName")
- last_name: str = Field(alias="lastName")
- email_address: str = Field(alias="emailAddress")
- phone_number: str = Field(alias="phoneNumber")
- password: str = Field(alias="password")
- date_of_birth: str = Field(alias="dateOfBirth")
- grade: int = Field(alias="grade")
- class UserModel(UserBase):
- id: int
- class Config:
- from_attributes = True
- class LoginBase(BaseModel):
- email_address: str = Field(alias="emailAddress")
- password: str = Field(alias="password")
- class LoginModel(LoginBase):
- id: int
- class Config:
- from_attributes = True
- @app.post("/create_account/")
- async def create_new_user(user: UserBase, db: db_dependency):
- if not validate_email(user.email_address):
- raise HTTPException(status_code=400, detail="Not A Valid Email")
- if not validate_password(user.password):
- raise HTTPException(status_code=400, detail="Not A Valid Password")
- if not is_name_not_in_password(user.first_name, user.last_name, user.password):
- raise HTTPException(status_code=400, detail="Name Cannot Be In Password")
- if not validate_universal_phone_number(user.phone_number):
- raise HTTPException(status_code=400, detail="Invalid Phone Number")
- query = db.query(models.User.id).filter(models.User.email_address == user.email_address)
- user_exists = db.query(query.exists()).scalar()
- if user_exists:
- raise HTTPException(status_code=409, detail="User Already Exists")
- user = models.User(**user.model_dump())
- login = models.Login(id = user.id, email_address = user.email_address, password = user.password)
- db.add(user)
- db.add(login)
- db.commit()
- db.refresh(user)
- return user
- @app.get("/login/")
- async def check_user_login(user: LoginBase, db: db_dependency, skip: int=0, limit: int=100):
- if not validate_email(user.email_address):
- raise HTTPException(status_code=400, detail="Not A Valid Email")
- if not validate_password(user.password):
- raise HTTPException(status_code=400, detail="Not A Valid Password")
- query_email = db.query(models.Login.id).filter(models.Login.email_address == user.email_address)
- query_pw = db.query(models.Login.id).filter(models.Login.password == user.password)
- if not query_email or query_pw:
- raise HTTPException(status_code=400, detail="Email/Password Does Not Exist")
- user = db.query(models.User).offset(skip).limit(limit).filter(models.Login.id)
- return user
Advertisement
Add Comment
Please, Sign In to add comment