mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-02 11:57:04 +08:00
fix (#422): retrocompatibility with authentication middleware
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewBool(t bool) *bool {
|
func NewBool(t bool) *bool {
|
||||||
@ -81,3 +82,10 @@ func PrettyPrint(json_dirty []byte) []byte {
|
|||||||
json_pretty.Write([]byte("\n"))
|
json_pretty.Write([]byte("\n"))
|
||||||
return json_pretty.Bytes()
|
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"
|
"github.com/mickael-kerjean/filestash/server/model"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -96,7 +95,7 @@ func SessionAuthenticate(ctx App, res http.ResponseWriter, req *http.Request) {
|
|||||||
end = len(obfuscate)
|
end = len(obfuscate)
|
||||||
}
|
}
|
||||||
http.SetCookie(res, &http.Cookie{
|
http.SetCookie(res, &http.Cookie{
|
||||||
Name: COOKIE_NAME_AUTH + strconv.Itoa(index),
|
Name: CookieName(index),
|
||||||
Value: obfuscate[index*value_limit : end],
|
Value: obfuscate[index*value_limit : end],
|
||||||
MaxAge: 60 * Config.Get("general.cookie_timeout").Int(),
|
MaxAge: 60 * Config.Get("general.cookie_timeout").Int(),
|
||||||
Path: COOKIE_PATH,
|
Path: COOKIE_PATH,
|
||||||
@ -135,12 +134,12 @@ func SessionLogout(ctx App, res http.ResponseWriter, req *http.Request) {
|
|||||||
}()
|
}()
|
||||||
index := 0
|
index := 0
|
||||||
for {
|
for {
|
||||||
_, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index))
|
_, err := req.Cookie(CookieName(index))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
http.SetCookie(res, &http.Cookie{
|
http.SetCookie(res, &http.Cookie{
|
||||||
Name: COOKIE_NAME_AUTH + strconv.Itoa(index),
|
Name: CookieName(index),
|
||||||
Value: "",
|
Value: "",
|
||||||
MaxAge: -1,
|
MaxAge: -1,
|
||||||
Path: COOKIE_PATH,
|
Path: COOKIE_PATH,
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import (
|
|||||||
. "github.com/mickael-kerjean/filestash/server/common"
|
. "github.com/mickael-kerjean/filestash/server/common"
|
||||||
"github.com/mickael-kerjean/filestash/server/model"
|
"github.com/mickael-kerjean/filestash/server/model"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,7 +44,8 @@ func ShareUpsert(ctx App, res http.ResponseWriter, req *http.Request) {
|
|||||||
str := ""
|
str := ""
|
||||||
index := 0
|
index := 0
|
||||||
for {
|
for {
|
||||||
cookie, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index))
|
|
||||||
|
cookie, err := req.Cookie(CookieName(index))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/mickael-kerjean/filestash/server/model"
|
"github.com/mickael-kerjean/filestash/server/model"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -260,7 +259,7 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) {
|
|||||||
str := ""
|
str := ""
|
||||||
index := 0
|
index := 0
|
||||||
for {
|
for {
|
||||||
cookie, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index))
|
cookie, err := req.Cookie(CookieName(index))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user