Skip to content

Commit

Permalink
Update gradio/routes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Aug 4, 2023
1 parent fd3837d commit 222589f
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,31 @@ def app_id(request: fastapi.Request) -> dict:

@app.post("/login")
@app.post("/login/")
def login(form_data: OAuth2PasswordRequestForm = Depends()):
username, password = form_data.username, form_data.password
if app.auth is None:
return RedirectResponse(url="/", status_code=status.HTTP_302_FOUND)
if (
not callable(app.auth)
and username in app.auth
and app.auth[username] == password
) or (callable(app.auth) and app.auth.__call__(username, password)):
token = secrets.token_urlsafe(16)
app.tokens[token] = username
response = JSONResponse(content={"success": True})
response.set_cookie(
key="access-token",
value=token,
httponly=True,
samesite="none",
secure=True,
)
response.set_cookie(
key="access-token-unsecure", value=token, httponly=True
)
return response
else:
raise HTTPException(status_code=400, detail="Incorrect credentials.")
def login(form_data: OAuth2PasswordRequestForm = Depends()):
username, password = form_data.username.strip(), form_data.password
if app.auth is None:
return RedirectResponse(url="/", status_code=status.HTTP_302_FOUND)
if (
not callable(app.auth)
and username in app.auth
and app.auth[username] == password
) or (callable(app.auth) and app.auth.__call__(username, password)):
token = secrets.token_urlsafe(16)
app.tokens[token] = username
response = JSONResponse(content={"success": True})
response.set_cookie(
key="access-token",
value=token,
httponly=True,
samesite="none",
secure=True,
)
response.set_cookie(
key="access-token-unsecure", value=token, httponly=True
)
return response
else:
raise HTTPException(status_code=400, detail="Incorrect credentials.")

###############
# Main Routes
Expand Down

0 comments on commit 222589f

Please sign in to comment.