fix metagen deps
This commit is contained in:
@@ -3,9 +3,10 @@ package middleware
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"maxwarden/config"
|
||||
"maxwarden/constants"
|
||||
"maxwarden/security"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -15,9 +16,13 @@ func LoadSession(h http.HandlerFunc) http.HandlerFunc {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var sessionMap map[string]interface{}
|
||||
|
||||
sessionCookie, err := r.Cookie(config.SESSION_COOKIE_NAME)
|
||||
sessionCookie, err := r.Cookie(constants.SESSION_COOKIE_NAME)
|
||||
if err == nil {
|
||||
decryptMap, _ := security.DecryptData[map[string]interface{}]([]byte(security.DecodeBase58(sessionCookie.Value)))
|
||||
decryptMap, _ := security.DecryptData[map[string]interface{}](
|
||||
[]byte(security.DecodeBase58(sessionCookie.Value)),
|
||||
config.GetConfig().IdentityPrivateKey,
|
||||
)
|
||||
|
||||
sessionMap = *decryptMap
|
||||
}
|
||||
|
||||
@@ -41,14 +46,14 @@ func PutSessionCookie(w http.ResponseWriter, r *http.Request, session map[string
|
||||
// calculate total bytes used by other cookies
|
||||
var totalBytes int
|
||||
for _, cookie := range cookies {
|
||||
if cookie.Name == config.SESSION_COOKIE_NAME {
|
||||
if cookie.Name == constants.SESSION_COOKIE_NAME {
|
||||
continue
|
||||
} else {
|
||||
totalBytes += len(cookie.Value)
|
||||
}
|
||||
}
|
||||
|
||||
sessionData, err := security.EncryptData(&session)
|
||||
sessionData, err := security.EncryptData(&session, config.GetConfig().IdentityPrivateKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -61,7 +66,7 @@ func PutSessionCookie(w http.ResponseWriter, r *http.Request, session map[string
|
||||
}
|
||||
|
||||
httpCookie := &http.Cookie{
|
||||
Name: config.SESSION_COOKIE_NAME,
|
||||
Name: constants.SESSION_COOKIE_NAME,
|
||||
Value: security.EncodeBase58(sessionData),
|
||||
HttpOnly: true,
|
||||
Secure: r.URL.Scheme == "https",
|
||||
@@ -74,7 +79,7 @@ func PutSessionCookie(w http.ResponseWriter, r *http.Request, session map[string
|
||||
|
||||
func DeleteSessionCookie(w http.ResponseWriter, r *http.Request) {
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: config.SESSION_COOKIE_NAME,
|
||||
Name: constants.SESSION_COOKIE_NAME,
|
||||
MaxAge: -1,
|
||||
Expires: time.Now().Add(-100 * time.Hour),
|
||||
Path: "/",
|
||||
|
||||
Reference in New Issue
Block a user