Changeset 6699
- Timestamp:
- 9 Sep 2011, 15:51:56 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/students
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r6696 r6699 70 70 from waeup.sirp.students.student import Student 71 71 from waeup.sirp.students.catalog import search 72 from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code 73 from waeup.sirp.accesscodes.workflow import USED 72 74 73 75 class StudentsTab(PrimaryNavTab): … … 142 144 return 143 145 146 class SetPassword(WAeUPPage): 147 grok.context(IWAeUPObject) 148 grok.name('setpassword') 149 grok.require('waeup.Public') 150 title = '' 151 label = 'Set password for first-time login' 152 acprefix = 'PWD' 153 pnav = 4 154 155 def update(self, SUBMIT=None): 156 self.reg_number = self.request.form.get('form.reg_number', None) 157 # We must not use form.ac_series and form.ac_number in forms since these 158 # are interpreted by applicant credentials 159 self.acseries = self.request.form.get('form.acseries', None) 160 self.acnumber = self.request.form.get('form.acnumber', None) 161 162 if SUBMIT is None: 163 return 164 hitlist = search(query=self.reg_number, 165 searchtype='reg_number', view=self) 166 if not hitlist: 167 self.flash('No student found.') 168 return 169 if len(hitlist) != 1: # Cannot happen but anyway 170 self.flash('More than one student found.') 171 return 172 self.student_id = hitlist[0].student_id 173 student_pw = hitlist[0].context.password 174 if student_pw: 175 self.flash('Password has already been set. Please request a password reset.') 176 return 177 pin = '%s-%s-%s' % (self.acprefix,self.acseries,self.acnumber) 178 code = get_access_code(pin) 179 if not code: 180 self.flash('Access code is invalid.') 181 return 182 # Mark pin as used (this also fires a pin related transition) 183 # and set student password 184 if code.state == USED: 185 self.flash('Access code has already been used.') 186 return 187 else: 188 comment = u"AC invalidated" 189 # Here we know that the ac is in state initialized so we do not 190 # expect an exception 191 #import pdb; pdb.set_trace() 192 invalidate_accesscode(pin,comment) 193 IUserAccount(hitlist[0].context).setPassword(self.acnumber) 194 return 195 144 196 class StudentsContainerManageActionButton(ManageActionButton): 145 197 grok.order(1) … … 234 286 grok.require('waeup.viewStudent') 235 287 grok.template('basepage') 236 form_fields = grok.AutoFields(IStudentBase) .omit('password')288 form_fields = grok.AutoFields(IStudentBase) #.omit('password') 237 289 pnav = 4 238 290 title = 'Base Data' … … 241 293 def label(self): 242 294 return '%s: Base Data' % self.context.name 295 296 @property 297 def hasPassword(self): 298 if self.context.password: 299 return 'set' 300 return 'unset' 243 301 244 302 class StudentBaseManageActionButton(ManageActionButton): … … 289 347 transition_id = form['transition'] 290 348 self.wf_info.fireTransition(transition_id) 349 if form.has_key('password') and form['password']: 350 IUserAccount(self.context).setPassword(form['password']) 351 if fields_string: 352 fields_string += ' + password' 353 else: 354 fields_string = 'password' 291 355 self.flash('Form has been saved.') 292 356 ob_class = self.__implemented__.__name__.replace('waeup.sirp.','') 293 357 if fields_string: 294 358 self.context.loggerInfo(ob_class, 'saved: % s' % fields_string) 295 if 'password' in fields_string:296 IUserAccount(self.context).setPassword(form['form.password'])297 359 return 298 360 … … 496 558 fields_string = '+'.join(' + '.join(str(i) for i in b) for b in changed_fields) 497 559 self.context._p_changed = True 560 form = self.request.form 561 if form.has_key('password') and form['password']: 562 IUserAccount(self.context).setPassword(form['password']) 563 if fields_string: 564 fields_string += ' + password' 565 else: 566 fields_string = 'password' 498 567 self.flash('Form has been saved.') 499 form = self.request.form500 568 ob_class = self.__implemented__.__name__.replace('waeup.sirp.','') 501 569 if fields_string: 502 570 self.context.loggerInfo(ob_class, 'saved: % s' % fields_string) 503 if 'password' in fields_string:504 IUserAccount(self.context).setPassword(form['form.password'])505 571 return 506 572 -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/baseeditpage.pt
r6695 r6699 38 38 </tr> 39 39 </tal:block> 40 <tr> 41 <td class="label"><label>Password:</label></td> 42 <td> 43 <input name="password" type="password" tal:attributes="value view/context/password" /> 44 </td> 45 </tr> 40 46 </tbody> 41 47 </table> -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/basemanagepage.pt
r6695 r6699 39 39 </tal:block> 40 40 <tr> 41 <td class="label"><label>Password:</label></td> 42 <td> 43 <input name="password" type="password" tal:attributes="value view/context/password" /> 44 </td> 45 </tr> 46 <tr> 41 47 <td class="label"><label>Registration Transition:</label></td> 42 48 <td> -
main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py
r6696 r6699 62 62 state = Attribute('Returns the registration state of a student') 63 63 #student_id = Attribute('Randomly generated id') 64 password = Attribute('Encrypted password of a student') 64 65 65 66 def loggerInfo(ob_class, comment): … … 76 77 default = u'Nobody', 77 78 required = True, 78 )79 80 password = schema.Password(81 title = u'Password',82 required = False,83 79 ) 84 80 … … 152 148 ) 153 149 154 password = schema.Password(155 title = u'Password',156 required = True,157 )158 159 150 IStudentBaseEdit['name'].order = IStudentBase['name'].order 160 151 -
main/waeup.sirp/trunk/src/waeup/sirp/students/student.py
r6695 r6699 45 45 except ComponentLookupError: 46 46 self.student_id = u'Z654321' 47 self.password = None 47 48 return 48 49 -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r6695 r6699 205 205 self.browser.getControl(name="transition").value = ['admit'] 206 206 self.browser.getControl(name="form.name").value = 'John Tester' 207 self.browser.getControl(name="form.password").value = 'secret' 207 self.browser.getControl(name="form.reg_number").value = '123' 208 self.browser.getControl(name="password").value = 'secret' 208 209 self.browser.getControl("Save").click() 209 self.assertTrue('Form has been saved' in self.browser.contents) 210 self.assertMatches('...Form has been saved...', 211 self.browser.contents) 212 #self.assertTrue('Form has been saved' in self.browser.contents) 210 213 211 214 self.browser.open(self.student_path) … … 262 265 # Change password 263 266 self.browser.getLink("Change password").click() 264 self.browser.getControl(name=" form.password").value = 'new_password'267 self.browser.getControl(name="password").value = 'new_password' 265 268 self.browser.getControl("Save").click() 266 269 self.assertTrue('Form has been saved' in self.browser.contents) … … 276 279 self.browser.open(self.login_path) 277 280 self.browser.getControl(name="form.login").value = self.test_student_id 278 self.browser.getControl(name=" form.password").value = 'new_password'281 self.browser.getControl(name="password").value = 'new_password' 279 282 self.browser.getControl("Login").click() 280 283 self.assertEqual(self.browser.url, self.student_path)
Note: See TracChangeset for help on using the changeset viewer.