Skip to content

Commit

Permalink
feat: user save limit (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeessy2 authored Oct 8, 2024
1 parent 7520de4 commit 33a327c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions web/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import (
"backup-x/client"
"backup-x/entity"
"backup-x/util"
"fmt"
"log"
"net/http"
"strconv"
"strings"
"time"
)

// 服务启动时间
var startTime = time.Now()

// 保存限制时间
var saveLimit = time.Duration(30 * time.Minute)

// Save 保存
func Save(writer http.ResponseWriter, request *http.Request) {
oldConf, _ := entity.GetConfigCache()
Expand All @@ -35,6 +42,10 @@ func Save(writer http.ResponseWriter, request *http.Request) {
return
}
if conf.Password != oldConf.Password {
if time.Since(startTime) > saveLimit {
writer.Write([]byte(fmt.Sprintf("需在 %s 之前完成用户名密码设置,请重启backup-x", startTime.Add(saveLimit).Format("2006-01-02 15:04:05"))))
return
}
encryptPasswd, err := util.EncryptByEncryptKey(conf.EncryptKey, conf.Password)
if err != nil {
writer.Write([]byte("加密失败"))
Expand Down

0 comments on commit 33a327c

Please sign in to comment.