1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-17 07:40:23 +08:00
Files
paper-manager/backend/register.go
2023-03-19 22:39:41 +08:00

28 lines
543 B
Go

package backend
import (
"errors"
"time"
"github.com/FloatTech/ttl"
"github.com/fumiama/paper-manager/backend/global"
)
var registerlimit = ttl.NewCache[string, bool](time.Minute * 10)
var (
errRequestTooFast = errors.New("request too fast")
errInvalidIP = errors.New("invalid IP")
)
func register(ip, name, mobile, npwd string) error {
if registerlimit.Get(ip) {
return errRequestTooFast
}
if ip == "" {
return errInvalidIP
}
registerlimit.Set(ip, true)
return global.UserDB.NotifyRegister(ip, name, mobile, npwd)
}