Changeset 18166 for main/waeup.kofa
- Timestamp:
- 3 Sep 2025, 07:38:18 (15 months ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 12 edited
-
CHANGES.txt (modified) (1 diff)
-
src/waeup/kofa/browser/interfaces.py (modified) (1 diff)
-
src/waeup/kofa/browser/pages.py (modified) (4 diffs)
-
src/waeup/kofa/interfaces.py (modified) (1 diff)
-
src/waeup/kofa/mandates/tests.py (modified) (1 diff)
-
src/waeup/kofa/students/authentication.py (modified) (4 diffs)
-
src/waeup/kofa/students/browser.py (modified) (2 diffs)
-
src/waeup/kofa/students/export.py (modified) (1 diff)
-
src/waeup/kofa/students/interfaces.py (modified) (2 diffs)
-
src/waeup/kofa/students/student.py (modified) (1 diff)
-
src/waeup/kofa/students/tests/test_browser.py (modified) (1 diff)
-
src/waeup/kofa/tests/test_configuration.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r18163 r18166 4 4 1.8.2.dev0 (unreleased) 5 5 ======================= 6 7 * Implement student password expiration feature. 6 8 7 9 * Reject login attempts from invalid sources. -
main/waeup.kofa/trunk/src/waeup/kofa/browser/interfaces.py
r13089 r18166 189 189 ) 190 190 191 class IPWExpired(IKofaObject): 192 """Interface needed for change pasword page after password has expired. 193 194 """ 195 identifier = schema.TextLine( 196 title = _(u'Student Id'), 197 description = _( 198 u'Alternatively you can use your Matriculation or Registration Number.'), 199 required = True, 200 readonly = False, 201 ) 202 203 email = schema.ASCIILine( 204 title = _(u'Email Address'), 205 required = True, 206 constraint=validate_email, 207 ) 208 191 209 class IStudentNavigationBase(IKofaObject): 192 210 """Objects that provide student navigation should -
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r18163 r18166 52 52 IDepartment, ICourse, ICertificate, 53 53 ICertificateCourse, 54 ICaptchaManager, IChangePassword )54 ICaptchaManager, IChangePassword, IPWExpired) 55 55 from waeup.kofa.browser.layout import jsaction, action, UtilityView 56 56 from waeup.kofa.interfaces import MessageFactory as _ … … 466 466 # Display appropriate flash message if credentials are correct 467 467 # but student has been deactivated or a temporary or parents 468 # password has been set .468 # password has been set or password has expired. 469 469 login = self.request.form['form.login'] 470 470 if len(login) == 8 and login in grok.getSite()['students']: … … 487 487 'because your parents have logged in.'), 488 488 type='warning') 489 return 490 # Finally we check if password has expired. 491 if student.password_expired: 492 self.redirect(self.application_url() + '/pwexpired') 489 493 return 490 494 # Now we know that the student is suspended. … … 2956 2960 '%s - %s - %s' % (ob_class, data['identifier'], data['email'])) 2957 2961 return 2962 2963 2964 class PasswordExpiredPage(ChangePasswordRequestPage): 2965 2966 grok.name('pwexpired') 2967 grok.template('pwexpired') 2968 form_fields = grok.AutoFields(IPWExpired) 2969 2970 label = _('Your password has expired!') -
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r17787 r18166 771 771 ) 772 772 773 days_pw = schema.Int( 774 title = _(u'Student password expiration period'), 775 description = _(u'Number of days after a student password becomes ' 776 'invalid. Enter 0 if passwords will never expire.'), 777 default = 0, 778 readonly = False, 779 required = False, 780 ) 781 782 773 783 captcha = schema.Choice( 774 784 title = _(u'Captcha used for public registration pages'), -
main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py
r16550 r18166 133 133 self.assertEqual(redirect_path, '/login?login=K1000000&password=mypwd1') 134 134 self.assertTrue(IUserAccount(student).checkPassword('mypwd1')) 135 # Password update time has been set 136 now = datetime.utcnow() 137 self.assertEqual((now - student.password_updated).seconds, 0) 135 138 # All mandates have been removed. 136 139 self.assertEqual(len(self.app['mandates'].keys()), 0) -
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>' -
main/waeup.kofa/trunk/src/waeup/kofa/tests/test_configuration.py
r17787 r18166 125 125 result = open(self.outfile, 'rb').read() 126 126 self.assertTrue( 127 'acronym,carry_over,current_academic_session, email_admin,'127 'acronym,carry_over,current_academic_session,days_pw,email_admin,' 128 128 'email_subject,export_disabled_message,frontpage,' 129 129 'maintmode_enabled_by,name,name_admin,next_matric_integer,' 130 130 'next_matric_integer_2,next_matric_integer_3,' 131 131 'next_matric_integer_4,smtp_mailer,curr_stud_id\r\n' 132 'WAeUP.Kofa,0,, contact@waeup.org,Kofa Contact,,'132 'WAeUP.Kofa,0,,0,contact@waeup.org,Kofa Contact,,' 133 133 '"<h1>Welcome to WAeUP.Kofa\n<br>' in result 134 134 )
Note: See TracChangeset for help on using the changeset viewer.
