mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-15 12:12:58 +08:00
31 lines
837 B
Go
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()
|
|
}
|
|
}
|