mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-02 20:23:32 +08:00
fix (#422): retrocompatibility with authentication middleware
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user