Fix user authentication when backend is down
This commit is contained in:
@@ -40,14 +40,20 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
|
|||||||
t.PixelAPI = pixelapi.New(wc.conf.APIURLInternal, key)
|
t.PixelAPI = pixelapi.New(wc.conf.APIURLInternal, key)
|
||||||
uinf, err := t.PixelAPI.UserInfo()
|
uinf, err := t.PixelAPI.UserInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This session key doesn't work, delete it
|
// This session key doesn't work, or the backend is down, user
|
||||||
|
// cannot be authenticated
|
||||||
log.Debug("Session check for key '%s' failed: %s", key, err)
|
log.Debug("Session check for key '%s' failed: %s", key, err)
|
||||||
http.SetCookie(w, &http.Cookie{
|
|
||||||
Name: "pd_auth_key",
|
if aerr, ok := err.(pixelapi.Error); ok && aerr.Value == "authentication_required" {
|
||||||
Value: "",
|
// This key is invalid, delete it
|
||||||
Path: "/",
|
log.Debug("Deleting invalid API key")
|
||||||
Expires: time.Unix(0, 0),
|
http.SetCookie(w, &http.Cookie{
|
||||||
})
|
Name: "pd_auth_key",
|
||||||
|
Value: "",
|
||||||
|
Path: "/",
|
||||||
|
Expires: time.Unix(0, 0),
|
||||||
|
})
|
||||||
|
}
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user