mirror of https://github.com/1Panel-dev/1Panel
appstorecrontabdatabasedockerdocker-composedocker-containerdocker-imagedocker-uifilemanagerlamplnmppanel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
package middleware |
|
|
|
import ( |
|
"strconv" |
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" |
|
"github.com/1Panel-dev/1Panel/backend/app/repo" |
|
"github.com/1Panel-dev/1Panel/backend/constant" |
|
"github.com/1Panel-dev/1Panel/backend/global" |
|
"github.com/gin-gonic/gin" |
|
) |
|
|
|
func SessionAuth() gin.HandlerFunc { |
|
return func(c *gin.Context) { |
|
if method, exist := c.Get("authMethod"); exist && method == constant.AuthMethodJWT { |
|
c.Next() |
|
return |
|
} |
|
sId, err := c.Cookie(constant.SessionName) |
|
if err != nil { |
|
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeNotLogin, nil) |
|
return |
|
} |
|
psession, err := global.SESSION.Get(sId) |
|
if err != nil { |
|
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeNotLogin, nil) |
|
return |
|
} |
|
settingRepo := repo.NewISettingRepo() |
|
setting, err := settingRepo.Get(settingRepo.WithByKey("SessionTimeout")) |
|
if err != nil { |
|
global.LOG.Errorf("create operation record failed, err: %v", err) |
|
} |
|
lifeTime, _ := strconv.Atoi(setting.Value) |
|
_ = global.SESSION.Set(sId, psession, lifeTime) |
|
c.Next() |
|
} |
|
}
|
|
|