mirror of https://gitee.com/answerdev/answer.git
Merge remote-tracking branch 'origin/feat/1.0.2/user' into test
This commit is contained in:
commit
35dbd269f9
|
@ -7,3 +7,6 @@ var Config []byte
|
|||
|
||||
//go:embed path_ignore.yaml
|
||||
var PathIgnore []byte
|
||||
|
||||
//go:embed reserved-usernames.json
|
||||
var ReservedUsernames []byte
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -126,6 +126,10 @@ func (us *UserCommon) MakeUsername(ctx context.Context, displayName string) (use
|
|||
return "", errors.BadRequest(reason.UsernameInvalid)
|
||||
}
|
||||
|
||||
if checker.IsReservedUsername(username) {
|
||||
return "", errors.BadRequest(reason.UsernameInvalid)
|
||||
}
|
||||
|
||||
for {
|
||||
_, has, err := us.userRepo.GetByUsername(ctx, username+suffix)
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/answerdev/answer/configs"
|
||||
"github.com/segmentfault/pacman/log"
|
||||
)
|
||||
|
||||
var (
|
||||
reservedUsernameMapping = make(map[string]bool)
|
||||
)
|
||||
|
||||
func init() {
|
||||
var usernames []string
|
||||
_ = json.Unmarshal(configs.ReservedUsernames, &usernames)
|
||||
log.Debugf("get reserved usernames %d", len(usernames))
|
||||
for _, username := range usernames {
|
||||
reservedUsernameMapping[username] = true
|
||||
}
|
||||
}
|
||||
|
||||
// IsReservedUsername checks whether the username is reserved
|
||||
func IsReservedUsername(username string) bool {
|
||||
return reservedUsernameMapping[username]
|
||||
}
|
Loading…
Reference in New Issue