Changeset 4129
- Timestamp:
- 15 May 2009, 11:17:34 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/authentication.py
r4125 r4129 13 13 from zope.component import getUtility 14 14 from zope.interface import Interface 15 from zope.securitypolicy.interfaces import IPrincipalRoleManager 16 from zope.securitypolicy.principalrole import principalRoleManager 15 17 from waeup.interfaces import IWAeUPObject, IUserAccount 16 18 from waeup.viewlets import Index, MainArea, LeftSidebar … … 78 80 class Account(grok.Model): 79 81 grok.implements(IUserAccount) 80 82 83 81 84 def __init__(self, name, password, title=None, description=None, 82 85 roles = []): … … 89 92 self.description = description 90 93 self.setPassword(password) 91 self. roles = roles94 self.setRoles(roles) 92 95 93 96 def setPassword(self, password): … … 99 102 return passwordmanager.checkPassword(self.password, password) 100 103 101 104 def getRoles(self): 105 prm = self._getPrincipalRoleManager() 106 roles = [x[0] for x in prm.getRolesForPrincipal(self.name) 107 if x[0].startswith('waeup.')] 108 return roles 109 110 def setRoles(self, roles): 111 prm = self._getPrincipalRoleManager() 112 113 old_roles = self.getRoles() 114 for role in old_roles: 115 # Remove old roles, not to be set now... 116 if role.startswith('waeup.') and role not in roles: 117 prm.unsetRoleForPrincipal(role, self.name) 118 119 for role in roles: 120 prm.assignRoleToPrincipal(role, self.name) 121 122 roles = property(getRoles, setRoles) 123 124 def _getPrincipalRoleManager(self): 125 portal = grok.getSite() 126 if portal is not None: 127 return IPrincipalRoleManager(portal) 128 return principalRoleManager 129 130 102 131 class UserAuthenticatorPlugin(grok.GlobalUtility): 103 132 grok.provides(IAuthenticatorPlugin)
Note: See TracChangeset for help on using the changeset viewer.