Added auth
This commit is contained in:
25
web/logoutHandler.go
Normal file
25
web/logoutHandler.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (ws *WebServer) LogoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie("session_id")
|
||||
if err != nil {
|
||||
http.Error(w, "No session found", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
delete(ws.sessions, cookie.Value)
|
||||
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "session_id",
|
||||
Value: "",
|
||||
Path: "/",
|
||||
HttpOnly: true,
|
||||
Expires: <-time.After(time.Second * 1),
|
||||
})
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
Reference in New Issue
Block a user