MCPcopy Create free account
hub / github.com/daodst/chat / validateUsername

Function validateUsername

clientapi/routing/register.go:279–298  ·  view source on GitHub ↗

validateUsername returns an error response if the username is invalid

(username string)

Source from the content-addressed store, hash-verified

277
278// validateUsername returns an error response if the username is invalid
279func validateUsername(username string) *util.JSONResponse {
280 // https://github.com/matrix-org/synapse/blob/v0.20.0/synapse/rest/client/v2_alpha/register.py#L161
281 if len(username) > maxUsernameLength {
282 return &util.JSONResponse{
283 Code: http.StatusBadRequest,
284 JSON: jsonerror.BadJSON(fmt.Sprintf("'username' >%d characters", maxUsernameLength)),
285 }
286 } else if !validUsernameRegex.MatchString(username) {
287 return &util.JSONResponse{
288 Code: http.StatusBadRequest,
289 JSON: jsonerror.InvalidUsername("Username can only contain characters a-z, 0-9, or '_-./='"),
290 }
291 } else if username[0] == '_' { // Regex checks its not a zero length string
292 return &util.JSONResponse{
293 Code: http.StatusBadRequest,
294 JSON: jsonerror.InvalidUsername("Username cannot start with a '_'"),
295 }
296 }
297 return nil
298}
299
300// validateApplicationServiceUsername returns an error response if the username is invalid for an application service
301func validateApplicationServiceUsername(username string) *util.JSONResponse {

Callers 3

RegisterFunction · 0.85
RegisterAvailableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected