Changeset 9338 for main/waeup.kofa/trunk/src
- Timestamp:
- 15 Oct 2012, 09:56:35 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r9332 r9338 298 298 return 299 299 300 class LoginAsStudentStep1(KofaEditFormPage): 301 """ View to temporarily set a student password. 302 """ 303 grok.context(IStudent) 304 grok.name('loginasstep1') 305 grok.require('waeup.loginAsStudent') 306 grok.template('loginasstep1') 307 pnav = 4 308 309 def label(self): 310 return _(u'Set temporary password for ${a}', 311 mapping = {'a':self.context.display_fullname}) 312 313 @action('Set password now', style='primary') 314 def setPassword(self, *args, **data): 315 kofa_utils = getUtility(IKofaUtils) 316 password = kofa_utils.genPassword() 317 self.context.setTempPassword(self.request.principal.id, password) 318 self.context.writeLogMessage( 319 self, 'temp_password generated: %s' % password) 320 args = {'password':password} 321 self.redirect(self.url(self.context) + 322 '/loginasstep2?%s' % urlencode(args)) 323 return 324 325 class LoginAsStudentStep2(KofaPage): 326 """ View to temporarily login as student with a temporary password. 327 """ 328 grok.context(IStudent) 329 grok.name('loginasstep2') 330 grok.require('waeup.Public') 331 grok.template('loginasstep2') 332 login_button = _('Login now') 333 pnav = 4 334 335 def label(self): 336 return _(u'Login as ${a}', 337 mapping = {'a':self.context.student_id}) 338 339 def update(self, SUBMIT=None, password=None): 340 self.password = password 341 if SUBMIT is not None: 342 self.flash(_('You successfully logged in as student.')) 343 self.redirect(self.url(self.context)) 344 return 345 300 346 class StudentBaseDisplayFormPage(KofaDisplayFormPage): 301 347 """ Page to display student base data -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r9336 r9338 1467 1467 self.assertTrue('The requested form is locked' in self.browser.contents) 1468 1468 1469 def test_login_as_student(self): 1470 # StudentImpersonators can login as student 1471 # Create clearance officer 1472 self.app['users'].addUser('mrofficer', 'mrofficersecret') 1473 self.app['users']['mrofficer'].email = 'mrofficer@foo.ng' 1474 self.app['users']['mrofficer'].title = 'Harry Actor' 1475 prmglobal = IPrincipalRoleManager(self.app) 1476 prmglobal.assignRoleToPrincipal('waeup.StudentImpersonator', 'mrofficer') 1477 prmglobal.assignRoleToPrincipal('waeup.StudentsManager', 'mrofficer') 1478 # Login as student impersonator 1479 self.browser.open(self.login_path) 1480 self.browser.getControl(name="form.login").value = 'mrofficer' 1481 self.browser.getControl(name="form.password").value = 'mrofficersecret' 1482 self.browser.getControl("Login").click() 1483 self.assertMatches('...You logged in...', self.browser.contents) 1484 self.browser.open(self.student_path) 1485 self.browser.getLink("Login as").click() 1486 self.browser.getControl("Set password now").click() 1487 temp_password = self.browser.getControl(name='form.password').value 1488 self.browser.getControl("Login now").click() 1489 self.assertMatches( 1490 '...You successfully logged in as...', self.browser.contents) 1491 # We are logged in as student and can see the 'My Data' tab 1492 self.assertMatches( 1493 '...<a href="#" class="dropdown-toggle">My Data</a>...', 1494 self.browser.contents) 1495 self.browser.getLink("Logout").click() 1496 # The student can't login with the original password ... 1497 self.browser.open(self.login_path) 1498 self.browser.getControl(name="form.login").value = self.student_id 1499 self.browser.getControl(name="form.password").value = 'spwd' 1500 self.browser.getControl("Login").click() 1501 self.assertMatches( 1502 '...Your account has been temporarily deactivated...', 1503 self.browser.contents) 1504 # ... but with the temporary password 1505 self.browser.open(self.login_path) 1506 self.browser.getControl(name="form.login").value = self.student_id 1507 self.browser.getControl(name="form.password").value = temp_password 1508 self.browser.getControl("Login").click() 1509 self.assertMatches('...You logged in...', self.browser.contents) 1510 # Creation of temp_password is properly logged 1511 logfile = os.path.join( 1512 self.app['datacenter'].storage, 'logs', 'students.log') 1513 logcontent = open(logfile).read() 1514 self.assertTrue( 1515 'mrofficer - students.browser.LoginAsStudentStep1 - K1000000 - ' 1516 'temp_password generated: %s' % temp_password in logcontent) 1517 1469 1518 class StudentUITests(StudentsFullSetup): 1470 1519 # Tests for Student class views and pages -
main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py
r9273 r9338 175 175 target = 'trigtrans' 176 176 177 class StudentLoginAsActionButton(ManageActionButton): 178 grok.order(3) 179 grok.context(IStudent) 180 grok.view(StudentBaseDisplayFormPage) 181 grok.require('waeup.loginAsStudent') 182 icon = 'actionicon_mask.png' 183 text = _(u'Login as student') 184 target = 'loginasstep1' 185 177 186 class AdmissionSlipActionButton(ManageActionButton): 178 187 grok.order(4)
Note: See TracChangeset for help on using the changeset viewer.