Add logout
This commit is contained in:
parent
93faba100e
commit
05d7c498c3
|
|
@ -112,6 +112,12 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if sess.LoggedIn {
|
if sess.LoggedIn {
|
||||||
fmt.Fprintf(w, "SUCCESS Me = %s", sess.Me)
|
fmt.Fprintf(w, "SUCCESS Me = %s", sess.Me)
|
||||||
|
fmt.Fprintln(w, `
|
||||||
|
<h2>Logout</h2>
|
||||||
|
<form action="/auth/logout" method="post">
|
||||||
|
<button type="submit">Logout</button>
|
||||||
|
</form>
|
||||||
|
`)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(w, `
|
fmt.Fprintln(w, `
|
||||||
<h2>Sign in to Ekster</h2>
|
<h2>Sign in to Ekster</h2>
|
||||||
|
|
@ -237,9 +243,18 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
http.Redirect(w, r, authURL.String(), 302)
|
http.Redirect(w, r, authURL.String(), 302)
|
||||||
return
|
return
|
||||||
}
|
} else if r.URL.Path == "/auth/logout" {
|
||||||
|
c, err := r.Cookie("session")
|
||||||
|
if err == http.ErrNoCookie {
|
||||||
|
http.Redirect(w, r, "/", 302)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
sessionVar := c.Value
|
||||||
|
conn.Do("DEL", "session:"+sessionVar)
|
||||||
|
http.Redirect(w, r, "/", 302)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user