当前位置: 首页>>代码示例>>Python>>正文


Python User.create_from_ldap方法代码示例

本文整理汇总了Python中pyvac.models.User.create_from_ldap方法的典型用法代码示例。如果您正苦于以下问题:Python User.create_from_ldap方法的具体用法?Python User.create_from_ldap怎么用?Python User.create_from_ldap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyvac.models.User的用法示例。


在下文中一共展示了User.create_from_ldap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: populate

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import create_from_ldap [as 别名]
def populate(engine, ldap):
    """ Retrieve users from ldap directory and import them in local database
    """

    session = DBSession()

    # retrieve managers from dedicated group
    managers = ldap.list_manager()

    # retrieve users
    searchFilter = '(&(objectClass=inetOrgPerson)(employeetype=Employee))'
    required = ['objectClass', 'employeeType', 'cn', 'givenName', 'sn',
                'manager', 'mail', 'ou', 'uid', 'userPassword']

    users = ldap._search(searchFilter, required)
    for user_dn, user_entry in users:
        user_data = ldap.parse_ldap_entry(user_dn, user_entry)
        login = user_data['login'].decode('utf-8')
        # check what type of user it is
        group = u'user'
        # if it's a manager he should be in manager group
        if user_data['dn'] in managers:
            group = u'manager'
        # if it's an admin he should be in admin group
        what = '(member=%s)' % user_data['dn']
        if len(ldap._search_admin(what, None)) > 0:
            group = u'admin'

        user = User.by_login(session, login)
        if not user:
            user = User.create_from_ldap(session, user_data, group)
        else:
            # update user with ldap informations in case it changed
            user.email = user_data['email'].decode('utf-8')
            user.firstname = user_data['firstname'].decode('utf-8')
            user.lastname = user_data['lastname'].decode('utf-8')
            user.manager_dn = user_data['manager_dn'].decode('utf-8')
            user.dn = user_data['dn'].decode('utf-8')
            user.role = group

        session.add(user)

    session.commit()
开发者ID:doyousoft,项目名称:pyvac,代码行数:45,代码来源:importldap.py


注:本文中的pyvac.models.User.create_from_ldap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。