Changeset 7144


Ignore:
Timestamp:
19 Nov 2011, 17:26:18 (13 years ago)
Author:
Henrik Bettermann
Message:

Simplify change password algorithm. No interface IStudentPasswordSetting needed, no adapter StudentPasswordSetting? needed.

I have to think about using a global utility instead of the validatePassword function in utils.py. Therefore validatePassword is not yet used by the PasswordChangeCredentialsPlugin?.

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  
    215215    loginpagename = 'login'
    216216    loginfield = 'student_id'
    217     passwordfield = 'form.password'
    218     repeatfield = 'form.password_repeat'
     217    passwordfield = 'change_password'
     218    repeatfield = 'change_password_repeat'
    219219
    220220    def extractCredentials(self, request):
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7141 r7144  
    4040from waeup.sirp.university.vocabularies import study_modes
    4141from waeup.sirp.students.interfaces import (
    42     IStudentsContainer, IStudent, IStudentClearance, IStudentPasswordSetting,
     42    IStudentsContainer, IStudent, IStudentClearance,
    4343    IStudentPersonal, IStudentBase, IStudentStudyCourse,
    4444    IStudentAccommodation, IStudentClearanceEdit, IStudentStudyLevel,
     
    5252from waeup.sirp.students.vocabularies import StudyLevelSource
    5353from waeup.sirp.students.utils import (
    54     getPaymentDetails, getAccommodationDetails, selectBed, renderPDF)
     54    getPaymentDetails, getAccommodationDetails, selectBed,
     55    renderPDF, validatePassword)
    5556from waeup.sirp.browser.resources import toggleall
    5657from waeup.sirp.authentication import get_principal_role_manager
     
    14961497    form_fields = grok.AutoFields(IStudentBase).select(
    14971498        'email', 'phone')
    1498     #grok.template('basemanagepage')
    14991499    label = 'Edit base data'
    15001500    title = 'Base Data'
     
    15061506        return
    15071507
    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
     1508class StudentChangePasswordPage(WAeUPEditFormPage):
     1509    """ View to manage student base data
    15351510    """
    15361511    grok.context(IStudent)
    15371512    grok.name('change_password')
    15381513    grok.require('waeup.handleStudent')
    1539     form_fields = grok.AutoFields(IStudentPasswordSetting)
    1540     grok.template('baseeditpage')
     1514    grok.template('change_password')
    15411515    label = 'Change password'
    15421516    title = 'Base Data'
    15431517    pnav = 4
    15441518
    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.')
    15571527            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)
    15711535        return
    15721536
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7140 r7144  
    7474        """
    7575
    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     @invariant
    93     def passwords_match(obj):
    94         if obj.password == obj.password_repeat:
    95             return
    96         raise Invalid('passwords do not match')
    97 
    9876class IStudentBase(IWAeUPObject):
    9977    """Representation of student base data.
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7143 r7144  
    653653        # Change password
    654654        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'
    658658        self.browser.getControl("Save").click()
    659659        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)
    670670        # We are still logged in. Changing the password hasn't thrown us out.
    671671        self.browser.getLink("My Data").click()
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r7021 r7144  
    3333    student['studycourse'].previous_verdict = verdict
    3434    return
     35
     36def validatePassword(password):
     37    if len(password) < 4:
     38        return u'Value is too short.'
     39    return None
    3540
    3641# To be specified in customization packages, see also the view which
Note: See TracChangeset for help on using the changeset viewer.