Changeset 18166 for main/waeup.kofa/trunk/src/waeup/kofa/students
- Timestamp:
- 3 Sep 2025, 07:38:18 (15 months ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 6 edited
-
authentication.py (modified) (4 diffs)
-
browser.py (modified) (2 diffs)
-
export.py (modified) (1 diff)
-
interfaces.py (modified) (2 diffs)
-
student.py (modified) (1 diff)
-
tests/test_browser.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/authentication.py
r15606 r18166 20 20 """ 21 21 import grok 22 importtime22 from datetime import datetime 23 23 from zope.component import getUtility 24 24 from zope.password.interfaces import IPasswordManager … … 109 109 passwordmanager = getUtility(IPasswordManager, 'SSHA') 110 110 self.context.password = passwordmanager.encodePassword(password) 111 self.context.password_updated = datetime.utcnow() 111 112 112 113 def checkPassword(self, password): … … 114 115 students, the temporary password was set by officers or 115 116 the parents_password was set by parents. 116 We additionally check if student account has been suspended 117 or if the portal is blocked.117 We additionally check if student account has been suspended, 118 if the portal is blocked or the password has expired. 118 119 """ 119 120 try: … … 137 138 if self.context.suspended == True: 138 139 return False 140 if self.context.password_expired: 141 return False 139 142 return passwordmanager.checkPassword(self.context.password, password) 140 143 -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r18153 r18166 481 481 form_fields = grok.AutoFields(IStudentBase).omit( 482 482 'password', 'suspended', 'suspended_comment', 'flash_notice') 483 form_fields[ 484 'password_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') 483 485 pnav = 4 484 486 … … 656 658 grok.require('waeup.manageStudent') 657 659 form_fields = grok.AutoFields(IStudentBase).omit( 658 'student_id', 'adm_code', 'suspended' )660 'student_id', 'adm_code', 'suspended', 'password_updated') 659 661 grok.template('basemanagepage') 660 662 label = _('Manage base data') -
main/waeup.kofa/trunk/src/waeup/kofa/students/export.py
r17641 r18166 354 354 grok.name('students') 355 355 356 fields = tuple(sorted(iface_names(IStudent ))) + (356 fields = tuple(sorted(iface_names(IStudent, omit=['password_updated']))) + ( 357 357 'password', 'state', 'history', 'certcode', 'is_postgrad', 358 358 'current_level', 'current_session', 'entry_session') -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r17245 r18166 238 238 temp_password = Attribute('Dictionary with user name, timestamp and encrypted password') 239 239 parents_password = Attribute('Dictionary with student_id, timestamp and encrypted password') 240 password_expired = Attribute('Can be used to force students to request a new password') 240 241 241 242 suspended = schema.Bool( … … 322 323 required = False, 323 324 constraint=validate_email, 325 ) 326 327 password_updated = schema.Datetime( 328 title = _(u'Password updated'), 329 required = False, 330 readonly = False, 324 331 ) 325 332 -
main/waeup.kofa/trunk/src/waeup/kofa/students/student.py
r17769 r18166 143 143 self.student_id, granted=True)) 144 144 return None 145 146 @property 147 def password_expired(self): 148 """Can be used to force students to request a new password. 149 """ 150 try: 151 days_pw = grok.getSite()['configuration'].days_pw 152 except TypeError: # in unit tests 153 return False 154 if not days_pw: 155 return False 156 now = datetime.utcnow() 157 if self.password_updated is None: 158 return True 159 try: 160 days_ago = getattr(now - self.password_updated, 'days') 161 except TypeError: 162 # This happens after reimport of personal_updated because 163 # Python can't subtract offset-naive and offset-aware datetimes 164 return True 165 if days_ago > days_pw: 166 return True 167 return False 145 168 146 169 def writeLogMessage(self, view, message): -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r18001 r18166 2761 2761 return 2762 2762 2763 def test_student_password_expired(self): 2764 # Password update time has been set 2765 now = datetime.utcnow() 2766 self.assertEqual((now - self.student.password_updated).days, 0) 2767 # Set expiration days 2768 config = grok.getSite()['configuration'] 2769 config.days_pw = 1 2770 # Student can login 2771 self.student.personal_updated = datetime.utcnow() 2772 self.browser.open(self.login_path) 2773 self.browser.getControl(name="form.login").value = self.student_id 2774 self.browser.getControl(name="form.password").value = 'spwd' 2775 self.browser.getControl("Login").click() 2776 self.assertEqual(self.browser.url, self.student_path) 2777 self.assertTrue('You logged in' in self.browser.contents) 2778 self.browser.getLink("Logout").click() 2779 # Student is requested to change password when old password expires 2780 delta = timedelta(days=3) 2781 self.student.password_updated = datetime.utcnow() - delta 2782 self.assertEqual((now - self.student.password_updated).days, 2) 2783 self.browser.open(self.login_path) 2784 self.browser.getControl(name="form.login").value = self.student_id 2785 self.browser.getControl(name="form.password").value = 'spwd' 2786 self.browser.getControl("Login").click() 2787 self.assertEqual(self.browser.url, 'http://localhost/app/pwexpired') 2788 self.assertTrue( 2789 'Your password has expired' in self.browser.contents) 2790 self.assertRaises( 2791 Unauthorized, self.browser.open, self.student_path) 2792 return 2793 2763 2794 def test_forbidden_name(self): 2764 2795 self.student.lastname = u'<TAG>Tester</TAG>'
Note: See TracChangeset for help on using the changeset viewer.
