1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

Handle the case when application session is expired and not user session

This commit is contained in:
Frédéric Guillot 2019-01-21 20:21:05 -08:00
parent 6378ad2734
commit 7897d8a8ad
5 changed files with 65 additions and 32 deletions

View file

@ -61,12 +61,21 @@ func (m *middleware) handleAppSession(next http.Handler) http.Handler {
session := m.getAppSessionValueFromCookie(r)
if session == nil {
logger.Debug("[UI:AppSession] Session not found")
session, err = m.store.CreateSession()
if err != nil {
html.ServerError(w, r, err)
return
if (request.IsAuthenticated(r)) {
userID := request.UserID(r)
logger.Debug("[UI:AppSession] Cookie expired but user #%d is logged: creating a new session", userID)
session, err = m.store.CreateAppSessionWithUserPrefs(userID)
if err != nil {
html.ServerError(w, r, err)
return
}
} else {
logger.Debug("[UI:AppSession] Session not found, creating a new one")
session, err = m.store.CreateAppSession()
if err != nil {
html.ServerError(w, r, err)
return
}
}
http.SetCookie(w, cookie.New(cookie.CookieSessionID, session.ID, m.cfg.IsHTTPS, m.cfg.BasePath()))
@ -104,7 +113,7 @@ func (m *middleware) getAppSessionValueFromCookie(r *http.Request) *model.Sessio
return nil
}
session, err := m.store.Session(cookieValue)
session, err := m.store.AppSession(cookieValue)
if err != nil {
logger.Error("[UI:AppSession] %v", err)
return nil