Skip to content

Commit d209a58

Browse files
committed
Only update local user cache when userdata has changed
There is no need to update the local user on every login when nothing has changed. This should fix most instances of #132 - if the oAuth provider data has actually updated, the user would have to log into the farmer to update the data though.
1 parent 9fd41b5 commit d209a58

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

OAuthManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ protected function processUserData($userdata, $servicename)
235235
$localUser = $auth->getUserByEmail($userdata['mail']);
236236
if ($localUser) {
237237
$localUserInfo = $auth->getUserData($localUser);
238+
$localUserInfo['user'] = $localUser;
239+
if(isset($localUserInfo['pass'])) unset($localUserInfo['pass']);
240+
238241
// check if the user allowed access via this service
239242
if (!in_array($auth->cleanGroup($servicename), $localUserInfo['grps'])) {
240243
throw new Exception('authnotenabled', [$servicename]);
@@ -251,8 +254,12 @@ protected function processUserData($userdata, $servicename)
251254
$auth->getConf('overwrite-groups')
252255
);
253256

254-
// update user
255-
$auth->modifyUser($localUser, $userdata);
257+
// update user if changed
258+
array_multisort($localUserInfo);
259+
array_multisort($userdata);
260+
if($localUserInfo != $userdata) {
261+
$auth->modifyUser($localUser, $userdata);
262+
}
256263
} elseif (actionOK('register') || $auth->getConf('register-on-auth')) {
257264
if (!$auth->registerOAuthUser($userdata, $servicename)) {
258265
throw new Exception('generic create error');

0 commit comments

Comments
 (0)