2022-09-29 16:15:59 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
2022-11-21 15:20:04 +08:00
|
|
|
"strconv"
|
|
|
|
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
2022-11-21 15:20:04 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
2022-11-21 15:20:04 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2022-09-29 16:15:59 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func PasswordExpired() gin.HandlerFunc {
|
|
|
|
return func(c *gin.Context) {
|
2022-11-21 15:20:04 +08:00
|
|
|
settingRepo := repo.NewISettingRepo()
|
|
|
|
setting, err := settingRepo.Get(settingRepo.WithByKey("ExpirationDays"))
|
2022-09-29 16:15:59 +08:00
|
|
|
if err != nil {
|
2022-11-21 15:20:04 +08:00
|
|
|
global.LOG.Errorf("create operation record failed, err: %v", err)
|
|
|
|
}
|
|
|
|
expiredDays, _ := strconv.Atoi(setting.Value)
|
|
|
|
if expiredDays == 0 {
|
|
|
|
c.Next()
|
2022-11-24 23:56:48 +08:00
|
|
|
return
|
2022-11-21 15:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := c.Cookie(constant.PasswordExpiredName); err != nil {
|
2022-09-29 16:15:59 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|