Add unique username check when creating users.
This commit is contained in:
parent
4535ba0851
commit
b7aa4b36d0
|
@ -27,7 +27,7 @@ User Views
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from formalchemy import Field
|
from formalchemy import Field, ValidationError
|
||||||
from formalchemy.fields import SelectFieldRenderer
|
from formalchemy.fields import SelectFieldRenderer
|
||||||
|
|
||||||
from edbob.pyramid.views import users
|
from edbob.pyramid.views import users
|
||||||
|
@ -168,6 +168,12 @@ class UserCrud(CrudView):
|
||||||
fs.active,
|
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:
|
if self.readonly:
|
||||||
del fs.password
|
del fs.password
|
||||||
del fs.confirm_password
|
del fs.confirm_password
|
||||||
|
|
Loading…
Reference in a new issue