mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-16 12:39:15 +08:00
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package middleware
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"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/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 {
|
|
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
|
|
return
|
|
}
|
|
expiredDays, _ := strconv.Atoi(setting.Value)
|
|
if expiredDays == 0 {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
extime, err := settingRepo.Get(settingRepo.WithByKey("ExpirationTime"))
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
|
|
return
|
|
}
|
|
expiredTime, err := time.Parse("2006-01-02 15:04:05", extime.Value)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
|
|
return
|
|
}
|
|
if time.Now().After(expiredTime) {
|
|
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, nil)
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|