From f5f2f4080bc5f29b8b4af5dd688589cd9828cc66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 8 Aug 2013 22:02:31 +0200 Subject: [PATCH] Remember the last 3rdParty provider used --- com.woltlab.wcf/templates/register.tpl | 10 +- .../lib/action/FacebookAuthAction.class.php | 2 + .../lib/action/GithubAuthAction.class.php | 2 + .../lib/action/GoogleAuthAction.class.php | 3 + .../lib/action/TwitterAuthAction.class.php | 2 + .../files/lib/form/RegisterForm.class.php | 171 +++++++++--------- 6 files changed, 99 insertions(+), 91 deletions(-) diff --git a/com.woltlab.wcf/templates/register.tpl b/com.woltlab.wcf/templates/register.tpl index 5146e95614..075a8061d6 100644 --- a/com.woltlab.wcf/templates/register.tpl +++ b/com.woltlab.wcf/templates/register.tpl @@ -50,15 +50,7 @@ {include file='userNotice'} {if $isExternalAuthentication} - {if $__wcf->session->getVar('__githubToken')} -

{lang}wcf.user.3rdparty.github.register{/lang}

- {elseif $__wcf->session->getVar('__twitterData')} -

{lang}wcf.user.3rdparty.twitter.register{/lang}

- {elseif $__wcf->session->getVar('__facebookData')} -

{lang}wcf.user.3rdparty.facebook.register{/lang}

- {elseif $__wcf->session->getVar('__googleData')} -

{lang}wcf.user.3rdparty.google.register{/lang}

- {/if} +

{lang}wcf.user.3rdparty.{$__wcf->session->getVar('__3rdPartyProvider')}.register{/lang}

{/if} {if $errorField} diff --git a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php index aeb1ded517..aae1f7956e 100644 --- a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php @@ -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']); diff --git a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php index 7ab58ed56f..ff0f99cd61 100644 --- a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php @@ -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']); diff --git a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php index 1a553eaf7d..04115e68b1 100644 --- a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php @@ -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']); diff --git a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php index 4dbe76a28d..5d17492bb6 100644 --- a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php @@ -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']); diff --git a/wcfsetup/install/files/lib/form/RegisterForm.class.php b/wcfsetup/install/files/lib/form/RegisterForm.class.php index 3ac4af4c1a..c4cb444f9f 100644 --- a/wcfsetup/install/files/lib/form/RegisterForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterForm.class.php @@ -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 -- 2.20.1