Changeset 6713


Ignore:
Timestamp:
10 Sep 2011, 10:36:11 (13 years ago)
Author:
uli
Message:

Enable immediate authentication of student when password is reset.

Location:
main/waeup.sirp/branches/uli-studentpw/src/waeup/sirp/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/branches/uli-studentpw/src/waeup/sirp/students/authentication.py

    r6680 r6713  
    2626from zope.component import getUtility
    2727from zope.password.interfaces import IPasswordManager
    28 from zope.pluggableauth.interfaces import IAuthenticatorPlugin
     28from zope.pluggableauth.interfaces import (
     29    IAuthenticatorPlugin, ICredentialsPlugin)
     30from zope.pluggableauth.plugins.session import SessionCredentialsPlugin
    2931from waeup.sirp.authentication import PrincipalInfo, get_principal_role_manager
    3032from waeup.sirp.interfaces import IAuthPluginUtility, IUserAccount
     
    117119            return None
    118120        if not account.checkPassword(credentials['password']):
    119             return None
     121            # XXX: This is not a proper solution. Works, however, basically
     122            if credentials.get('reset', False) is not True:
     123                return None
    120124        return PrincipalInfo(id=account.name,
    121125                             title=account.title,
     
    157161        return IUserAccount(student)
    158162
     163class PasswordChangeCredentialsPlugin(grok.GlobalUtility,
     164                                      SessionCredentialsPlugin):
     165    grok.provides(ICredentialsPlugin)
     166    grok.name('student_pw_change')
     167
     168    loginpagename = 'login'
     169    loginfield = 'student_id'
     170    passwordfield = 'form.password'
     171
     172    def extractCredentials(self, request):
     173        result = super(
     174            PasswordChangeCredentialsPlugin, self).extractCredentials(
     175            request)
     176        if isinstance(result, dict):
     177            # Add a marker for the authentication plugin
     178            result['reset'] = True
     179        return result
     180
    159181class StudentsAuthenticatorSetup(grok.GlobalUtility):
    160182    """Register or unregister student authentication for a PAU.
     
    165187
    166188    def register(self, pau):
     189        plugins = list(pau.credentialsPlugins)
     190        plugins.insert(0, 'student_pw_change')
     191        pau.credentialsPlugins = tuple(plugins)
    167192        plugins = list(pau.authenticatorPlugins)
    168193        plugins.append('students')
  • main/waeup.sirp/branches/uli-studentpw/src/waeup/sirp/students/tests/test_browser.py

    r6707 r6713  
    282282        self.browser.open(self.login_path)
    283283        self.browser.getControl(name="form.login").value = self.test_student_id
    284         self.browser.getControl(name="password").value = 'new_password'
     284        self.browser.getControl(name="form.password").value = 'new_password'
    285285        self.browser.getControl("Login").click()
    286286        self.assertEqual(self.browser.url, self.student_path)
    287287        self.assertTrue('You logged in' in self.browser.contents)
    288 
    289         return
     288        return
Note: See TracChangeset for help on using the changeset viewer.