From cf73db11b5d62239baf9736602d15a0e9f11a312 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 16 Mar 2016 20:51:03 +0100 Subject: Avatar must be saved after login is done and external storages set up properly, fixes #21555 --- apps/user_ldap/lib/user/user.php | 17 ++++++++++++++++- apps/user_ldap/tests/user/user.php | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/user_ldap/lib/user/user.php b/apps/user_ldap/lib/user/user.php index 083f517f9f1..4707f0d0dd2 100644 --- a/apps/user_ldap/lib/user/user.php +++ b/apps/user_ldap/lib/user/user.php @@ -207,7 +207,11 @@ class User { foreach ($attrs as $attr) { if(isset($ldapEntry[$attr])) { $this->avatarImage = $ldapEntry[$attr][0]; - $this->updateAvatar(); + // the call to the method that saves the avatar in the file + // system must be postponed after the login. It is to ensure + // external mounts are mounted properly (e.g. with login + // credentials from the session). + \OCP\Util::connectHook('OC_User', 'post_login', $this, 'updateAvatarPostLogin'); break; } } @@ -451,6 +455,17 @@ class User { } } + /** + * called by a post_login hook to save the avatar picture + * + * @param array $params + */ + public function updateAvatarPostLogin($params) { + if(isset($params['uid']) && $params['uid'] === $this->getUsername()) { + $this->updateAvatar(); + } + } + /** * @brief attempts to get an image from LDAP and sets it as ownCloud avatar * @return null diff --git a/apps/user_ldap/tests/user/user.php b/apps/user_ldap/tests/user/user.php index 166fe4b000c..74f27877882 100644 --- a/apps/user_ldap/tests/user/user.php +++ b/apps/user_ldap/tests/user/user.php @@ -774,6 +774,7 @@ class Test_User_User extends \Test\TestCase { } $userMock->processAttributes($record); + \OC_Hook::emit('OC_User', 'post_login', array('uid' => $uid)); } public function emptyHomeFolderAttributeValueProvider() { -- cgit v1.2.3