-
Notifications
You must be signed in to change notification settings - Fork 25
/
logout.go
39 lines (33 loc) · 1.07 KB
/
logout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package user is a child of package api to handle api calls concerning users
package user
import (
"log"
"net/http"
"strconv"
"strings"
"time"
)
// Logout function is accessed by an API call from the webhost root
// by accessing /user_logout and sending it an empty POST request. This function will
// delete the user-auth cookie session store
func Logout(res http.ResponseWriter, req *http.Request, logger *log.Logger, dir string) bool {
if req.Method != "POST" {
logger.Println(req.URL.Path + "::" + req.Method + "::" + strconv.Itoa(http.StatusMethodNotAllowed) + "::" + http.StatusText(http.StatusMethodNotAllowed))
http.Error(res, req.Method+" HTTP method is unsupported for this API.", http.StatusMethodNotAllowed)
return false
}
var sessionName string
if strings.Contains(dir, "bundles/") {
sessionName = "gpanel-account-user-auth"
} else {
sessionName = "gpanel-server-user-auth"
}
http.SetCookie(res, &http.Cookie{
Name: sessionName,
Value: "",
Path: "/",
Expires: time.Unix(0, 0),
})
res.WriteHeader(http.StatusNoContent)
return true
}