當前位置: 首頁>>代碼示例>>Python>>正文


Python PersistentMapping.has_key方法代碼示例

本文整理匯總了Python中ZODB.PersistentMapping.PersistentMapping.has_key方法的典型用法代碼示例。如果您正苦於以下問題:Python PersistentMapping.has_key方法的具體用法?Python PersistentMapping.has_key怎麽用?Python PersistentMapping.has_key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ZODB.PersistentMapping.PersistentMapping的用法示例。


在下文中一共展示了PersistentMapping.has_key方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: nisAuthSource

# 需要導入模塊: from ZODB.PersistentMapping import PersistentMapping [as 別名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import has_key [as 別名]
class nisAuthSource(Folder):
    """ Authenticate Users against NIS 
    
    This folder has 2 modes:
    1. Authenticates only those users for which you add a local role
    2. Authenticates without local roles.  
    
    Since #1 uses local roles, it should play nice with Prop sources and memberships, 
    where #2 will not. """

    meta_type='Authentication Source'
    title='NIS Authentication'
    icon ='misc_/exUserFolder/exUserFolderPlugin.gif'
    manage_editForm=manage_editnisAuthSourceForm
        
    def __init__(self,default_role,NoLocalRoles):
        self.id='nisAuthSource'
        self.default_role=default_role
        self.NoLocalRoles=NoLocalRoles
        self.data=PersistentMapping()
        self.manage_addUserForm=DTMLFile('manage_addNISUserForm',globals())
        self.manage_editUserForm=DTMLFile('manage_editNISUserForm',globals()) #not used.  No way to plug it into exUserFolder.py
    
    def manage_editAuthSource(self,REQUEST):
        """ """
        self.default_role=REQUEST['nisauth_default_role']
        self.NoLocalRoles=REQUEST.has_key('nisauth_NoLocalRoles')

    # Create a User to store local roles
    def createUser(self, username, password, roles):
        import pdb
        pdb.set_trace()
        """ Add A Username """
        if self.NoLocalRoles:
            return self.MessageDialog(self,REQUEST=REQUEST,
                        title  ='Create Error', 
                        message='Cannot create user.  No local roles allowed',
                        action ='manage_main')
        else:
            if self._listOneNISUser(username) and (not self.data.has_key(username)):
                if type(roles) != type([]):
                    if roles:
                        roles=list(roles)
                    else:
                        roles=[self.default_role]
                self.data[username]=PersistentMapping()
                self.data[username].update({'username': username,
                                            'roles': roles})
            else:
                return self.MessageDialog(self,REQUEST=REQUEST,
                            title  ='Create Error', 
                            message='Cannot create user.  Username not in NIS',
                            action ='manage_main')

    # Update a user's roles
    # Passwords are managed via the users NIS unix accounts, not here
    def updateUser(self, username, password, roles):
        if self.NoLocalRoles:
            return self.MessageDialog(self,REQUEST=REQUEST,
                        title  ='Create Error', 
                        message='Cannot create user.  No local roles allowed',
                        action ='manage_main')
        else:
            self.data[username].update({'roles':roles})

    # Encrypt a password
    def cryptPassword_old(self, username, password):
        NISuser=self._listOneNISUser(username)
        if self.NoLocalRoles:
            user=NISuser
        else:
            user=self.listOneUser(username)
        salt = NISuser['password'][:2]
        secret = crypt(password, salt)
        return secret

    # Delete a set of local users
    def deleteUsers(self, userids):
        if self.NoLocalRoles:
            return self.MessageDialog(self,REQUEST=REQUEST,
                        title  ='Create Error', 
                        message='Cannot create user.  No local roles allowed',
                        action ='manage_main')
        for name in userids:
            del self.data[name]

    # Return a list of usernames
    def listUserNames(self,listNIS=None):
        if self.NoLocalRoles or listNIS:
            usernames=self._listNISUserNames()
        else:
            usernames=self.data.keys()
            usernames.sort()
        return usernames
        
    # Return one user matching the username
    # Should be a dictionary;
    # {'username':username, 'password':cryptedPassword, 'roles':list_of_roles}
    def listOneUser(self, username):
        users = []
#.........這裏部分代碼省略.........
開發者ID:denys-duchier,項目名稱:Scolar,代碼行數:103,代碼來源:nisAuthSource.py


注:本文中的ZODB.PersistentMapping.PersistentMapping.has_key方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。