from OFS.Folder import Folder from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from Globals import Persistent, Acquisition from zope.interface import implements from interfaces import IUsersManager from zope.component.factory import Factory from AccessControl import getSecurityManager _marker = object() class UsersManager(Persistent, Folder, Acquisition.Implicit): implements(IUsersManager) meta_type = 'UsersManager' id = 'users' def _listUsers(self): """ list all users """ user = getSecurityManager().getUser() user = str(user) uuid = user u = getattr(self, user, _marker) if u is _marker and user is not None and user != 'Anonymous User': if user.startswith('http'): # we have openid user uuid = 'openid_'+user.replace('/', '_slash_').replace(':', '_colon_').replace('.', '_dot_') from User import User uo = User(uuid, user) self._setObject(uuid, uo) return self.objectValues() def getUser(self, uname): """ return a user by uname """ u = getattr(self, uname, _marker) if u is _marker: # create a userobject if uname == currently logged in user user = str(getSecurityManager().getUser()) if user == uname: from User import User uo = User(uname) self._setObject(uname, uo) u = getattr(self, uname) else: return None return u UsersManagerFactory = Factory(UsersManager)