|
@@ -73,7 +73,7 @@ async def index(request: Request):
|
|
|
async def login(request: Request):
|
|
|
return templates.TemplateResponse(name='login.html', context={'request': request})
|
|
|
|
|
|
-@app.post("/login", response_class=HTMLResponse)
|
|
|
+@app.post("/login")
|
|
|
async def login_for_access_token(request: Request, form_data: OAuth2PasswordRequestForm = Depends(), Authorize: AuthJWT = Depends()):
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/aaron_testdb?charset=utf8mb4')
|
|
|
user = authenticate_user(form_data.username, form_data.password)
|
|
@@ -95,8 +95,8 @@ async def login_for_access_token(request: Request, form_data: OAuth2PasswordRequ
|
|
|
refresh_token = Authorize.create_refresh_token(subject=user.username)
|
|
|
Authorize.set_access_cookies(access_token)
|
|
|
Authorize.set_refresh_cookies(refresh_token)
|
|
|
- return templates.TemplateResponse("home.html", {"request": request, "msg": 'Login'})
|
|
|
- # return {"access_token": access_token, "token_type": "bearer"}
|
|
|
+ # return templates.TemplateResponse("home.html", {"request": request, "msg": 'Login'})
|
|
|
+ return {"access_token": access_token, "token_type": "bearer"} # 回傳token給前端
|
|
|
|
|
|
|
|
|
@app.get('/register', response_class=HTMLResponse)
|