changeset 722:02bdf2f296ff beta

fixes #69 password confirmation for register dialog. Fixes appcrash when using some special characters in register field fixes app crash when no email config is enabled
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 18 Nov 2010 23:07:04 +0100
parents 74975001a1af
children bf26b46e82d6
files rhodecode/lib/celerylib/tasks.py rhodecode/model/forms.py rhodecode/public/css/style.css rhodecode/templates/register.html
diffstat 4 files changed, 67 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/celerylib/tasks.py	Thu Nov 18 21:04:40 2010 +0100
+++ b/rhodecode/lib/celerylib/tasks.py	Thu Nov 18 23:07:04 2010 +0100
@@ -255,7 +255,7 @@
         recipients = [email_config.get('email_to')]
 
     def str2bool(v):
-        return v.lower() in ["yes", "true", "t", "1"]
+        return v.lower() in ["yes", "true", "t", "1"] if v else None
 
     mail_from = email_config.get('app_email_from')
     user = email_config.get('smtp_username')
--- a/rhodecode/model/forms.py	Thu Nov 18 21:04:40 2010 +0100
+++ b/rhodecode/model/forms.py	Thu Nov 18 23:07:04 2010 +0100
@@ -76,8 +76,34 @@
 class ValidPassword(formencode.validators.FancyValidator):
 
     def to_python(self, value, state):
+
         if value:
-            return get_crypt_password(value)
+
+            if value.get('password'):
+                try:
+                    value['password'] = get_crypt_password(value['password'])
+                except UnicodeEncodeError:
+                    e_dict = {'password':_('Invalid characters in password')}
+                    raise formencode.Invalid('', value, state, error_dict=e_dict)
+
+            if value.get('password_confirmation'):
+                try:
+                    value['password_confirmation'] = \
+                        get_crypt_password(value['password_confirmation'])
+                except UnicodeEncodeError:
+                    e_dict = {'password_confirmation':_('Invalid characters in password')}
+                    raise formencode.Invalid('', value, state, error_dict=e_dict)
+
+            return value
+
+class ValidPasswordsMatch(formencode.validators.FancyValidator):
+
+    def validate_python(self, value, state):
+
+        if value['password'] != value['password_confirmation']:
+            e_dict = {'password_confirmation':
+                   _('Password do not match')}
+            raise formencode.Invalid('', value, state, error_dict=e_dict)
 
 class ValidAuth(formencode.validators.FancyValidator):
     messages = {
@@ -281,18 +307,34 @@
         filter_extra_fields = True
         username = All(UnicodeString(strip=True, min=1, not_empty=True), ValidUsername(edit, old_data))
         if edit:
-            new_password = All(UnicodeString(strip=True, min=6, not_empty=False), ValidPassword)
+            new_password = All(UnicodeString(strip=True, min=6, not_empty=False))
             admin = StringBoolean(if_missing=False)
         else:
-            password = All(UnicodeString(strip=True, min=6, not_empty=True), ValidPassword)
+            password = All(UnicodeString(strip=True, min=6, not_empty=True))
         active = StringBoolean(if_missing=False)
         name = UnicodeString(strip=True, min=1, not_empty=True)
         lastname = UnicodeString(strip=True, min=1, not_empty=True)
         email = All(Email(not_empty=True), UniqSystemEmail(old_data))
 
+        chained_validators = [ValidPassword]
+
     return _UserForm
 
-RegisterForm = UserForm
+def RegisterForm(edit=False, old_data={}):
+    class _RegisterForm(formencode.Schema):
+        allow_extra_fields = True
+        filter_extra_fields = True
+        username = All(ValidUsername(edit, old_data), UnicodeString(strip=True, min=1, not_empty=True))
+        password = All(UnicodeString(strip=True, min=6, not_empty=True))
+        password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=True))
+        active = StringBoolean(if_missing=False)
+        name = UnicodeString(strip=True, min=1, not_empty=True)
+        lastname = UnicodeString(strip=True, min=1, not_empty=True)
+        email = All(Email(not_empty=True), UniqSystemEmail(old_data))
+
+        chained_validators = [ValidPasswordsMatch, ValidPassword]
+
+    return _RegisterForm
 
 def PasswordResetForm():
     class _PasswordResetForm(formencode.Schema):
--- a/rhodecode/public/css/style.css	Thu Nov 18 21:04:40 2010 +0100
+++ b/rhodecode/public/css/style.css	Thu Nov 18 23:07:04 2010 +0100
@@ -1327,7 +1327,6 @@
 }
 
 #register div.title {
-width:420px;
 clear:both;
 overflow:hidden;
 position:relative;
@@ -1337,7 +1336,6 @@
 }
 
 #register div.inner {
-width:380px;
 background:#FFF;
 border-top:none;
 border-bottom:none;
@@ -1346,7 +1344,7 @@
 }
 
 #register div.form div.fields div.field div.label {
-width:100px;
+width:135px;
 float:left;
 text-align:right;
 margin:2px 10px 0 0;
@@ -1354,7 +1352,7 @@
 }
 
 #register div.form div.fields div.field div.input input {
-width:245px;
+width:300px;
 background:#FFF;
 border-top:1px solid #b3b3b3;
 border-left:1px solid #b3b3b3;
@@ -2235,7 +2233,7 @@
 }
 
 #login,#register {
-width:420px;
+width:520px;
 margin:10% auto 0;
 padding:0;
 }
--- a/rhodecode/templates/register.html	Thu Nov 18 21:04:40 2010 +0100
+++ b/rhodecode/templates/register.html	Thu Nov 18 23:07:04 2010 +0100
@@ -15,7 +15,7 @@
 		<div id="register">
 			
 			<div class="title top-left-rounded-corner top-right-rounded-corner">
-				<h5>${_('Sign Up to rhodecode')}</h5>
+				<h5>${_('Sign Up to RhodeCode')}</h5>
 			</div>
 			<div class="inner">
 			    ${h.form(url('register'))}
@@ -27,25 +27,34 @@
 			                    <label for="username">${_('Username')}:</label>
 			                </div>
 			                <div class="input">
-			                    ${h.text('username')}
+			                    ${h.text('username',class_="medium")}
 			                </div>
 			             </div>
 			            
 			             <div class="field">
 			                <div class="label">
-			                    <label for="password">${_('New Password')}:</label>
+			                    <label for="password">${_('Password')}:</label>
 			                </div>
 			                <div class="input">
-			                    ${h.password('password')}
+			                    ${h.password('password',class_="medium")}
 			                </div>
 			             </div>
-			            
+                         
+                         <div class="field">
+                            <div class="label">
+                                <label for="password">${_('Re-enter password')}:</label>
+                            </div>
+                            <div class="input">
+                                ${h.password('password_confirmation',class_="medium")}
+                            </div>
+                         </div>
+                         			            
 			             <div class="field">
 			                <div class="label">
 			                    <label for="name">${_('First Name')}:</label>
 			                </div>
 			                <div class="input">
-			                    ${h.text('name')}
+			                    ${h.text('name',class_="medium")}
 			                </div>
 			             </div>
 			            
@@ -54,7 +63,7 @@
 			                    <label for="lastname">${_('Last Name')}:</label>
 			                </div>
 			                <div class="input">
-			                    ${h.text('lastname')}
+			                    ${h.text('lastname',class_="medium")}
 			                </div>
 			             </div>
 			            
@@ -63,7 +72,7 @@
 			                    <label for="email">${_('Email')}:</label>
 			                </div>
 			                <div class="input">
-			                    ${h.text('email')}
+			                    ${h.text('email',class_="medium")}
 			                </div>
 			             </div>