Changeset 7233 for main/waeup.sirp/trunk/src/waeup/sirp
- Timestamp:
- 28 Nov 2011, 21:04:57 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/authentication.py
r7221 r7233 24 24 from zope.securitypolicy.interfaces import ( 25 25 IPrincipalRoleMap, IPrincipalRoleManager) 26 from zope.pluggableauth.factories import Principal 26 27 from zope.pluggableauth.plugins.session import SessionCredentialsPlugin 27 28 from zope.pluggableauth.interfaces import ( 28 ICredentialsPlugin, IAuthenticatorPlugin, IPrincipalInfo) 29 ICredentialsPlugin, IAuthenticatorPlugin, 30 IAuthenticatedPrincipalFactory, AuthenticatedPrincipalCreated) 31 from zope.publisher.interfaces import IRequest 29 32 from zope.password.interfaces import IPasswordManager 30 33 from zope.securitypolicy.principalrole import principalRoleManager 31 34 from waeup.sirp.interfaces import (ILocalRoleSetEvent, 32 IUserAccount, IAuthPluginUtility, IPasswordValidator) 35 IUserAccount, IAuthPluginUtility, IPasswordValidator, 36 ISIRPPrincipal, ISIRPPrincipalInfo) 33 37 34 38 def setup_authentication(pau): … … 68 72 passwordfield = 'form.password' 69 73 70 class PrincipalInfo(object): 71 grok.implements(IPrincipalInfo) 72 73 def __init__(self, id, title, description): 74 class SIRPPrincipalInfo(object): 75 """An implementation of ISIRPPrincipalInfo. 76 77 A SIRP principal info is created with id, login, title, description, 78 phone and email. 79 """ 80 grok.implements(ISIRPPrincipalInfo) 81 82 def __init__(self, id, title, description, email, phone): 74 83 self.id = id 75 84 self.title = title 76 85 self.description = description 86 self.email = email 87 self.phone = phone 77 88 self.credentialsPlugin = None 78 89 self.authenticatorPlugin = None 79 90 91 class SIRPPrincipal(Principal): 92 """A portal principal. 93 94 SIRP principals provide an extra `email` and `phone` 95 attribute extending ordinary principals. 96 """ 97 98 grok.implements(ISIRPPrincipal) 99 100 def __init__(self, id, title=u'', description=u'', email=u'', 101 phone=None, prefix=None): 102 self.id = id 103 self.title = title 104 self.description = description 105 self.groups = [] 106 self.email = email 107 self.phone = phone 108 109 def __repr__(self): 110 return 'SIRPPrincipal(%r)' % self.id 111 112 class AuthenticatedSIRPPrincipalFactory(grok.MultiAdapter): 113 """Creates 'authenticated' SIRP principals. 114 115 Adapts (principal info, request) to a SIRPPrincipal instance. 116 117 This adapter is used by the standard PAU to transform 118 PrincipalInfos into Principal instances. 119 """ 120 grok.adapts(ISIRPPrincipalInfo, IRequest) 121 grok.implements(IAuthenticatedPrincipalFactory) 122 123 def __init__(self, info, request): 124 self.info = info 125 self.request = request 126 127 def __call__(self, authentication): 128 principal = SIRPPrincipal( 129 self.info.id, 130 self.info.title, 131 self.info.description, 132 self.info.email, 133 self.info.phone, 134 ) 135 notify( 136 AuthenticatedPrincipalCreated( 137 authentication, principal, self.info, self.request)) 138 return principal 139 80 140 class Account(grok.Model): 81 141 grok.implements(IUserAccount) … … 84 144 85 145 def __init__(self, name, password, title=None, description=None, 86 email=None, roles = []):146 email=None, phone=None, roles = []): 87 147 self.name = name 88 148 if title is None: … … 93 153 self.description = description 94 154 self.email = email 155 self.phone = phone 95 156 self.setPassword(password) 96 157 #self.setSiteRolesForPrincipal(roles) … … 155 216 if not account.checkPassword(credentials['password']): 156 217 return None 157 return PrincipalInfo(id=account.name,218 return SIRPPrincipalInfo(id=account.name, 158 219 title=account.title, 159 description=account.description) 220 description=account.description, 221 email=account.email, 222 phone=account.phone) 160 223 161 224 def principalInfo(self, id): … … 163 226 if account is None: 164 227 return None 165 return PrincipalInfo(id=account.name,228 return SIRPPrincipalInfo(id=account.name, 166 229 title=account.title, 167 description=account.description) 230 description=account.description, 231 email=account.email, 232 phone=account.phone) 168 233 169 234 def getAccount(self, login): -
main/waeup.sirp/trunk/src/waeup/sirp/browser/browser.txt
r7229 r7233 128 128 >>> browser.getControl(name="control_password").value = 'secret' 129 129 >>> browser.getControl(name="form.email").value = 'xx@yy.zz' 130 >>> browser.getControl(name="form.phone").value = '1234' 130 131 >>> browser.getControl("Add user").click() 131 132 >>> print browser.contents … … 162 163 >>> browser.getControl(name="control_password").value = 'secret' 163 164 >>> browser.getControl(name="form.email").value = 'xx@yy.zz' 165 >>> browser.getControl(name="form.phone").value = '1234' 164 166 >>> browser.getControl("Add user").click() 165 167 >>> 'The userid chosen already exists' in browser.contents -
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r7232 r7233 382 382 title = data['title'] 383 383 email = data['email'] 384 phone = data['phone'] 384 385 description = data['description'] 385 386 #password = data['password'] … … 396 397 try: 397 398 self.context.addUser(name, password, title=title, email=email, 398 description=description, roles=roles) 399 phone=phone, description=description, 400 roles=roles) 399 401 except KeyError: 400 402 self.status = self.flash('The userid chosen already exists ' -
main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py
r7225 r7233 23 23 from zc.sourcefactory.basic import BasicSourceFactory 24 24 from zope import schema 25 from zope.pluggableauth.interfaces import IPrincipalInfo 26 from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal 25 27 from zope.component import getUtility 26 28 from zope.component.interfaces import IObjectEvent … … 232 234 required = True,) 233 235 236 class ISIRPPrincipalInfo(IPrincipalInfo): 237 """Infos about principals that are users of WAeUP SIRP. 238 """ 239 email = Attribute("The email address of a user") 240 phone = Attribute("The phone number of a user") 241 242 243 class ISIRPPrincipal(IPrincipal): 244 """A principle for WAeUP SIRP. 245 246 This interface extends zope.security.interfaces.IPrincipal and 247 requires also an `id` and other attributes defined there. 248 """ 249 250 email = schema.TextLine( 251 title = u'Email', 252 description = u'', 253 required=False,) 254 255 phone = schema.Int( 256 title = u'Phone', 257 description = u'', 258 required=False,) 234 259 235 260 class IUserAccount(IWAeUPObject): … … 255 280 required = True, 256 281 constraint=validate_email, 282 ) 283 284 phone = schema.Int( 285 title = u'Phone', 286 default = None, 287 required = True, 257 288 ) 258 289 -
main/waeup.sirp/trunk/src/waeup/sirp/students/authentication.py
r7221 r7233 28 28 from zope.publisher.interfaces.http import IHTTPRequest 29 29 from zope.session.interfaces import ISession 30 from waeup.sirp.authentication import PrincipalInfo, get_principal_role_manager30 from waeup.sirp.authentication import SIRPPrincipalInfo, get_principal_role_manager 31 31 from waeup.sirp.interfaces import ( 32 32 IAuthPluginUtility, IUserAccount, IPasswordValidator) … … 54 54 def email(self): 55 55 return self.context.email 56 57 @property 58 def phone(self): 59 return self.context.phone 56 60 57 61 @property … … 127 131 if not account.checkPassword(credentials['password']): 128 132 return None 129 return PrincipalInfo(id=account.name,133 return SIRPPrincipalInfo(id=account.name, 130 134 title=account.title, 131 description=account.description) 135 description=account.description, 136 email=account.email, 137 phone=account.phone) 132 138 133 139 def principalInfo(self, id): 134 140 """Get a principal identified by `id`. 135 141 136 This one is required by IAuthenticatorPlugin. 137 """ 138 account = self.getAccount(id) 139 if account is None: 140 return None 141 return PrincipalInfo(id=account.name, 142 title=account.title, 143 description=account.description) 142 This one is required by IAuthenticatorPlugin but not needed here 143 (see respective docstring in applicants package). 144 """ 145 return None 144 146 145 147 def getAccount(self, login): -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_authentication.py
r7221 r7233 64 64 password = None 65 65 email = None 66 phone = None 66 67 67 68 -
main/waeup.sirp/trunk/src/waeup/sirp/tests/test_authentication.py
r7194 r7233 24 24 from waeup.sirp.testing import FunctionalTestCase, FunctionalLayer 25 25 from waeup.sirp.authentication import ( 26 UserAuthenticatorPlugin, Account, PrincipalInfo, get_principal_role_manager)26 UserAuthenticatorPlugin, Account, SIRPPrincipalInfo, get_principal_role_manager) 27 27 28 28 class FakeSite(grok.Site, grok.Container): … … 63 63 result2 = plugin.authenticateCredentials( 64 64 dict(login='bob', password='nonsense')) 65 self.assertTrue(isinstance(result1, PrincipalInfo))65 self.assertTrue(isinstance(result1, SIRPPrincipalInfo)) 66 66 self.assertTrue(result2 is None) 67 67 return … … 72 72 result1 = plugin.principalInfo('bob') 73 73 result2 = plugin.principalInfo('manfred') 74 self.assertTrue(isinstance(result1, PrincipalInfo))74 self.assertTrue(isinstance(result1, SIRPPrincipalInfo)) 75 75 self.assertTrue(result2 is None) 76 76 return -
main/waeup.sirp/trunk/src/waeup/sirp/userscontainer.py
r7221 r7233 32 32 33 33 def addUser(self, name, password, title=None, 34 description=None, email=None, roles=[]):34 description=None, email=None, phone=None, roles=[]): 35 35 """Add a new Account instance, created from parameters. 36 36 """ … … 39 39 #if description is None: 40 40 # description = title 41 self[name] = Account(name, password, title, description, email, roles) 41 self[name] = Account(name, password, title, description, 42 email, phone, roles) 42 43 43 44 def addAccount(self, account):
Note: See TracChangeset for help on using the changeset viewer.