def ldap_get_email_info(username): """ Use LDAP to query the e-mail, then Returns a 3-tuple of: ("username", "*****@*****.**", "My Name") """ try: ldap_attrs = lookupUser(username) except IndexError: raise Exception("Username %s could not be found in LDAP" % username) user_email = ldap_attrs.get('mail', [None])[0] if not user_email: raise Exception( "Could not locate email address for User:%s - Attrs: %s" % (username, ldap_attrs) ) user_name = ldap_attrs.get('cn', [""])[0] if not user_name: user_name = "%s %s" % ( ldap_attrs.get("displayName", [""])[0], ldap_attrs.get("sn", [""])[0] ) if not user_name.strip(' '): user_name = username return (username, user_email, user_name)
def is_expired(self, user): ldap_user = lookupUser(user.username) if not ldap_user: logger.warn("Cannot contact LDAP -- Assume user is expired?") return True expiry_dict = ldap_user.get('expiry') if not expiry_dict: logger.error("LDAP password expiration map is missing --" " check django_cyverse_auth: %s" % ldap_user) return True expiry_date = expiry_dict.get('expires_on') if not expiry_date: logger.error("LDAP password expiration date is missing -- " "check django_cyverse_auth: %s" % ldap_user) return True _is_expired = expiry_date.replace(tzinfo=pytz.UTC) < timezone.now() return _is_expired
def ldap_get_email_info(username): """ Use LDAP to query the e-mail, then Returns a 3-tuple of: ("username", "*****@*****.**", "My Name") """ try: ldap_attrs = lookupUser(username) except IndexError: raise Exception("Username %s could not be found in LDAP" % username) user_email = ldap_attrs.get('mail', [None])[0] if not user_email: raise Exception( "Could not locate email address for User:%s - Attrs: %s" % (username, ldap_attrs)) user_name = ldap_attrs.get('cn', [""])[0] if not user_name: user_name = "%s %s" % (ldap_attrs.get( "displayName", [""])[0], ldap_attrs.get("sn", [""])[0]) if not user_name.strip(' '): user_name = username return (username, user_email, user_name)