1Panel/backend/middleware/password_expired.go
2022-11-22 15:39:28 +08:00

31 lines
837 B
Go

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 PasswordExpired() gin.HandlerFunc {
return func(c *gin.Context) {
settingRepo := repo.NewISettingRepo()
setting, err := settingRepo.Get(settingRepo.WithByKey("ExpirationDays"))
if err != nil {
global.LOG.Errorf("create operation record failed, err: %v", err)
}
expiredDays, _ := strconv.Atoi(setting.Value)
if expiredDays == 0 {
c.Next()
}
if _, err := c.Cookie(constant.PasswordExpiredName); err != nil {
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, nil)
return
}
c.Next()
}
}