/** * Get the data for TYPO3 database * * @param array $ldapUser * @return array */ public function getTypo3UserData(array $ldapUser) { $mappings = $this->currentConfig->getFeUsersMapping(); // generate random password $charSet = 'abdeghjmnpqrstuvxyzABDEGHJLMNPQRSTVWXYZ23456789@#$%'; $password = ''; for ($i = 0; $i < 16; $i++) { $password .= $charSet[rand() % strlen($charSet)]; } $usernameAttribute = LDAPConfigUtility::getUsernameAttribute($this->currentConfig->getFeUsersFilter()); $typo3UserData = array('username' => $ldapUser[$usernameAttribute][0], 'tx_apldapauth_dn' => $ldapUser['dn'], 'pid' => 0, 'password' => $password); unset($mappings['pid']); /** @var $mapping FeUsers */ foreach ($mappings as $mapping) { $typo3FieldName = $mapping->getField(); $ldapAttribute = strtolower($mapping->getAttribute()); $value = $mapping->getIsAttribute() ? $ldapUser[$ldapAttribute][0] : $mapping->getValue(); if ($mapping->getIsImage()) { // image $fileName = 'tx_apldapauth_' . md5($typo3UserData['tx_apldapauth_dn']) . '.jpg'; $imageFilePath = PATH_site . 'uploads/pics/' . $fileName; $image = imagecreatefromstring($value); $imageSaveSuccess = imagejpeg($image, $imageFilePath); if ($imageSaveSuccess) { $typo3UserData[$typo3FieldName] = $fileName; } } else { if ($mapping->getIsDatetime()) { // date fields $typo3UserData[$typo3FieldName] = strtotime($value); } else { // text fields $typo3UserData[$typo3FieldName] = $value; // use value of $ldapFieldName if field in $ldapUser doesn't exist } } } return $typo3UserData; }