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


Python Profile.employee_id方法代码示例

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


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

示例1: authenticate

# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import employee_id [as 别名]
  def authenticate(self, username=None, password=None):
    if self.local_admin_user and username == self.local_admin_user:
      # let the configured local admin user pass-through
      return None

    try:
      l = ldap.initialize(self.uri)
      if self.secure: l.start_tls_s()
      # authenticate to LDAP
      l.simple_bind_s("%[email protected]" % username, password)
      # read our attributes
      results = l.search_s(self.base,
                          ldap.SCOPE_SUBTREE,
                          self.search_filter % username,
                          attrlist=self.attributes.keys())
      results = results[0][1]

      # split results into user/profile attributes and normalize field names
      attributes = {'user': {}, 'profile': {}}
      for attr in self.attributes:
        (obj, field) = self.attributes[attr].split('.')
        attributes[obj][field] = results.get(attr, [''])

      # see if we have a user
      try:
        user = User.objects.get(username=username)
      except User.DoesNotExist:
        user = User.objects.create_user(username)

      # update the user with the current directory information
      user.first_name = attributes['user']['first_name'][0]
      user.last_name = attributes['user']['last_name'][0]
      user.email = attributes['user']['email'][0]
      user.save()

      # see if the user has a profile
      try:
        profile = user.profile
      except Profile.DoesNotExist:
        profile = Profile()

      # update the user's profile
      profile.employee_id = attributes['profile']['employee_id'][0]
      profile.phone_number = attributes['profile']['phone_number'][0]
      profile.mailbox = attributes['profile']['mailbox'][0]
      profile.department = attributes['profile']['department'][0]
      profile.nickname = attributes['profile']['nickname'][0]
      # affiliation is handled a little differently, we need to check to see
      # if 'faculty' or 'staff' is in the affiliation list
      if "faculty" in attributes['profile']['affiliation']:
        profile.affiliation = "faculty"
      elif "staff" in attributes['profile']['affiliation']:
        profile.affiliation = "staff"
      else:
        profile.affiliation = "other"

      # if there is no employee_id, set it to all zeros
      if not profile.employee_id:
        profile.employee_id = '000000000'

      # set the profile in the user and save it
      user.profile = profile
      user.profile.save()
      return user
    except ldap.INVALID_CREDENTIALS:
      self.logger.debug("failed authentication for user '%s'" % username)
      raise PermissionDenied
    except ldap.LDAPError, e:
      if type(e.message) == dict:
        info = e.message.get('info', "<no info>")
        desc = e.message.get('desc', "<no desc>")
        self.logger.error("LDAP Error: %s (%s)" % (info, desc))
      else:
        self.logger.error("LDAP Error: %s" % e)
开发者ID:cit-jmu,项目名称:workshop-django,代码行数:76,代码来源:backends.py


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