/**
  * Create/Update ldap group as tl_member_group
  * @param serialized array $varValue
  * @return serialized array $varValue
  */
 public static function updateMemberGroups($varValue)
 {
     $arrSelectedLdapMemberGroups = deserialize($varValue, true);
     if (!empty($arrSelectedLdapMemberGroups)) {
         $arrLdapMemberGroups = LdapMemberGroupModel::getLdapMemberGroups();
         if (!is_array($arrLdapMemberGroups) || empty($arrLdapMemberGroups)) {
             return $varValue;
         }
         // ldap groups
         foreach ($arrLdapMemberGroups as $k => $v) {
             // selected ldap groups in settings
             foreach ($arrSelectedLdapMemberGroups as $gid) {
                 if (isset($v['gidnumber']) && $v['gidnumber'][0] == $gid) {
                     $objMemberGroup = \MemberGroupModel::findBy('ldapGid', $gid);
                     if ($objMemberGroup === null) {
                         $objMemberGroup = new \MemberGroupModel();
                         $objMemberGroup->ldapGid = $gid;
                     }
                     $objMemberGroup->tstamp = time();
                     // name
                     if (isset($v['cn'])) {
                         $objMemberGroup->name = $v['cn'][0];
                     } else {
                         $objMemberGroup->name = $gid;
                     }
                     $objMemberGroup->save();
                 }
             }
         }
         LdapMember::updateMembers($arrSelectedLdapMemberGroups);
     }
     return $varValue;
 }
Пример #2
0
 /**
  * Import User from LDAP
  * @param String - Input Username $username
  * @param String - Input Password $password
  * @param String - Parent Table $strTable
  * @return boolean login status
  */
 public function importUserHook($strUsername, $strPassword, $strTable)
 {
     if (LdapMember::authenticateLdapMember($strUsername, $strPassword)) {
         LdapMember::doImportMember($strUsername, deserialize($GLOBALS['TL_CONFIG']['ldap_groups'], true));
         return true;
     } else {
         return false;
     }
 }
 /**
  * Store Login Module ID in Session, required by LdapAuth (Module config)
  * @return string
  */
 public function generate()
 {
     // Login
     if (\Input::post('FORM_SUBMIT') == 'tl_login') {
         if (\Input::post('username', true) && \Input::post('password', true)) {
             $objMember = \MemberModel::findBy('username', \Input::post('username', true));
             if ($objMember !== null) {
                 // always reset the password to a random value, otherwise checkCredentialsHook will never be triggered
                 LdapMember::resetPassword($objMember, \Input::post('username', true));
             }
         }
         // validate email
         if ($GLOBALS['TL_CONFIG']['ldap_uid'] == 'mail' && !\Validator::isEmail(\Input::post('username', true))) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['email']);
             $this->reload();
         }
     }
     $strParent = parent::generate();
     return $strParent;
 }
 public static function findLdapMember($strUsername)
 {
     if (Ldap::getConnection()) {
         $user_name_filter = $GLOBALS['TL_CONFIG']['ldap_uid'] . '=' . $strUsername;
         $filter = '(&(' . $user_name_filter . ')' . $GLOBALS['TL_CONFIG']['ldap_filter_person'] . ')';
         // search by username
         $query = ldap_search(Ldap::getConnection(), $GLOBALS['TL_CONFIG']['ldap_base'], $filter, LdapMember::getAttributes());
         if (!$query) {
             return null;
         }
         $found = ldap_get_entries(Ldap::getConnection(), $query);
         // user not found
         if (!is_array($found) || count($found) <= 0) {
             return null;
         }
         $found = (object) $found[0];
         return $found;
     } else {
         return null;
     }
 }