Changeset - 9dd38344c466
[Not reviewed]
celery
0 1 0
Marcin Kuzminski - 15 years ago 2010-09-13 01:38:14
marcin@python-works.com
Added validation for uniq email address
1 file changed with 14 insertions and 1 deletions:
0 comments (0 inline, 0 general)
pylons_app/model/forms.py
Show inline comments
 
@@ -206,12 +206,25 @@ class ValidPath(formencode.validators.Fa
 
        else:
 
            msg = _('You need to specify * or ** at the end of path (ie. /tmp/*)')
 
        
 
        raise formencode.Invalid(msg, value, state,
 
                                     error_dict={'paths_root_path':msg})            
 

	
 
class UniqSystemEmail(formencode.validators.FancyValidator):
 
    def to_python(self, value, state):
 
        sa = meta.Session
 
        try:
 
            user = sa.query(User).filter(User.email == value).scalar()
 
            if user:
 
                raise formencode.Invalid(_("That e-mail address is already taken") ,
 
                                         value, state)
 
        finally:
 
            meta.Session.remove()
 
            
 
        return value 
 
    
 
class ValidSystemEmail(formencode.validators.FancyValidator):
 
    def to_python(self, value, state):
 
        sa = meta.Session
 
        try:
 
            user = sa.query(User).filter(User.email == value).scalar()
 
            if  user is None:
 
@@ -260,13 +273,13 @@ def UserForm(edit=False, old_data={}):
 
            admin = StringBoolean(if_missing=False)
 
        else:
 
            password = All(UnicodeString(strip=True, min=8, not_empty=True), ValidPassword)
 
        active = StringBoolean(if_missing=False)
 
        name = UnicodeString(strip=True, min=3, not_empty=True)
 
        lastname = UnicodeString(strip=True, min=3, not_empty=True)
 
        email = Email(not_empty=True)
 
        email = All(Email(not_empty=True), UniqSystemEmail())
 
        
 
    return _UserForm
 

	
 
RegisterForm = UserForm
 

	
 
def PasswordResetForm():
0 comments (0 inline, 0 general)