Browse Source

added check for unique username in registration

php2python
Holger Frey 7 years ago
parent
commit
738e4b90b4
  1. 7
      ordr2/schemas/account.py
  2. 12
      ordr2/schemas/helpers.py
  3. 2
      ordr2/views/account.py

7
ordr2/schemas/account.py

@ -2,7 +2,10 @@ import colander @@ -2,7 +2,10 @@ import colander
import deform
from . import CSRFSchema
from .helpers import deferred_unique_email_validator
from .helpers import (
deferred_unique_email_validator,
deferred_unique_username_validator
)
# schema for user registration
@ -14,7 +17,7 @@ class RegistrationSchema(CSRFSchema): @@ -14,7 +17,7 @@ class RegistrationSchema(CSRFSchema):
colander.String(),
widget=deform.widget.TextInputWidget(),
description='automagically generated for you',
missing=''
validator = deferred_unique_username_validator
)
first_name = colander.SchemaNode(
colander.String()

12
ordr2/schemas/helpers.py

@ -23,6 +23,18 @@ def deferred_csrf_validator(node, kw): @@ -23,6 +23,18 @@ def deferred_csrf_validator(node, kw):
return validate_csrf
@colander.deferred
def deferred_unique_username_validator(node, kw):
''' checks if an username is not registered already '''
def validate_unique_username(node, value):
request = kw.get('request')
user = request.dbsession.query(User).filter_by(user_name=value).first()
if user is not None:
raise colander.Invalid(node, 'User name already registered')
return validate_unique_username
@colander.deferred
def deferred_unique_email_validator(node, kw):
''' checks if an email is not registered already '''

2
ordr2/views/account.py

@ -134,8 +134,6 @@ def registration_form_processing(context, request): @@ -134,8 +134,6 @@ def registration_form_processing(context, request):
'You should really consider using a longer password.',
dismissable=False
)
return HTTPFound(request.resource_path(context, 'registered'))