Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2024-12-16 16:24:59 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2024-12-16 16:24:59 +0300
commitb29bd993d4e2f03b7ec6a61761fa7806458365b3 (patch)
tree381d41b599b4b156cb08063403e5c3f31fcc2126 /web/session/session.go
parent127eaf69b619a4e0a53485666ad485a499edf333 (diff)
fix session
twice set-cookie bug fixed
Diffstat (limited to 'web/session/session.go')
-rw-r--r--web/session/session.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/web/session/session.go b/web/session/session.go
index f5055efd..13aedad8 100644
--- a/web/session/session.go
+++ b/web/session/session.go
@@ -10,38 +10,41 @@ import (
)
const (
- loginUser = "LOGIN_USER"
- defaultPath = "/"
+ loginUserKey = "LOGIN_USER"
+ defaultPath = "/"
)
func init() {
gob.Register(model.User{})
}
-func SetLoginUser(c *gin.Context, user *model.User) error {
+func SetLoginUser(c *gin.Context, user *model.User) {
+ if user == nil {
+ return
+ }
s := sessions.Default(c)
- s.Set(loginUser, user)
- return s.Save()
+ s.Set(loginUserKey, *user)
}
-func SetMaxAge(c *gin.Context, maxAge int) error {
+func SetMaxAge(c *gin.Context, maxAge int) {
s := sessions.Default(c)
s.Options(sessions.Options{
Path: defaultPath,
MaxAge: maxAge,
HttpOnly: true,
})
- return s.Save()
}
func GetLoginUser(c *gin.Context) *model.User {
s := sessions.Default(c)
- obj := s.Get(loginUser)
+ obj := s.Get(loginUserKey)
if obj == nil {
return nil
}
user, ok := obj.(model.User)
if !ok {
+
+ s.Delete(loginUserKey)
return nil
}
return &user
@@ -51,7 +54,7 @@ func IsLogin(c *gin.Context) bool {
return GetLoginUser(c) != nil
}
-func ClearSession(c *gin.Context) error {
+func ClearSession(c *gin.Context) {
s := sessions.Default(c)
s.Clear()
s.Options(sessions.Options{
@@ -59,5 +62,4 @@ func ClearSession(c *gin.Context) error {
MaxAge: -1,
HttpOnly: true,
})
- return s.Save()
}