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?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.