fix (#422): retrocompatibility with authentication middleware

This commit is contained in:
Mickael Kerjean
2022-02-01 17:16:21 +11:00
parent bc2eae63c6
commit 82e12ca1a6
4 changed files with 14 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"io"
"io/ioutil"
"strconv"
)
func NewBool(t bool) *bool {
@ -81,3 +82,10 @@ func PrettyPrint(json_dirty []byte) []byte {
json_pretty.Write([]byte("\n"))
return json_pretty.Bytes()
}
func CookieName(idx int) string {
if idx == 0 {
return COOKIE_NAME_AUTH
}
return COOKIE_NAME_AUTH + strconv.Itoa(idx)
}

View File

@ -8,7 +8,6 @@ import (
"github.com/mickael-kerjean/filestash/server/model"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)
@ -96,7 +95,7 @@ func SessionAuthenticate(ctx App, res http.ResponseWriter, req *http.Request) {
end = len(obfuscate)
}
http.SetCookie(res, &http.Cookie{
Name: COOKIE_NAME_AUTH + strconv.Itoa(index),
Name: CookieName(index),
Value: obfuscate[index*value_limit : end],
MaxAge: 60 * Config.Get("general.cookie_timeout").Int(),
Path: COOKIE_PATH,
@ -135,12 +134,12 @@ func SessionLogout(ctx App, res http.ResponseWriter, req *http.Request) {
}()
index := 0
for {
_, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index))
_, err := req.Cookie(CookieName(index))
if err != nil {
break
}
http.SetCookie(res, &http.Cookie{
Name: COOKIE_NAME_AUTH + strconv.Itoa(index),
Name: CookieName(index),
Value: "",
MaxAge: -1,
Path: COOKIE_PATH,

View File

@ -7,7 +7,6 @@ import (
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"net/http"
"strconv"
"strings"
)
@ -45,7 +44,8 @@ func ShareUpsert(ctx App, res http.ResponseWriter, req *http.Request) {
str := ""
index := 0
for {
cookie, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index))
cookie, err := req.Cookie(CookieName(index))
if err != nil {
break
}

View File

@ -10,7 +10,6 @@ import (
"github.com/mickael-kerjean/filestash/server/model"
"net/http"
"regexp"
"strconv"
"strings"
)
@ -260,7 +259,7 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) {
str := ""
index := 0
for {
cookie, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index))
cookie, err := req.Cookie(CookieName(index))
if err != nil {
break
}