Skip to content

Commit aded3cb

Browse files
committed
Fix email syncing issue on login
1 parent 2b516b5 commit aded3cb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Topcoder/class.topcoder.plugin.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ public function gdn_auth_startAuthenticator_handler() {
505505

506506
if ($userID) {
507507
$this->syncTopcoderRoles($userID,$topcoderRoles);
508+
if($decodedToken->hasClaim('email')) {
509+
$email = $decodedToken->getClaim('email');
510+
$this->syncTopcoderEmail($userID, $email);
511+
}
508512
Gdn::authenticator()->setIdentity($userID, true);
509513
Gdn::session()->start($userID, true);
510514
Gdn::authenticator()->trigger(Gdn_Authenticator::AUTH_SUCCESS);
@@ -659,6 +663,23 @@ private function syncTopcoderRoles($userID, $roles) {
659663
}
660664
}
661665

666+
/**
667+
* Sync a email of Topcoder user
668+
* @param $userID
669+
* @param $email Email of Topcoder user
670+
*
671+
*/
672+
private function syncTopcoderEmail($userID, $email) {
673+
$userModel = new UserModel();
674+
$user = $userModel->getID($userID, DATASET_TYPE_ARRAY);
675+
$currentEmail = val('Email', $user)
676+
677+
// Update email if there are any changes only
678+
if($currentEmail !== $email) {
679+
$userModel->setField($userID, 'Email', $email);
680+
}
681+
}
682+
662683
/**
663684
* Get a role by name and type.
664685
*

0 commit comments

Comments
 (0)