书写前端代码

This commit is contained in:
hoteas
2021-12-11 17:59:02 +08:00
parent 44e46982f5
commit db013b9966
13 changed files with 657 additions and 439 deletions
+11 -6
View File
@@ -294,15 +294,21 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
// 没有保存就生成随机的session
cookie, err := req.Cookie(that.Config.GetString("sessionName"))
sessionId := Md5(strconv.Itoa(Rand(10)))
token := req.FormValue("token")
token := req.Header.Get("Authorization")
if len(token) != 32 {
token = req.Header.Get("Authorization")
}
if len(token) == 32 && cookie.Value != token {
token = req.FormValue("token")
}
//没有cookie或者cookie不等于token
//有token优先token
if len(token) == 32 {
sessionId = token
} else {
//没有token,则查阅session
} else if err == nil && cookie.Value != "" {
sessionId = cookie.Value
//session也没有则判断是否创建cookie
} else {
//没有跨域设置
if that.Config.GetString("crossDomain") == "" {
http.SetCookie(w, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
@@ -310,7 +316,6 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
//跨域允许需要设置cookie的允许跨域https才有效果
w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
}
}
unescapeUrl, err := url.QueryUnescape(req.RequestURI)