Compare commits

..

4 Commits

Author SHA1 Message Date
67e617c969
Add pool
All checks were successful
continuous-integration/drone/push Build is passing
2019-05-29 22:58:22 +02:00
ed336fe39a
Extract method httpSessionLogout 2019-05-13 21:57:07 +02:00
4c1b768a09
Handle errors 2019-05-13 21:31:42 +02:00
28d7d953e2
Handle errors 2019-05-13 21:28:36 +02:00
2 changed files with 27 additions and 12 deletions

View File

@ -516,28 +516,29 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sess, err := loadSession(sessionVar, conn) sess, err := loadSession(sessionVar, conn)
if err != nil {
http.Redirect(w, r, "/", 302)
return
}
sess.AuthorizationEndpoint = endpoints.AuthorizationEndpoint sess.AuthorizationEndpoint = endpoints.AuthorizationEndpoint
sess.Me = meURL.String() sess.Me = meURL.String()
sess.State = state sess.State = state
sess.RedirectURI = redirectURI sess.RedirectURI = redirectURI
sess.LoggedIn = false sess.LoggedIn = false
saveSession(sessionVar, &sess, conn)
authenticationURL := indieauth.CreateAuthenticationURL(*authURL, meURL.String(), ClientID, redirectURI, state) err = saveSession(sessionVar, &sess, conn)
if err != nil {
http.Redirect(w, r, authenticationURL, 302)
return
} else if r.URL.Path == "/session/logout" {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", 302) http.Redirect(w, r, "/", 302)
return return
} }
sessionVar := c.Value authenticationURL := indieauth.CreateAuthenticationURL(*authURL, meURL.String(), ClientID, redirectURI, state)
conn.Do("DEL", "session:"+sessionVar) http.Redirect(w, r, authenticationURL, 302)
http.Redirect(w, r, "/", 302)
return
} else if r.URL.Path == "/session/logout" {
httpSessionLogout(r, w, conn)
return return
} else if r.URL.Path == "/auth/approve" { } else if r.URL.Path == "/auth/approve" {
// create a code // create a code
@ -668,3 +669,16 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r) 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)
}

View File

@ -126,6 +126,7 @@ func NewApp(options AppOptions) (*App, error) {
http.Handle("/micropub", &micropubHandler{ http.Handle("/micropub", &micropubHandler{
Backend: app.backend, Backend: app.backend,
pool: options.pool,
}) })
handler, broker := server.NewMicrosubHandler(app.backend) handler, broker := server.NewMicrosubHandler(app.backend)