Remember the last 3rdParty provider used
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 8 Aug 2013 20:02:31 +0000 (22:02 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 8 Aug 2013 20:03:20 +0000 (22:03 +0200)
com.woltlab.wcf/templates/register.tpl
wcfsetup/install/files/lib/action/FacebookAuthAction.class.php
wcfsetup/install/files/lib/action/GithubAuthAction.class.php
wcfsetup/install/files/lib/action/GoogleAuthAction.class.php
wcfsetup/install/files/lib/action/TwitterAuthAction.class.php
wcfsetup/install/files/lib/form/RegisterForm.class.php

index 5146e95614dca2e1bbbb6d90227a890632a230fd..075a8061d6ef6316fbe6cc72be9f2fa6aff142b7 100644 (file)
 {include file='userNotice'}
 
 {if $isExternalAuthentication}
-       {if $__wcf->session->getVar('__githubToken')}
-               <p class="info">{lang}wcf.user.3rdparty.github.register{/lang}</p>
-       {elseif $__wcf->session->getVar('__twitterData')}
-               <p class="info">{lang}wcf.user.3rdparty.twitter.register{/lang}</p>
-       {elseif $__wcf->session->getVar('__facebookData')}
-               <p class="info">{lang}wcf.user.3rdparty.facebook.register{/lang}</p>
-       {elseif $__wcf->session->getVar('__googleData')}
-               <p class="info">{lang}wcf.user.3rdparty.google.register{/lang}</p>
-       {/if}
+       <p class="info">{lang}wcf.user.3rdparty.{$__wcf->session->getVar('__3rdPartyProvider')}.register{/lang}</p>
 {/if}
 
 {if $errorField}
index aeb1ded5170cde3251d77ef2a26c1cbe778c3031..aae1f7956e07ae8795daec3b0b265bf0e2c5bc11 100644 (file)
@@ -52,6 +52,7 @@ class FacebookAuthAction extends AbstractAction {
                        
                        // validate state, validation of state is executed after fetching the access_token to invalidate 'code'
                        if (!isset($_GET['state']) || $_GET['state'] != WCF::getSession()->getVar('__facebookInit')) throw new IllegalLinkException();
+                       WCF::getSession()->unregister('__facebookInit');
                        
                        parse_str($content, $data);
                        
@@ -96,6 +97,7 @@ class FacebookAuthAction extends AbstractAction {
                                }
                        }
                        else {
+                               WCF::getSession()->register('__3rdPartyProvider', 'facebook');
                                // save data for connection
                                if (WCF::getUser()->userID) {
                                        WCF::getSession()->register('__facebookUsername', $userData['name']);
index 7ab58ed56f150b0843d83c8fb206032e90cdad13..ff0f99cd618ceb1395cd3bbf7c4bc2b240316380 100644 (file)
@@ -55,6 +55,7 @@ class GithubAuthAction extends AbstractAction {
                        
                        // validate state, validation of state is executed after fetching the access_token to invalidate 'code'
                        if (!isset($_GET['state']) || $_GET['state'] != WCF::getSession()->getVar('__githubInit')) throw new IllegalLinkException();
+                       WCF::getSession()->unregister('__githubInit');
                        
                        parse_str($content, $data);
                        
@@ -99,6 +100,7 @@ class GithubAuthAction extends AbstractAction {
                                        throw new IllegalLinkException();
                                }
                                
+                               WCF::getSession()->register('__3rdPartyProvider', 'github');
                                // save data for connection
                                if (WCF::getUser()->userID) {
                                        WCF::getSession()->register('__githubUsername', $userData['login']);
index 1a553eaf7df7f98813c38d991178eefd0279ca54..04115e68b14430229ad4c9dc578a0b073ce975dc 100644 (file)
@@ -60,6 +60,7 @@ class GoogleAuthAction extends AbstractAction {
                        
                        // validate state, validation of state is executed after fetching the access_token to invalidate 'code'
                        if (!isset($_GET['state']) || $_GET['state'] != WCF::getSession()->getVar('__googleInit')) throw new IllegalLinkException();
+                       WCF::getSession()->unregister('__googleInit');
                        
                        $data = JSON::decode($content);
                        
@@ -105,6 +106,8 @@ class GoogleAuthAction extends AbstractAction {
                                }
                        }
                        else {
+                               WCF::getSession()->register('__3rdPartyProvider', 'google');
+                               
                                // save data for connection
                                if (WCF::getUser()->userID) {
                                        WCF::getSession()->register('__googleUsername', $userData['name']);
index 4dbe76a28d1e90ce761af2e30fab5505046e9ab8..5d17492bb6b74ec235cc9687a7c64b768ec3a90c 100644 (file)
@@ -38,6 +38,7 @@ class TwitterAuthAction extends AbstractAction {
                if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) {
                        // fetch data created in the first step
                        $initData = WCF::getSession()->getVar('__twitterInit');
+                       WCF::getSession()->unregister('__twitterInit');
                        if (!$initData) throw new IllegalLinkException();
                        
                        // validate oauth_token
@@ -99,6 +100,7 @@ class TwitterAuthAction extends AbstractAction {
                                }
                        }
                        else {
+                               WCF::getSession()->register('__3rdPartyProvider', 'twitter');
                                // save data for connection
                                if (WCF::getUser()->userID) {
                                        WCF::getSession()->register('__twitterUsername', $data['screen_name']);
index 3ac4af4c1af899222b0666e18f85b1546bdd6fb1..c4cb444f9f3d48b9c3e5a39cfaa74c13950fc57a 100644 (file)
@@ -113,7 +113,7 @@ class RegisterForm extends UserAddForm {
                        $this->useCaptcha = false;
                }
                
-               if (WCF::getSession()->getVar('__githubToken') || WCF::getSession()->getVar('__twitterData') || WCF::getSession()->getVar('__facebookData') || WCF::getSession()->getVar('__googleData')) {
+               if (WCF::getSession()->getVar('__3rdPartyProvider')) {
                        $this->isExternalAuthentication = true;
                }
        }
@@ -294,89 +294,96 @@ class RegisterForm extends UserAddForm {
                
                $avatarURL = '';
                if ($this->isExternalAuthentication) {
-                       // GitHub
-                       if (WCF::getSession()->getVar('__githubData')) {
-                               $githubData = WCF::getSession()->getVar('__githubData');
-                               
-                               $this->additionalFields['authData'] = 'github:'.WCF::getSession()->getVar('__githubToken');
-                               
-                               WCF::getSession()->unregister('__githubData');
-                               WCF::getSession()->unregister('__githubToken');
-                               
-                               if (WCF::getSession()->getVar('__email') && WCF::getSession()->getVar('__email') == $this->email) {
-                                       $registerVia3rdParty = true;
-                               }
-                               
-                               if (isset($githubData['bio'])) $saveOptions[User::getUserOptionID('aboutMe')] = $githubData['bio'];
-                               if (isset($githubData['location'])) $saveOptions[User::getUserOptionID('location')] = $githubData['location'];
-                       }
-                       
-                       // Twitter
-                       if (WCF::getSession()->getVar('__twitterData')) {
-                               $twitterData = WCF::getSession()->getVar('__twitterData');
-                               $this->additionalFields['authData'] = 'twitter:'.$twitterData['user_id'];
-                               
-                               WCF::getSession()->unregister('__twitterData');
-                               
-                               if (isset($twitterData['description'])) $saveOptions[User::getUserOptionID('aboutMe')] = $twitterData['description'];
-                               if (isset($twitterData['location'])) $saveOptions[User::getUserOptionID('location')] = $twitterData['location'];
-                       }
-                       
-                       // Facebook
-                       if (WCF::getSession()->getVar('__facebookData')) {
-                               $facebookData = WCF::getSession()->getVar('__facebookData');
-                               $this->additionalFields['authData'] = 'facebook:'.$facebookData['id'];
-                               
-                               WCF::getSession()->unregister('__facebookData');
-                               
-                               if ($facebookData['email'] == $this->email) {
-                                       $registerVia3rdParty = true;
-                               }
-                               
-                               $saveOptions[User::getUserOptionID('gender')] = ($facebookData['gender'] == 'male' ? UserProfile::GENDER_MALE : UserProfile::GENDER_FEMALE);
-                               
-                               if (isset($facebookData['birthday'])) {
-                                       list($month, $day, $year) = explode('/', $facebookData['birthday']);
-                                       $saveOptions[User::getUserOptionID('birthday')] = $year.'-'.$month.'-'.$day;
-                               }
-                               if (isset($facebookData['bio'])) $saveOptions[User::getUserOptionID('aboutMe')] = $facebookData['bio'];
-                               if (isset($facebookData['location'])) $saveOptions[User::getUserOptionID('location')] = $facebookData['location']['name'];
-                               if (isset($facebookData['website'])) {
-                                       if (!Regex::compile('^https?://')->match($facebookData['website'])) {
-                                               $facebookData['website'] = 'http://' . $facebookData['website'];
+                       switch (WCF::getSession()->getVar('__3rdPartyProvider')) {
+                               case 'github':
+                                       // GitHub
+                                       if (WCF::getSession()->getVar('__githubData')) {
+                                               $githubData = WCF::getSession()->getVar('__githubData');
+                                               
+                                               $this->additionalFields['authData'] = 'github:'.WCF::getSession()->getVar('__githubToken');
+                                               
+                                               WCF::getSession()->unregister('__githubData');
+                                               WCF::getSession()->unregister('__githubToken');
+                                               
+                                               if (WCF::getSession()->getVar('__email') && WCF::getSession()->getVar('__email') == $this->email) {
+                                                       $registerVia3rdParty = true;
+                                               }
+                                               
+                                               if (isset($githubData['bio'])) $saveOptions[User::getUserOptionID('aboutMe')] = $githubData['bio'];
+                                               if (isset($githubData['location'])) $saveOptions[User::getUserOptionID('location')] = $githubData['location'];
                                        }
-                                       
-                                       $saveOptions[User::getUserOptionID('homepage')] = $facebookData['website'];
-                               }
-                               
-                               // avatar
-                               if (isset($facebookData['picture']) && !$facebookData['picture']['data']['is_silhouette']) {
-                                       $avatarURL = $facebookData['picture']['data']['url'];
-                               }
-                       }
-                       
-                       // Google Plus
-                       if (WCF::getSession()->getVar('__googleData')) {
-                               $googleData = WCF::getSession()->getVar('__googleData');
-                               $this->additionalFields['authData'] = 'google:'.$googleData['id'];
-                               
-                               WCF::getSession()->unregister('__googleData');
-                               
-                               if (isset($googleData['email']) && $googleData['email'] == $this->email) {
-                                       $registerVia3rdParty = true;
-                               }
-                               
-                               if (isset($googleData['gender'])) {
-                                       switch ($googleData['gender']) {
-                                               case 'male':
-                                                       $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_MALE;
-                                               break;
-                                               case 'female':
-                                                       $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_FEMALE;
-                                               break;
+                               break;
+                               case 'twitter':
+                                       // Twitter
+                                       if (WCF::getSession()->getVar('__twitterData')) {
+                                               $twitterData = WCF::getSession()->getVar('__twitterData');
+                                               $this->additionalFields['authData'] = 'twitter:'.$twitterData['user_id'];
+                                               
+                                               WCF::getSession()->unregister('__twitterData');
+                                               
+                                               if (isset($twitterData['description'])) $saveOptions[User::getUserOptionID('aboutMe')] = $twitterData['description'];
+                                               if (isset($twitterData['location'])) $saveOptions[User::getUserOptionID('location')] = $twitterData['location'];
+                                       }
+                               break;
+                               case 'facebook':
+                                       // Facebook
+                                       if (WCF::getSession()->getVar('__facebookData')) {
+                                               $facebookData = WCF::getSession()->getVar('__facebookData');
+                                               $this->additionalFields['authData'] = 'facebook:'.$facebookData['id'];
+                                               
+                                               WCF::getSession()->unregister('__facebookData');
+                                               
+                                               if ($facebookData['email'] == $this->email) {
+                                                       $registerVia3rdParty = true;
+                                               }
+                                               
+                                               $saveOptions[User::getUserOptionID('gender')] = ($facebookData['gender'] == 'male' ? UserProfile::GENDER_MALE : UserProfile::GENDER_FEMALE);
+                                               
+                                               if (isset($facebookData['birthday'])) {
+                                                       list($month, $day, $year) = explode('/', $facebookData['birthday']);
+                                                       $saveOptions[User::getUserOptionID('birthday')] = $year.'-'.$month.'-'.$day;
+                                               }
+                                               if (isset($facebookData['bio'])) $saveOptions[User::getUserOptionID('aboutMe')] = $facebookData['bio'];
+                                               if (isset($facebookData['location'])) $saveOptions[User::getUserOptionID('location')] = $facebookData['location']['name'];
+                                               if (isset($facebookData['website'])) {
+                                                       if (!Regex::compile('^https?://')->match($facebookData['website'])) {
+                                                               $facebookData['website'] = 'http://' . $facebookData['website'];
+                                                       }
+                                                       
+                                                       $saveOptions[User::getUserOptionID('homepage')] = $facebookData['website'];
+                                               }
+                                               
+                                               // avatar
+                                               if (isset($facebookData['picture']) && !$facebookData['picture']['data']['is_silhouette']) {
+                                                       $avatarURL = $facebookData['picture']['data']['url'];
+                                               }
+                                       }
+                               break;
+                               case 'google':
+                                       // Google Plus
+                                       if (WCF::getSession()->getVar('__googleData')) {
+                                               $googleData = WCF::getSession()->getVar('__googleData');
+                                               $this->additionalFields['authData'] = 'google:'.$googleData['id'];
+                                               
+                                               WCF::getSession()->unregister('__googleData');
+                                               
+                                               if (isset($googleData['email']) && $googleData['email'] == $this->email) {
+                                                       $registerVia3rdParty = true;
+                                               }
+                                               
+                                               if (isset($googleData['gender'])) {
+                                                       switch ($googleData['gender']) {
+                                                               case 'male':
+                                                                       $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_MALE;
+                                                               break;
+                                                               case 'female':
+                                                                       $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_FEMALE;
+                                                               break;
+                                                       }
+                                               }
+                                               if (isset($googleData['birthday'])) $saveOptions[User::getUserOptionID('birthday')] = $googleData['birthday'];
                                        }
-                               }
-                               if (isset($googleData['birthday'])) $saveOptions[User::getUserOptionID('birthday')] = $googleData['birthday'];
+                               break;
                        }
                        
                        // create fake password