@@ -505,6 +505,7 @@ public function gdn_auth_startAuthenticator_handler() {
505
505
506
506
if ($ userID ) {
507
507
$ this ->syncTopcoderRoles ($ userID ,$ topcoderRoles );
508
+ $ this ->syncTopcoderEmail ($ userID ,$ decodedToken ->getClaim ('email ' ));
508
509
Gdn::authenticator ()->setIdentity ($ userID , true );
509
510
Gdn::session ()->start ($ userID , true );
510
511
Gdn::authenticator ()->trigger (Gdn_Authenticator::AUTH_SUCCESS );
@@ -659,6 +660,45 @@ private function syncTopcoderRoles($userID, $roles) {
659
660
}
660
661
}
661
662
663
+ /**
664
+ * Sync the e-mail addressof Topcoder for an user
665
+ * @param $userID
666
+ * @param $roles array a list of role names
667
+ *
668
+ */
669
+ private function syncTopcoderEmail ($ userID ,$ topcoder_email ) {
670
+ $ userModel = new UserModel ();
671
+ $ user = $ userModel ->getID ($ userID );
672
+ $ vanilla_email = val ('Email ' , $ user );
673
+
674
+ // Update if two e-mail addresses are different
675
+ if ($ vanilla_email !== $ topcoder_email ) {
676
+ $ userData = [
677
+ "UserID " => $ userID ,
678
+ "Email " => $ topcoder_email ,
679
+ "EmailConfirmed " => true
680
+ ];
681
+
682
+ $ settings = [
683
+ 'NoConfirmEmail ' => true
684
+ ];
685
+ $ ret = $ userModel ->save ($ userData , $ settings );
686
+ if ($ ret ) {
687
+ $ modified_user = $ userModel ->getID ($ userID );
688
+ $ modified_email = val ('Email ' , $ user );
689
+ if ($ modified_email === $ topcoder_email ) {
690
+ self ::log ('Succeeded to modify e-mail ' , ["new_email " =>$ modified_email ]);
691
+ } else {
692
+ self ::log ('Failed to modify e-mail ' , []);
693
+ }
694
+ } else {
695
+ self ::log ('Failed to modify e-mail ' , []);
696
+ }
697
+ } else {
698
+ self ::log ('No need to modify e-mail. ' , []);
699
+ }
700
+ }
701
+
662
702
/**
663
703
* Get a role by name and type.
664
704
*
0 commit comments