mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-13 17:24:44 +08:00
fix: 密码过期校验调整
This commit is contained in:
parent
cdf3f8cdd0
commit
9f5cc07e9f
@ -41,8 +41,7 @@ func (u *AuthService) SafeEntrance(c *gin.Context, code string) error {
|
||||
return err
|
||||
}
|
||||
timeout, _ := strconv.Atoi(expiredSetting.Value)
|
||||
c.SetCookie(constant.PasswordExpiredName, encrypt.Md5(time.Now().Format("20060102150405")), 86400*timeout, "", "", false, false)
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006.01.02 15:04:05")); err != nil {
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006-01-02 15:04:05")); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -203,8 +202,7 @@ func (u *AuthService) InitUser(c *gin.Context, req dto.InitUser) error {
|
||||
}
|
||||
timeout, _ := strconv.Atoi(expiredSetting.Value)
|
||||
if timeout != 0 {
|
||||
c.SetCookie(constant.PasswordExpiredName, encrypt.Md5(time.Now().Format("20060102150405")), 86400*timeout, "", "", false, false)
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006.01.02 15:04:05")); err != nil {
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006-01-02 15:04:05")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -51,10 +51,9 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
|
||||
func (u *SettingService) Update(c *gin.Context, key, value string) error {
|
||||
if key == "ExpirationDays" {
|
||||
timeout, _ := strconv.Atoi(value)
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006.01.02 15:04:05")); err != nil {
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006-01-02 15:04:05")); err != nil {
|
||||
return err
|
||||
}
|
||||
c.SetCookie(constant.PasswordExpiredName, encrypt.Md5(time.Now().Format("20060102150405")), 86400*timeout, "", "", false, false)
|
||||
}
|
||||
if err := settingRepo.Update(key, value); err != nil {
|
||||
return err
|
||||
@ -85,8 +84,7 @@ func (u *SettingService) HandlePasswordExpired(c *gin.Context, old, new string)
|
||||
return err
|
||||
}
|
||||
timeout, _ := strconv.Atoi(expiredSetting.Value)
|
||||
c.SetCookie(constant.PasswordExpiredName, encrypt.Md5(time.Now().Format("20060102150405")), 86400*timeout, "", "", false, false)
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006.01.02 15:04:05")); err != nil {
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006-01-02 15:04:05")); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -84,7 +84,7 @@ var AddTableSetting = &gormigrate.Migration{
|
||||
if err := tx.Create(&model.Setting{Key: "SecurityEntrance", Value: "onepanel"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "ExpirationTime", Value: time.Now().AddDate(0, 0, 10).Format("2006.01.02 15:04:05")}).Error; err != nil {
|
||||
if err := tx.Create(&model.Setting{Key: "ExpirationTime", Value: time.Now().AddDate(0, 0, 10).Format("2006-01-02 15:04:05")}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "ExpirationDays", Value: "0"}).Error; err != nil {
|
||||
|
@ -2,11 +2,11 @@ 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/1Panel-dev/1Panel/backend/global"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -15,7 +15,8 @@ func PasswordExpired() gin.HandlerFunc {
|
||||
settingRepo := repo.NewISettingRepo()
|
||||
setting, err := settingRepo.Get(settingRepo.WithByKey("ExpirationDays"))
|
||||
if err != nil {
|
||||
global.LOG.Errorf("create operation record failed, err: %v", err)
|
||||
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
|
||||
return
|
||||
}
|
||||
expiredDays, _ := strconv.Atoi(setting.Value)
|
||||
if expiredDays == 0 {
|
||||
@ -23,7 +24,17 @@ func PasswordExpired() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := c.Cookie(constant.PasswordExpiredName); err != nil {
|
||||
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
|
||||
}
|
||||
|
@ -531,6 +531,7 @@ export default {
|
||||
users: 'User',
|
||||
hosts: 'Host',
|
||||
groups: 'Group',
|
||||
containers: 'Container',
|
||||
commands: 'Command',
|
||||
backups: 'Backup Account',
|
||||
settings: 'Panel Setting',
|
||||
@ -539,6 +540,7 @@ export default {
|
||||
status: ' Update status',
|
||||
auth: 'User',
|
||||
login: ' login',
|
||||
operate: ' operate',
|
||||
logout: ' logout',
|
||||
post: ' create',
|
||||
put: ' update',
|
||||
|
@ -546,6 +546,7 @@ export default {
|
||||
users: '用户',
|
||||
hosts: '主机',
|
||||
groups: '组',
|
||||
containers: '容器',
|
||||
commands: '快捷命令',
|
||||
backups: '备份账号',
|
||||
settings: '面板设置',
|
||||
@ -560,6 +561,7 @@ export default {
|
||||
login: '登录',
|
||||
backup: '备份',
|
||||
recover: '恢复',
|
||||
operate: '操作',
|
||||
logout: '退出',
|
||||
del: '删除',
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user