validate usernames

via Authenticator.validate_username

base class configurable with Authenticator.username_pattern
This commit is contained in:
Min RK
2016-01-08 15:49:16 +01:00
parent beb2dae6ce
commit 9441fa37c5
5 changed files with 62 additions and 1 deletions

View File

@@ -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))