# -*- coding: utf-8 # Copyright (c) 2008, iCamp Consortium # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 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 from User import User _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_') uo = User(uuid, user, '', '', '') self._setObject(uuid, uo) return self.objectValues() def _getAllUsers(self): """ get all users without creating some """ 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 and user is not None and user!='Anonymous User': uo = User(uname, uname, '', '', '') self._setObject(uname, uo) u = getattr(self, uname) else: return None return u def createUser(self, uname, fname, lname, email): # Create a user instance with preset values fullname = ' '.join((fname,lname)) uo = User(uname, fullname, fname, lname, email) self._setObject(uname, uo) UsersManagerFactory = Factory(UsersManager)