mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-17 06:52:59 +00:00
validate usernames
via Authenticator.validate_username base class configurable with Authenticator.username_pattern
This commit is contained in:
@@ -33,14 +33,25 @@ class UserListAPIHandler(APIHandler):
|
||||
admin = data.get('admin', False)
|
||||
|
||||
to_create = []
|
||||
invalid_names = []
|
||||
for name in usernames:
|
||||
name = self.authenticator.normalize_username(name)
|
||||
if not self.authenticator.validate_username(name):
|
||||
invalid_names.append(name)
|
||||
continue
|
||||
user = self.find_user(name)
|
||||
if user is not None:
|
||||
self.log.warn("User %s already exists" % name)
|
||||
else:
|
||||
to_create.append(name)
|
||||
|
||||
if invalid_names:
|
||||
if len(invalid_names) == 1:
|
||||
msg = "Invalid username: %s" % invalid_names[0]
|
||||
else:
|
||||
msg = "Invalid usernames: %s" % ', '.join(invalid_names)
|
||||
raise web.HTTPError(400, msg)
|
||||
|
||||
if not to_create:
|
||||
raise web.HTTPError(400, "All %i users already exist" % len(usernames))
|
||||
|
||||
|
Reference in New Issue
Block a user