Squash username to all lowercase letters upon registration (#361)

* Squash username to all lowercase letters upon registration

Signed-off-by: Andrew Morgan (https://amorgan.xyz) <andrew@amorgan.xyz>
main
Andrew Morgan 2017-12-04 09:40:36 +00:00 committed by Erik Johnston
parent cc12fc930a
commit 791a5ee7f4
1 changed files with 11 additions and 1 deletions

View File

@ -49,7 +49,7 @@ const (
var (
// TODO: Remove old sessions. Need to do so on a session-specific timeout.
sessions = make(map[string][]authtypes.LoginType) // Sessions and completed flow stages
validUsernameRegex = regexp.MustCompile(`^[0-9a-zA-Z_\-./]+$`)
validUsernameRegex = regexp.MustCompile(`^[0-9a-z_\-./]+$`)
)
// registerRequest represents the submitted registration request.
@ -183,6 +183,9 @@ func Register(
}
}
// Squash username to all lowercase letters
r.Username = strings.ToLower(r.Username)
if resErr = validateUserName(r.Username); resErr != nil {
return *resErr
}
@ -278,6 +281,10 @@ func LegacyRegister(
if resErr != nil {
return *resErr
}
// Squash username to all lowercase letters
r.Username = strings.ToLower(r.Username)
if resErr = validateUserName(r.Username); resErr != nil {
return *resErr
}
@ -478,6 +485,9 @@ func RegisterAvailable(
) util.JSONResponse {
username := req.URL.Query().Get("username")
// Squash username to all lowercase letters
username = strings.ToLower(username)
if err := validateUserName(username); err != nil {
return *err
}