basepath fixes

This commit is contained in:
Nazar Kanaev
2021-03-17 16:25:16 +00:00
parent 5e453e3227
commit f3c55ba5f2
4 changed files with 25 additions and 29 deletions

View File

@@ -23,30 +23,21 @@ func IsAuthenticated(req *http.Request, username, password string) bool {
}
func Authenticate(rw http.ResponseWriter, username, password, basepath string) {
expires := time.Now().Add(time.Hour * 24 * 7) // 1 week
var cookiePath string
if basepath != "" {
cookiePath = basepath
} else {
cookiePath = "/"
}
cookie := http.Cookie{
http.SetCookie(rw, &http.Cookie{
Name: "auth",
Value: username + ":" + secret(username, password),
Expires: expires,
Path: cookiePath,
}
http.SetCookie(rw, &cookie)
Expires: time.Now().Add(time.Hour * 24 * 7), // 1 week,
Path: basepath,
})
}
func Logout(rw http.ResponseWriter) {
cookie := http.Cookie{
func Logout(rw http.ResponseWriter, basepath string) {
http.SetCookie(rw, &http.Cookie{
Name: "auth",
Value: "",
MaxAge: -1,
}
http.SetCookie(rw, &cookie)
Path: basepath,
})
}
func StringsEqual(p1, p2 string) bool {