mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-18 17:00:24 +08:00
finish register
This commit is contained in:
27
backend/register.go
Normal file
27
backend/register.go
Normal file
@@ -0,0 +1,27 @@
|
||||
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 (
|
||||
errRegisterTooFast = errors.New("register too fast")
|
||||
errInvalidIP = errors.New("invalid IP")
|
||||
)
|
||||
|
||||
func register(ip, name, mobile, npwd string) error {
|
||||
if registerlimit.Get(ip) {
|
||||
return errRegisterTooFast
|
||||
}
|
||||
if ip == "" {
|
||||
return errInvalidIP
|
||||
}
|
||||
registerlimit.Set(ip, true)
|
||||
return global.UserDB.NotifyRegister(ip, name, mobile, npwd)
|
||||
}
|
||||
Reference in New Issue
Block a user