Marcin Kuzminski avatar Marcin Kuzminski committed 019026a

implements #237 added password confirmation for my account and admin edit user.

Comments (0)

Files changed (6)

rhodecode/model/forms.py

 class ValidPasswordsMatch(formencode.validators.FancyValidator):
 
     def validate_python(self, value, state):
-
-        if value['password'] != value['password_confirmation']:
+        
+        pass_val = value.get('password') or value.get('new_password')
+        if pass_val != value['password_confirmation']:
             e_dict = {'password_confirmation':
                    _('Passwords do not match')}
             raise formencode.Invalid('', value, state, error_dict=e_dict)
                                 'tooShort':_('Enter %(min)i characters or more')}
                                 )
 
-
-    #chained validators have access to all data
     chained_validators = [ValidAuth]
 
 def UserForm(edit=False, old_data={}):
                        ValidUsername(edit, old_data))
         if edit:
             new_password = All(UnicodeString(strip=True, min=6, not_empty=False))
+            password_confirmation = 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))
+            password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=False))
+            
         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]
+        chained_validators = [ValidPasswordsMatch, ValidPassword]
 
     return _UserForm
 

rhodecode/templates/admin/users/user_add.html

                     ${h.password('password',class_='small')}
                 </div>
              </div>
-            
+             
+             <div class="field">
+                <div class="label">
+                    <label for="password_confirmation">${_('Password confirmation')}:</label>
+                </div>
+                <div class="input">
+                    ${h.password('password_confirmation',class_="small",autocomplete="off")}
+                </div>
+             </div>    
+                         
              <div class="field">
                 <div class="label">
                     <label for="name">${_('First Name')}:</label>

rhodecode/templates/admin/users/user_edit.html

                     ${h.password('new_password',class_='medium',autocomplete="off")}
                 </div>
              </div>
-            
+             
+             <div class="field">
+                <div class="label">
+                    <label for="password_confirmation">${_('New password confirmation')}:</label>
+                </div>
+                <div class="input">
+                    ${h.password('password_confirmation',class_="medium",autocomplete="off")}
+                </div>
+             </div>
+                         
              <div class="field">
                 <div class="label">
                     <label for="name">${_('First Name')}:</label>

rhodecode/templates/admin/users/user_edit_my_account.html

 	                    ${h.password('new_password',class_="medium",autocomplete="off")}
 	                </div>
 	             </div>
-	            
+                 
+                 <div class="field">
+                    <div class="label">
+                        <label for="password_confirmation">${_('New password confirmation')}:</label>
+                    </div>
+                    <div class="input">
+                        ${h.password('password_confirmation',class_="medium",autocomplete="off")}
+                    </div>
+                 </div>
+                 	            
 	             <div class="field">
 	                <div class="label">
 	                    <label for="name">${_('First Name')}:</label>
 		        </tr>
 		     %endfor
 	     %else:
+            <div style="padding:5px 0px 10px 0px;">
 	     	${_('No repositories yet')} 
 	     	%if h.HasPermissionAny('hg.admin','hg.create.repository')():
-	     		${h.link_to(_('create one now'),h.url('admin_settings_create_repository'))}
+	     		${h.link_to(_('create one now'),h.url('admin_settings_create_repository'),class_="ui-button-small")}
 	     	%endif
+            </div>
 	     %endif
 	     </tbody>
 	     </table>

rhodecode/tests/functional/test_admin_settings.py

                                  params=dict(_method='put',
                                              username='test_admin',
                                              new_password=new_password,
+                                             password_confirmation = new_password,
                                              password='',
                                              name=new_name,
                                              lastname=new_lastname,
                                                             _method='put',
                                                             username='test_admin',
                                                             new_password=old_password,
+                                                            password_confirmation = old_password,
                                                             password='',
                                                             name=old_name,
                                                             lastname=old_lastname,
                                                             _method='put',
                                                             username='test_admin',
                                                             new_password='test12',
+                                                            password_confirmation = 'test122',
                                                             name='NewName',
                                                             lastname='NewLastname',
                                                             email=new_email,))
                                                             _method='put',
                                                             username='test_admin',
                                                             new_password='test12',
+                                                            password_confirmation = 'test122',
                                                             name='NewName',
                                                             lastname='NewLastname',
                                                             email=new_email,))

rhodecode/tests/functional/test_admin_users.py

         self.log_user()
         username = 'newtestuser'
         password = 'test12'
+        password_confirmation = password
         name = 'name'
         lastname = 'lastname'
         email = 'mail@mail.com'
 
         response = self.app.post(url('users'), {'username':username,
                                                'password':password,
+                                               'password_confirmation':password_confirmation,
                                                'name':name,
                                                'active':True,
                                                'lastname':lastname,
 
         response = self.app.post(url('users'), {'username':username,
                                                'password':password,
+                                               'password_confirmation':password,
                                                'name':name,
                                                'active':True,
                                                'lastname':lastname,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.