import time from fastapi import HTTPException,APIRouter from .pydanticModel import * from .dao import tableStore router = APIRouter() # 定义路由和函数 @router.post("/login") @router.get("/login") async def login(login: signIn): # ->"user info or throw error" # 检查email和password是否匹配 table_store = tableStore(ots_client=router.ots_client,table_name=router.table_name) try: login_result = table_store.login(login.email, login.password) if login_result['ec']==200: return login_result else: raise HTTPException(status_code=400, detail="login failed in table store") except Exception as e: print(e) raise HTTPException(status_code=400, detail="sign in failed") @router.get("/signUp") @router.post("/signUp") async def sign_up(signUp: signUp): # ->"user info or throw error" table_store = tableStore(ots_client=router.ots_client,table_name=router.table_name) try: signUp_result = table_store.userSignUp(signUp.email,signUp.password) if signUp_result['ec']==200: return signUp_result else: raise HTTPException(status_code=400, detail="sign up failed in table store") except Exception as e: raise HTTPException(status_code=400, detail="sign up failed") @router.get("/purchase") @router.post("/purchase") async def purchase(plan: userPlan): #->bool or raise error # 提取plan价格和时间 price = plan.price time_to_add = plan.duration_seconds email = plan.email password = plan.password table_store = tableStore(ots_client=router.ots_client, table_name=router.table_name) # 读取存储数据,如果存的expiredAt>now,那么从expiredAt加时间 # 如果存的