- Timestamp:
- 30 Jun 2012, 07:03:20 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r8853 r8857 2125 2125 kofa_utils = getUtility(IKofaUtils) 2126 2126 pwd = kofa_utils.genPassword() 2127 2128 ###: To be changed 2127 2129 IUserAccount(user).setPassword(pwd) 2128 # Send email with new redentials 2130 2131 2132 # Send email with new credentials 2129 2133 msg = _('You have successfully changed your password for the') 2130 2134 login_url = self.url(grok.getSite(), 'login') -
main/waeup.kofa/trunk/src/waeup/kofa/mandates/mandate.py
r8853 r8857 50 50 return _('Nothing to do.') 51 51 52 class StudentPasswordMandate(Mandate):52 class PasswordMandate(Mandate): 53 53 """This is a mandate which can set a student password. 54 54 """ 55 55 56 def _set StudentPassword(self):57 student_id = self.params.get('student_id', None)56 def _setPassword(self): 57 user_id = self.params.get('user_id', None) 58 58 pwd = self.params.get('password', None) 59 student = grok.getSite()['students'].get(student_id, None) 60 if student and pwd: 61 IUserAccount(student).setPassword(pwd) 59 user_type = self.params.get('user_type', None) 60 user = None 61 if user_type == 'student': 62 user = grok.getSite()['students'].get(user_id, None) 63 elif user_type == 'officer': 64 user = grok.getSite()['users'].get(user_id, None) 65 if user and pwd: 66 IUserAccount(user).setPassword(pwd) 62 67 return True 63 68 return False … … 67 72 if self.expires < datetime.utcnow(): 68 73 msg = _('Mandate expired.') 69 if self._set StudentPassword():74 if self._setPassword(): 70 75 msg = _('Password has been successfully set. ' 71 76 'Proceed to the login page and enter your credentials.') -
main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py
r8853 r8857 31 31 IMandatesContainer, IMandate) 32 32 from waeup.kofa.mandates.container import MandatesContainer 33 from waeup.kofa.mandates.mandate import StudentPasswordMandate33 from waeup.kofa.mandates.mandate import PasswordMandate 34 34 from waeup.kofa.testing import (FunctionalLayer, FunctionalTestCase) 35 35 … … 50 50 self.assertTrue( 51 51 verifyClass( 52 IMandate, StudentPasswordMandate)52 IMandate, PasswordMandate) 53 53 ) 54 54 self.assertTrue( 55 55 verifyObject( 56 IMandate, StudentPasswordMandate())56 IMandate, PasswordMandate()) 57 57 ) 58 58 return … … 84 84 shutil.rmtree(self.dc_root) 85 85 86 def test_set_ password(self):86 def test_set_student_password(self): 87 87 student = createObject('waeup.Student') 88 88 self.app['students'].addStudent(student) 89 89 # Add and execute a mandate with missing parameters. 90 mandate = StudentPasswordMandate()90 mandate = PasswordMandate() 91 91 self.app['mandates'].addMandate(mandate) 92 92 msg = mandate.execute() 93 93 self.assertEqual(msg, u'Wrong mandate parameters.') 94 94 # Add and execute an expired mandate. 95 mandate = StudentPasswordMandate(days=0)95 mandate = PasswordMandate(days=0) 96 96 self.app['mandates'].addMandate(mandate) 97 97 msg = mandate.execute() 98 98 self.assertEqual(msg, u'Mandate expired.') 99 99 # Add and execute a perfect mandate 100 mandate = StudentPasswordMandate()101 mandate.params[' student_id'] = student.student_id100 mandate = PasswordMandate() 101 mandate.params['user_id'] = student.student_id 102 102 mandate.params['password'] = 'mypwd1' 103 mandate.params['user_type'] = 'student' 103 104 self.app['mandates'].addMandate(mandate) 104 105 msg = mandate.execute() … … 110 111 self.assertEqual(len(self.app['mandates'].keys()), 0) 111 112 113 def test_set_officer_password(self): 114 self.app['users'].addUser('bob', 'bobssecret') 115 officer = self.app['users']['bob'] 116 mandate = PasswordMandate() 117 mandate.params['user_id'] = 'bob' 118 mandate.params['password'] = 'mypwd1' 119 mandate.params['user_type'] = 'officer' 120 self.app['mandates'].addMandate(mandate) 121 msg = mandate.execute() 122 # Password has been set. 123 self.assertEqual(msg, 'Password has been successfully set. Proceed to ' 124 'the login page and enter your credentials.') 125 self.assertTrue(IUserAccount(officer).checkPassword('mypwd1')) 126 112 127 def test_remove_expired(self): 113 128 # mandate1 is an old mandate which just expired. 114 mandate1 = StudentPasswordMandate(days=0)129 mandate1 = PasswordMandate(days=0) 115 130 self.app['mandates'].addMandate(mandate1) 116 131 # mandate2 is a new mandate with default time delta. 117 mandate2 = StudentPasswordMandate(mandate_id='23456')132 mandate2 = PasswordMandate(mandate_id='23456') 118 133 self.app['mandates'].addMandate(mandate2) 119 134 self.assertEqual(len(self.app['mandates'].keys()), 2) … … 126 141 student = createObject('waeup.Student') 127 142 self.app['students'].addStudent(student) 128 mandate = StudentPasswordMandate() 129 mandate.params['student_id'] = student.student_id 143 mandate = PasswordMandate() 144 mandate.params['user_id'] = student.student_id 145 mandate.params['user_type'] = 'student' 130 146 mandate.params['password'] = 'mypwd1' 131 147 self.app['mandates'].addMandate(mandate) -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r8856 r8857 64 64 from waeup.kofa.hostels.hostel import NOT_OCCUPIED 65 65 from waeup.kofa.utils.helpers import get_current_principal, to_timezone 66 from waeup.kofa.mandates.mandate import StudentPasswordMandate66 from waeup.kofa.mandates.mandate import PasswordMandate 67 67 68 68 grok.context(IKofaObject) # Make IKofaObject the default context … … 1987 1987 kofa_utils = getUtility(IKofaUtils) 1988 1988 password = kofa_utils.genPassword() 1989 mandate = StudentPasswordMandate()1989 mandate = PasswordMandate() 1990 1990 mandate.params['password'] = password 1991 1991 mandate.params['student_id'] = student.student_id 1992 mandate.params['user_type'] = 'student' 1992 1993 site = grok.getSite() 1993 1994 site['mandates'].addMandate(mandate)
Note: See TracChangeset for help on using the changeset viewer.