LDAP: also try MS AD's thumbnailPhoto when looking for an avatar image
This commit is contained in:
parent
84607db284
commit
18e1a10e96
|
@ -85,15 +85,14 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$jpegPhoto = $this->access->readAttribute($dn, 'jpegPhoto');
|
$avatarImage = $this->getAvatarImage($uid, $dn);
|
||||||
\OCP\Config::setUserValue($uid, 'user_ldap', 'lastJpegPhotoLookup', time());
|
if($avatarImage === false) {
|
||||||
if(!$jpegPhoto || !is_array($jpegPhoto) || !isset($jpegPhoto[0])) {
|
|
||||||
//not set, nothing left to do;
|
//not set, nothing left to do;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$image = new \OCP\Image();
|
$image = new \OCP\Image();
|
||||||
$image->loadFromBase64(base64_encode($jpegPhoto[0]));
|
$image->loadFromBase64(base64_encode($avatarImage));
|
||||||
|
|
||||||
if(!$image->valid()) {
|
if(!$image->valid()) {
|
||||||
\OCP\Util::writeLog('user_ldap', 'jpegPhoto data invalid for '.$dn,
|
\OCP\Util::writeLog('user_ldap', 'jpegPhoto data invalid for '.$dn,
|
||||||
|
@ -128,8 +127,7 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface {
|
||||||
if(!$dn) {
|
if(!$dn) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$jpegPhoto = $this->access->readAttribute($dn, 'jpegPhoto');
|
if($this->getAvatarImage($uid, $dn) === false) {
|
||||||
if(!$jpegPhoto || !is_array($jpegPhoto) || !isset($jpegPhoto[0])) {
|
|
||||||
//The user is allowed to change his avatar in ownCloud only if no
|
//The user is allowed to change his avatar in ownCloud only if no
|
||||||
//avatar is provided by LDAP
|
//avatar is provided by LDAP
|
||||||
return true;
|
return true;
|
||||||
|
@ -137,6 +135,26 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief reads the image from LDAP that shall be used as Avatar
|
||||||
|
* @param $uid string, the ownCloud user name
|
||||||
|
* @param $dn string, the user DN
|
||||||
|
* @return image data (provided by LDAP) | false
|
||||||
|
*/
|
||||||
|
private function getAvatarImage($uid, $dn) {
|
||||||
|
$attributes = array('jpegPhoto', 'thumbnailPhoto');
|
||||||
|
foreach($attributes as $attribute) {
|
||||||
|
$result = $this->access->readAttribute($dn, $attribute);
|
||||||
|
\OCP\Config::setUserValue($uid, 'user_ldap', 'lastJpegPhotoLookup',
|
||||||
|
time());
|
||||||
|
if($result !== false && is_array($result) && isset($result[0])) {
|
||||||
|
return $result[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if the password is correct
|
* @brief Check if the password is correct
|
||||||
* @param $uid The username
|
* @param $uid The username
|
||||||
|
|
Loading…
Reference in New Issue