2022-08-16 23:30:23 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/1Panel-dev/1Panel/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/constant"
|
|
|
|
"github.com/1Panel-dev/1Panel/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()
|
|
|
|
}
|
|
|
|
sId, err := c.Cookie(global.CONF.Session.SessionName)
|
|
|
|
if err != nil {
|
2022-08-17 11:47:56 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeNotLogin, nil)
|
2022-08-16 23:30:23 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if _, err := global.SESSION.Get(sId); err != nil {
|
2022-08-17 11:47:56 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeNotLogin, nil)
|
2022-08-16 23:30:23 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|