mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
Merge pull request #10083 from nextcloud/fix/noid/ldap-unsupported-avatar-format
LDAP user should be able to set avatar if directory provides incompatible image
This commit is contained in:
commit
42912a0e25
4 changed files with 677 additions and 1042 deletions
|
|
@ -552,35 +552,37 @@ class User {
|
|||
|
||||
/**
|
||||
* @brief attempts to get an image from LDAP and sets it as Nextcloud avatar
|
||||
* @return null
|
||||
* @return bool
|
||||
*/
|
||||
public function updateAvatar() {
|
||||
if($this->wasRefreshed('avatar')) {
|
||||
return;
|
||||
public function updateAvatar($force = false) {
|
||||
if(!$force && $this->wasRefreshed('avatar')) {
|
||||
return false;
|
||||
}
|
||||
$avatarImage = $this->getAvatarImage();
|
||||
if($avatarImage === false) {
|
||||
//not set, nothing left to do;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$this->image->loadFromBase64(base64_encode($avatarImage));
|
||||
$this->setOwnCloudAvatar();
|
||||
if(!$this->image->loadFromBase64(base64_encode($avatarImage))) {
|
||||
return false;
|
||||
}
|
||||
return $this->setOwnCloudAvatar();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sets an image as Nextcloud avatar
|
||||
* @return null
|
||||
* @return bool
|
||||
*/
|
||||
private function setOwnCloudAvatar() {
|
||||
if(!$this->image->valid()) {
|
||||
$this->log->log('jpegPhoto data invalid for '.$this->dn, ILogger::ERROR);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
//make sure it is a square and not bigger than 128x128
|
||||
$size = min(array($this->image->width(), $this->image->height(), 128));
|
||||
if(!$this->image->centerCrop($size)) {
|
||||
$this->log->log('croping image for avatar failed for '.$this->dn, ILogger::ERROR);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->fs->isLoaded()) {
|
||||
|
|
@ -590,6 +592,7 @@ class User {
|
|||
try {
|
||||
$avatar = $this->avatarManager->getAvatar($this->uid);
|
||||
$avatar->set($this->image);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
\OC::$server->getLogger()->logException($e, [
|
||||
'message' => 'Could not set avatar for ' . $this->dn,
|
||||
|
|
@ -597,6 +600,7 @@ class User {
|
|||
'app' => 'user_ldap',
|
||||
]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -93,8 +93,10 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
|
|||
|
||||
/**
|
||||
* checks whether the user is allowed to change his avatar in Nextcloud
|
||||
*
|
||||
* @param string $uid the Nextcloud user name
|
||||
* @return boolean either the user can or cannot
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function canChangeAvatar($uid) {
|
||||
if ($this->userPluginManager->implementsActions(Backend::PROVIDE_AVATAR)) {
|
||||
|
|
@ -105,11 +107,11 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
|
|||
if(!$user instanceof User) {
|
||||
return false;
|
||||
}
|
||||
if($user->getAvatarImage() === false) {
|
||||
$imageData = $user->getAvatarImage();
|
||||
if($imageData === false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return !$user->updateAvatar(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue