Various fixes in login sources (#10428)
This commit is contained in:
parent
542bd59239
commit
09dbd85a3a
15 changed files with 66 additions and 21 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -87,6 +88,9 @@ var (
|
|||
|
||||
// ErrUnsupportedLoginType login source is unknown error
|
||||
ErrUnsupportedLoginType = errors.New("Login source is unknown")
|
||||
|
||||
// Characters prohibited in a user name (anything except A-Za-z0-9_.-)
|
||||
alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
|
||||
)
|
||||
|
||||
// User represents the object of individual and member of organization.
|
||||
|
@ -906,6 +910,11 @@ func isUsableName(names, patterns []string, name string) error {
|
|||
|
||||
// IsUsableUsername returns an error when a username is reserved
|
||||
func IsUsableUsername(name string) error {
|
||||
// Validate username make sure it satisfies requirement.
|
||||
if alphaDashDotPattern.MatchString(name) {
|
||||
// Note: usually this error is normally caught up earlier in the UI
|
||||
return ErrNameCharsNotAllowed{Name: name}
|
||||
}
|
||||
return isUsableName(reservedUsernames, reservedUserPatterns, name)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue