Extract method httpSessionLogout

This commit is contained in:
Peter Stuifzand 2019-05-13 21:57:07 +02:00
parent 4c1b768a09
commit ed336fe39a
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -538,19 +538,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
} else if r.URL.Path == "/session/logout" {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", 302)
return
}
if err == nil {
sessionVar := c.Value
_, _ = conn.Do("DEL", "session:"+sessionVar)
}
http.Redirect(w, r, "/", 302)
httpSessionLogout(r, w, conn)
return
} else if r.URL.Path == "/auth/approve" {
// create a code
@ -681,3 +669,16 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
}
func httpSessionLogout(r *http.Request, w http.ResponseWriter, conn redis.Conn) {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", 302)
return
}
if err == nil {
sessionVar := c.Value
_, _ = conn.Do("DEL", "session:"+sessionVar)
}
http.Redirect(w, r, "/", 302)
}