<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE>
BLOCKQUOTE {
        MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em; MARGIN-TOP: 0px
}
OL {
        MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
UL {
        MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
P {
        MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
BODY {
        FONT-SIZE: 10.5pt; FONT-FAMILY: Î¢ÈíÑźÚ; COLOR: #000000; LINE-HEIGHT: 1.5
}
</STYLE>

<META name=GENERATOR content="MSHTML 11.00.9600.16521"></HEAD>
<BODY style="MARGIN: 10px">
<DIV>
<DIV>In my Client-Server Application,I do not want two user login with the same 
login name.</DIV>
<DIV> </DIV>
<DIV>For example, user1 logined with name "test1",then user2 try to login with 
"test1" too, the login of user2 should be denied. At now, my code could not 
achieve this goal,so what's the method.</DIV>
<DIV>Thanks all!</DIV>
<DIV> </DIV>
<DIV>
<DIV>The following is server code:</DIV>
<DIV>-----------------------------------------------------------------------------</DIV></DIV>
<DIV>class simulationServer:</DIV>
<DIV>
<DIV>    def __init__(self):</DIV>
<DIV>        self.groups = {} # indexed by 
name</DIV>
<DIV>        self.groups['#admin']= 
Group('#admin')</DIV>
<DIV>        
self.groups['#general']=Group('#general')</DIV>
<DIV>    def joinGroup(self, groupname, user):</DIV>
<DIV>        if groupname not in 
self.groups:</DIV>
<DIV>            
self.groups[groupname] = Group(groupname)</DIV>
<DIV>        
self.groups[groupname].addUser(user)</DIV>
<DIV>        return 
self.groups[groupname]</DIV>
<DIV>    def leaveGroup(self, groupname, user):</DIV>
<DIV>        
self.groups[groupname].delUser(user)</DIV>
<DIV>        return 
self.groups[groupname]</DIV>
<DIV>    def getGroup(self, admin=False):</DIV>
<DIV>        if admin==True:</DIV>
<DIV>            return 
self.groups['#admin']</DIV>
<DIV>        return 
self.groups['#general']</DIV>
<DIV> </DIV>
<DIV>class simulRealm:</DIV>
<DIV>    implements(portal.IRealm)</DIV>
<DIV>    def requestAvatar(self, avatarID, mind, 
*interfaces):</DIV>
<DIV>        assert pb.IPerspective in 
interfaces</DIV>
<DIV>        avatar = User(avatarID)</DIV>
<DIV>        avatar.server = 
self.server</DIV>
<DIV>        avatar.attached(mind)</DIV>
<DIV>        return pb.IPerspective, avatar, 
lambda a=avatar:a.detached(mind)</DIV>
<DIV>        </DIV>
<DIV>class User(pb.Avatar):</DIV>
<DIV>    def __init__(self, name):</DIV>
<DIV>        self.name = name</DIV>
<DIV>        self.group=None</DIV>
<DIV>        self.status=False  #False: 
general client user not sync yet </DIV>
<DIV>        
self.serverRoot=ServerRoot()</DIV>
<DIV>    def attached(self, mind):</DIV>
<DIV>        self.remote = mind</DIV>
<DIV>    def detached(self, mind):</DIV>
<DIV>        print '%s 
detached...'%self.name</DIV>
<DIV>        
self.server.leaveGroup(self.group, self)</DIV>
<DIV>        
self.server.messageClientUserupdated()</DIV>
<DIV>        self.remote = None</DIV>
<DIV>    def perspective_joinGroup(self, groupname):</DIV>
<DIV>        print 'joined Group on Server 
Machine '</DIV>
<DIV>        print groupname</DIV>
<DIV>        self.group=groupname</DIV>
<DIV>        self.server.joinGroup(groupname, 
self)</DIV>
<DIV>        
self.server.messageClientUserupdated()</DIV>
<DIV>        return groupname</DIV>
<DIV>    def perspective_getServerRoot(self):</DIV>
<DIV>        return self.serverRoot</DIV>
<DIV>    def getClientRoot(self):</DIV>
<DIV>        return self.remote</DIV>
<DIV>    def perspective_updateStatus(self):</DIV>
<DIV>        self.status=True  # user 
sync</DIV>
<DIV> </DIV>
<DIV>class Group(pb.Viewable):</DIV>
<DIV>    def __init__(self, groupname):</DIV>
<DIV>        self.name = groupname</DIV>
<DIV>        self.users = []</DIV>
<DIV>    def addUser(self, user):</DIV>
<DIV>        self.users.append(user)</DIV>
<DIV>    def delUser(self, user):</DIV>
<DIV>        self.users.remove(user)</DIV>
<DIV>    def getallUsers(self):</DIV>
<DIV>        return self.users</DIV>
<DIV>    def getnotSyncUsers(self):</DIV>
<DIV>        nosyncusers=[]</DIV>
<DIV>        if self.users:</DIV>
<DIV>            for user 
in self.users:</DIV>
<DIV>                
if not user.status:</DIV>
<DIV>                    
nosyncusers.append(user)</DIV>
<DIV>        return nosyncusers</DIV>
<DIV>    def getUsers(self):</DIV>
<DIV>            
syncusers=[]</DIV>
<DIV>            if 
self.users:</DIV>
<DIV>                
for user in self.users:</DIV>
<DIV>                    
if user.status:</DIV>
<DIV>                        
syncusers.append(user)</DIV>
<DIV>            return 
syncusers</DIV></DIV>
<DIV>-----------------------------------------------------------------------------</DIV>
<DIV>
<DIV>Client code:</DIV>
<DIV>def1 = 
factory.login(credentials.UsernamePassword(self.group+'_'+self.UserNameandPwd[0], 
self.UserNameandPwd[1]), client=self)</DIV>
<DIV>def1.addCallback(self.connected)</DIV>
<DIV>def1.addErrback(self.connectFailure)</DIV></DIV></DIV></BODY></HTML>