Add unique username check when creating users.

This commit is contained in:
Lance Edgar 2015-01-15 01:40:00 -06:00
parent 4535ba0851
commit b7aa4b36d0

View file

@ -27,7 +27,7 @@ User Views
from __future__ import unicode_literals
from formalchemy import Field
from formalchemy import Field, ValidationError
from formalchemy.fields import SelectFieldRenderer
from edbob.pyramid.views import users
@ -168,6 +168,12 @@ class UserCrud(CrudView):
fs.active,
])
if self.creating:
def valid_username(value, field):
if Session.query(User).filter_by(username=value).count():
raise ValidationError("Username must be unique.")
fs.username.set(validate=valid_username)
if self.readonly:
del fs.password
del fs.confirm_password