Changeset 7144 for main/waeup.sirp/trunk/src/waeup/sirp
- Timestamp:
- 19 Nov 2011, 17:26:18 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/students
- Files:
-
- 1 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/authentication.py
r7142 r7144 215 215 loginpagename = 'login' 216 216 loginfield = 'student_id' 217 passwordfield = ' form.password'218 repeatfield = ' form.password_repeat'217 passwordfield = 'change_password' 218 repeatfield = 'change_password_repeat' 219 219 220 220 def extractCredentials(self, request): -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7141 r7144 40 40 from waeup.sirp.university.vocabularies import study_modes 41 41 from waeup.sirp.students.interfaces import ( 42 IStudentsContainer, IStudent, IStudentClearance, IStudentPasswordSetting,42 IStudentsContainer, IStudent, IStudentClearance, 43 43 IStudentPersonal, IStudentBase, IStudentStudyCourse, 44 44 IStudentAccommodation, IStudentClearanceEdit, IStudentStudyLevel, … … 52 52 from waeup.sirp.students.vocabularies import StudyLevelSource 53 53 from waeup.sirp.students.utils import ( 54 getPaymentDetails, getAccommodationDetails, selectBed, renderPDF) 54 getPaymentDetails, getAccommodationDetails, selectBed, 55 renderPDF, validatePassword) 55 56 from waeup.sirp.browser.resources import toggleall 56 57 from waeup.sirp.authentication import get_principal_role_manager … … 1496 1497 form_fields = grok.AutoFields(IStudentBase).select( 1497 1498 'email', 'phone') 1498 #grok.template('basemanagepage')1499 1499 label = 'Edit base data' 1500 1500 title = 'Base Data' … … 1506 1506 return 1507 1507 1508 class StudentPasswordSetting(grok.Adapter): 1509 """Adapt IStudent to data needed for password settings. 1510 1511 We provide password getters/setters for the attached context (an 1512 IStudent object) that cooperate seamless with the usual 1513 formlib/form techniques. 1514 """ 1515 grok.context(IStudent) 1516 grok.provides(IStudentPasswordSetting) 1517 1518 def __init__(self, context): 1519 self.name = context.fullname 1520 self.password_repeat = context.password 1521 self.context = context 1522 return 1523 1524 def getPassword(self): 1525 return self.context.password 1526 1527 def setPassword(self, password): 1528 IUserAccount(self.context).setPassword(password) 1529 return 1530 1531 password = property(getPassword, setPassword) 1532 1533 class StudentPasswordFormPage(WAeUPEditFormPage): 1534 """ View to edit the password by student 1508 class StudentChangePasswordPage(WAeUPEditFormPage): 1509 """ View to manage student base data 1535 1510 """ 1536 1511 grok.context(IStudent) 1537 1512 grok.name('change_password') 1538 1513 grok.require('waeup.handleStudent') 1539 form_fields = grok.AutoFields(IStudentPasswordSetting) 1540 grok.template('baseeditpage') 1514 grok.template('change_password') 1541 1515 label = 'Change password' 1542 1516 title = 'Base Data' 1543 1517 pnav = 4 1544 1518 1545 def update(self): 1546 super(StudentPasswordFormPage, self).update() 1547 return 1548 1549 def onFailure(self, action, data, errors): 1550 new_status = [] 1551 other_errors = False 1552 for error in errors: 1553 msg = getattr(error, 'message', '') 1554 if isinstance(msg, basestring) and msg != '': 1555 # invariant error 1556 new_status.append(msg) 1519 @grok.action('Save') 1520 def save(self, **data): 1521 form = self.request.form 1522 password = form.get('change_password', None) 1523 password_ctl = form.get('change_password_repeat', None) 1524 if password: 1525 if (password != password_ctl): 1526 self.flash('Passwords do not match.') 1557 1527 else: 1558 # field error 1559 new_status.append('see below for details') 1560 continue 1561 self.status = u'Error: %s' % ', '.join(new_status) 1562 return 1563 1564 @grok.action('Save', failure=onFailure) 1565 def save(self, **data): 1566 if not isinstance(data.get('password', None), basestring): 1567 self.flash('Password unchanged.') 1568 return 1569 self.applyData(self.context, **data) 1570 self.flash('Password has been set.') 1528 error = validatePassword(password) 1529 if not error: 1530 IUserAccount(self.context).setPassword(password) 1531 write_log_message(self, 'password changed') 1532 self.flash('Password changed.') 1533 else: 1534 self.flash(error) 1571 1535 return 1572 1536 -
main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py
r7140 r7144 74 74 """ 75 75 76 class IStudentPasswordSetting(IWAeUPObject):77 """Data needed for password setting.78 """79 80 password = schema.Password(81 title = u'New password',82 description = u'min. length: 3',83 min_length = 3,84 required = False,85 )86 87 password_repeat = schema.Password(88 title = u'Retype new password',89 required = False,90 )91 92 @invariant93 def passwords_match(obj):94 if obj.password == obj.password_repeat:95 return96 raise Invalid('passwords do not match')97 98 76 class IStudentBase(IWAeUPObject): 99 77 """Representation of student base data. -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r7143 r7144 653 653 # Change password 654 654 self.browser.getLink("Change password").click() 655 self.browser.getControl(name=" form.password").value = 'pw'656 self.browser.getControl( 657 name=" form.password_repeat").value = 'pw'655 self.browser.getControl(name="change_password").value = 'pw' 656 self.browser.getControl( 657 name="change_password_repeat").value = 'pw' 658 658 self.browser.getControl("Save").click() 659 659 self.assertTrue('Value is too short' in self.browser.contents) 660 self.browser.getControl(name=" form.password").value = 'new_password'661 self.browser.getControl( 662 name=" form.password_repeat").value = 'new_passssword'663 self.browser.getControl("Save").click() 664 self.assertTrue(' passwords do not match' in self.browser.contents)665 self.browser.getControl(name=" form.password").value = 'new_password'666 self.browser.getControl( 667 name=" form.password_repeat").value = 'new_password'668 self.browser.getControl("Save").click() 669 self.assertTrue('Password has been set' in self.browser.contents)660 self.browser.getControl(name="change_password").value = 'new_password' 661 self.browser.getControl( 662 name="change_password_repeat").value = 'new_passssword' 663 self.browser.getControl("Save").click() 664 self.assertTrue('Passwords do not match' in self.browser.contents) 665 self.browser.getControl(name="change_password").value = 'new_password' 666 self.browser.getControl( 667 name="change_password_repeat").value = 'new_password' 668 self.browser.getControl("Save").click() 669 self.assertTrue('Password changed' in self.browser.contents) 670 670 # We are still logged in. Changing the password hasn't thrown us out. 671 671 self.browser.getLink("My Data").click() -
main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py
r7021 r7144 33 33 student['studycourse'].previous_verdict = verdict 34 34 return 35 36 def validatePassword(password): 37 if len(password) < 4: 38 return u'Value is too short.' 39 return None 35 40 36 41 # To be specified in customization packages, see also the view which
Note: See TracChangeset for help on using the changeset viewer.