Ignore:
Timestamp:
15 Aug 2010, 15:05:55 (14 years ago)
Author:
uli
Message:

Start implementing a serious credentials plugin for applicant data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/jambtables/authentication.py

    r5435 r5440  
    3636from waeup.sirp.authentication import Account, PrincipalInfo
    3737from waeup.sirp.jambtables.interfaces import (
    38     IApplicantPrincipalInfo, IApplicantPrincipal)
     38    IApplicantPrincipalInfo, IApplicantPrincipal, IApplicantSessionCredentials,
     39    IJAMBApplicantSessionCredentials)
    3940
    4041class PortalUser(grok.Role):
     
    121122        return principal
    122123
    123    
     124
     125#
     126# Credentials plugins and related....
     127#
     128
     129class ApplicantCredentials(object):
     130    """Credentials class for ordinary applicants.
     131    """
     132    grok.implements(IApplicantSessionCredentials)
     133
     134    def __init__(self, access_code):
     135        self.access_code = access_code
     136
     137    def getAccessCode(self):
     138        """Get the access code.
     139        """
     140        return self.access_code
     141
     142class JAMBApplicantCredentials(ApplicantCredentials):
     143    """Credentials class for JAMB-screened applicants.
     144    """
     145    grok.implements(IJAMBApplicantSessionCredentials)
     146
     147    def __init__(self, access_code, jamb_reg_no):
     148        self.access_code = access_code
     149        self.jamb_reg_no = jamb_reg_no
     150
     151    def getJAMBRegNo(self):
     152        """Get the JAMB registration no.
     153        """
     154        return self.jamb_reg_no
     155
    124156class WAeUPApplicantCredentialsPlugin(grok.GlobalUtility,
    125157                                      SessionCredentialsPlugin):
     158    """A credentials plugin that scans requests for applicant credentials.
     159    """
    126160    grok.provides(ICredentialsPlugin)
    127161    grok.name('applicant_credentials')
    128162
    129163    loginpagename = 'login'
    130     loginfield = 'form.login'
    131     passwordfield = 'form.password'
     164    accesscode_field = 'form.access_code'
     165    jamb_reg_no_field = 'form.jamb_reg_no'
    132166
    133167    def extractCredentials(self, request):
    134168        """Extracts credentials from a session if they exist.
    135 
    136         This is currently the implementation from zope.pluggableauth.
    137 
    138         XXX: Make this plugin handle login_pde-like input.
    139169        """
    140170        if not IHTTPRequest.providedBy(request):
     
    143173        sessionData = session.get(
    144174            'zope.pluggableauth.browserplugins')
    145         login = request.get(self.loginfield, None)
    146         password = request.get(self.passwordfield, None)
     175        access_code = request.get(self.acccesscode_field, None)
     176        jamb_reg_no = request.get(self.jamb_reg_no_field, None)
    147177        credentials = None
    148178
    149         if login and password:
    150             credentials = SessionCredentials(login, password)
     179        if access_code and jamb_reg_no:
     180            credentials = JAMBApplicantCredentials(
     181                access_code, jamb_reg_no)
     182        elif access_code:
     183            credentials = ApplicantCredentials(access_code)
    151184        elif not sessionData:
    152185            return None
     
    159192        if not credentials:
    160193            return None
    161         return {'login': credentials.getLogin(),
    162                 'password': credentials.getPassword()}
     194        if credentials.getJAMBRegNo() is not None:
     195            return {'accesscode': credentials.getAccessCode(),
     196                    'jambregno': credentials.getJAMBRegNo()}
     197        return {'accesscode': credentials.getAccessCode()}
    163198
    164199
     
    199234    """
    200235    return access_code
    201 
Note: See TracChangeset for help on using the changeset viewer.