Florianschmidtwelzow has uploaded a new change for review. https://gerrit.wikimedia.org/r/226577
Change subject: Enable to link a new Google account with an existing wiki account ...................................................................... Enable to link a new Google account with an existing wiki account If the user isn't logged in so far and tries to login with Google, he now can choose "I already have a {{SITENAME}} account" to link the existing MediaWiki account with the new Google account without to abort the login process, login with the wiki account, go to the special page and link it then. Bug: T106606 Change-Id: I2380d7e6031434fa87a1dd642ebf5a7adb493994 --- M GoogleLogin.php M i18n/en.json M i18n/qqq.json M includes/GoogleLogin.body.php M includes/GoogleLogin.hooks.php M includes/specials/SpecialGoogleLogin.php 6 files changed, 65 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GoogleLogin refs/changes/77/226577/1 diff --git a/GoogleLogin.php b/GoogleLogin.php index 40b908d..ec1e8fc 100644 --- a/GoogleLogin.php +++ b/GoogleLogin.php @@ -79,6 +79,7 @@ $wgHooks['RecentChange_save'][] = 'GoogleLoginHooks::onRecentChange_save'; $wgHooks['ListDefinedTags'][] = 'GoogleLoginHooks::onListDefinedAndActiveTags'; $wgHooks['ChangeTagsListActive'][] = 'GoogleLoginHooks::onListDefinedAndActiveTags'; + $wgHooks['LoginFormValidErrorMessages'][] = 'GoogleLoginHooks::onLoginFormValidErrorMessages'; // ResourceLoader modules // path template diff --git a/i18n/en.json b/i18n/en.json index 9ec00cc..278bd41 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -50,7 +50,7 @@ "googlelogin-form-merge-title": "Link user account", "googlelogin-form-logout": "Login with another Google account", "googlelogin-form-backlink": "Back to Google login", - "googlelogin-form-create": "Create account", + "googlelogin-form-next": "Next", "googlelogin-form-merge": "Link Google to wiki account", "googlelogin-form-unlink": "Unlink Google from wiki account", "googlelogin-email": "Email address", @@ -59,6 +59,8 @@ "googlelogin-information-body": "In the following table you find information about your Google account and if it is linked to a wiki account or not.", "googlelogin-linkstatus": "Link status", "googlelogin-linked": "linked", + "googlelogin-login-already-registered": "I already have a {{SITENAME}} account", + "googlelogin-login-merge-warning": "Please login to link your Google account with your {{SITENAME}} account.", "googlelogin-or": "or", "googlelogin-unlinked": "not linked", "googlelogin-link-other": "Your Google account is already linked to another user. Please unlink the connection or contact an administrator, if you have no other wiki account.", diff --git a/i18n/qqq.json b/i18n/qqq.json index f13e5b4..deb577b 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -53,7 +53,7 @@ "googlelogin-form-merge-title": "Title of button to merge the wiki and Google account.", "googlelogin-form-logout": "Title of button to choose another Google account to merge/create (to/a new) wiki account. (logout the currently Google account in wiki)", "googlelogin-form-backlink": "Used as link text on subpages of Special:GoogleLogin to go back to Main special page [[Special:GoogleLogin]].", - "googlelogin-form-create": "Title of button to create a new user account on form to choose the username.\n{{Identical|Create account}}", + "googlelogin-form-next": "Next button", "googlelogin-form-merge": "Title of button to merge the wikiaccount and Google account, if the user is logged into a wikiaccount (and not connected to a Google account) and navigates to Special:GoogleLogin.", "googlelogin-form-unlink": "Title of button to unlink the connection between the wiki user account and Google account.", "googlelogin-email": "Title of value email address in account information table on [[Special:GoogleLogin]].\n{{Identical|E-mail address}}", @@ -61,6 +61,8 @@ "googlelogin-information-title": "Title of fieldset containing the table with account information.\n{{Identical|Account information}}", "googlelogin-information-body": "Information text above account information table, that the following table contains information about the Google and wiki account and the link status (linked, not linked).", "googlelogin-linkstatus": "Title of value Link status in account information table on Special:GoogleLogin (is wiki account linked to Google account?).", + "googlelogin-login-already-registered": "Option for the user when the Google account isn't linked with any wiki account yet, to use an already existing account, instead of creating a new one.", + "googlelogin-login-merge-warning": "Warning message to explain the user, why he is redirected to the login page (to login and link the wiki account with the Google account).", "googlelogin-linked": "Google and wiki account are linked. (Used in account information table)", "googlelogin-or": "'or' to show as seperator on login page (GoogleLogin 'or' MediaWiki Login).\n\nPreceded by {{msg-mw|Googlelogin}} button.\n\nFollowed by the standard login form.\n{{Identical|Or}}", "googlelogin-unlinked": "Google and wiki account aren't linked. (Used in account information table)", diff --git a/includes/GoogleLogin.body.php b/includes/GoogleLogin.body.php index e606027..4bd2065 100644 --- a/includes/GoogleLogin.body.php +++ b/includes/GoogleLogin.body.php @@ -480,6 +480,8 @@ empty( $data['ChooseName'] ) ) { return wfMessage( 'googlelogin-form-choosename-error' )->text(); + } elseif ( $data['ChooseOwn'] === 'wpAlreadyRegistered' ) { + return true; } else { if ( $data['ChooseName'] == 'wpOwn' && empty( $data['ChooseOwn'] ) ) { return wfMessage( 'googlelogin-form-chooseown-error' )->text(); @@ -524,10 +526,15 @@ public static function getLoginCreateForm( &$tpl, $login = true ) { $glConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'googlelogin' ); + $request = $tpl->getSkin()->getRequest(); $out = $tpl->getSkin()->getOutput(); // actual styling doesn't work on create account page, there's already a nice div using the space $showRight = $login ? $glConfig->get( 'GLShowRight' ) : false; + // disallow login with google, if the user has to login to link the google account with the wiki account + if ( $request->getVal( 'loginmerge' ) === '1' ) { + return; + } // add default css module $modules = array( 'ext.GoogleLogin.style' ); // if the administrator requested to show the form at the right side, diff --git a/includes/GoogleLogin.hooks.php b/includes/GoogleLogin.hooks.php index 48a13ee..621712b 100644 --- a/includes/GoogleLogin.hooks.php +++ b/includes/GoogleLogin.hooks.php @@ -151,4 +151,13 @@ $tags[] = 'googlelogin'; return true; } + + /** + * Adds a custom valid error message to the login page, used when the user want + * to link an account with the google account and isn't logged in so far. + * @param array $messages Already added messages + */ + public static function onLoginFormValidErrorMessages( array &$messages ) { + $messages[] = 'googlelogin-login-merge-warning'; + } } diff --git a/includes/specials/SpecialGoogleLogin.php b/includes/specials/SpecialGoogleLogin.php index 1ce4c72..4577e02 100644 --- a/includes/specials/SpecialGoogleLogin.php +++ b/includes/specials/SpecialGoogleLogin.php @@ -212,7 +212,9 @@ private function createGoogleUserForm( $userInfo, $db ) { $request = $this->getRequest(); $this->getOutput()->setPageTitle( $this->msg( 'googlelogin-form-choosename-title' )->text() ); - $names = array(); + $names = array( + $this->msg( 'googlelogin-login-already-registered' )->text() => 'wpAlreadyRegistered' + ); if ( GoogleLogin::isValidUsername( $userInfo['displayName'] ) ) { $names[$userInfo['displayName']] = 'wpDisplayName'; } @@ -238,7 +240,7 @@ $htmlForm->addHiddenField( 'action', 'Create' ); $htmlForm->addHiddenField( 'wpSecureHash', $this->mGoogleLogin->getRequestToken() ); $htmlForm->setWrapperLegendMsg( 'googlelogin-form-choosename' ); - $htmlForm->setSubmitText( $this->msg( 'googlelogin-form-create' )->text() ); + $htmlForm->setSubmitText( $this->msg( 'googlelogin-form-next' )->text() ); $htmlForm->setAction( $this->getPageTitle( 'Create' )->getLocalUrl() ); $htmlForm->setSubmitCallback( array( 'GoogleLogin', 'submitChooseName' ) ); @@ -318,15 +320,45 @@ $out->addWikiMsg( 'googlelogin-parerror' ); break; case 'Create': + if ( !$this->mGoogleLogin->isValidRequest() ) { + $this->createError( 'Token failure' ); + } // Handles the creation of a new wikiuser, but before: check, if no-one changed the username // and is still valid // Finish with the creation of connection between user id and google id - if ( $this->mGoogleLogin->isValidRequest() && $this->mGoogleLogin->isCreateAllowed() ) { + if ( $this->mGoogleLogin->isCreateAllowed() ) { $userName = ''; - if ( $request->getVal( 'wpChooseName' ) === null ) { + $chooseOwn = $request->getVal( 'wpChooseName' ); + if ( $chooseOwn === null ) { $this->createGoogleUserForm( $userInfo, $db ); } - if ( $request->getVal( 'wpChooseName' ) === 'wpOwn' ) { + // if the user selected the "i have an account" option, redirect to the login page + // with all required parameter + if ( $chooseOwn === 'wpAlreadyRegistered' ) { + // target page query + $query = array( + // to redirect the user to the link function directly after login + 'action' => 'Merge', + // with this parameter, the user doesn't get an error message because of the + // missing form token + 'fromLogin' => 1 + ); + + $out->redirect( + // redirect to Special:UserLogin + SpecialPage::getTitleFor( 'UserLogin' )->getFullUrl( array( + 'returnto' => 'Special:GoogleLogin', + 'returntoquery' => wfArrayToCgi( $query ), + // this parameter disables the "Login with Google" option, it would be + // pointless here + 'loginmerge' => 1, + // a custom warning message, if you change the mesasge key, change it in + // GoogleLoginHooks::onLoginFormValidErrorMessages, too + 'warning' => 'googlelogin-login-merge-warning', + ) ) + ); + } + if ( $chooseOwn === 'wpOwn' ) { if ( $request->getVal( 'wpChooseOwn' ) === '' ) { $this->createGoogleUserForm( $userInfo, $db ); } elseif( @@ -338,14 +370,14 @@ $userName = $request->getVal( 'wpChooseOwn' ); } } - if ( $request->getVal( 'wpChooseName' ) === 'wpDisplayName' ) { + if ( $chooseOwn === 'wpDisplayName' ) { if ( GoogleLogin::isValidUsername( $userInfo['displayName'] ) ) { $userName = $userInfo['displayName']; } else { $this->createGoogleUserForm( $userInfo, $db ); } } - if ( $request->getVal( 'wpChooseName' ) === 'wpGivenName' ) { + if ( $chooseOwn === 'wpGivenName' ) { if ( GoogleLogin::isValidUsername( $userInfo['name']['givenName'] ) ) { $userName = $userInfo['name']['givenName']; } else { @@ -385,9 +417,7 @@ } } } else { - $this->createError( - ($this->mGoogleLogin->isCreateAllowed() ? 'Token failure' : 'not allowed') - ); + $this->createError( 'not allowed' ); } break; case 'Merge': @@ -403,6 +433,8 @@ $this->createError( 'Database error' ); } } + } elseif ( $request->getBool( 'fromLogin' ) === true ) { + $this->createOrMerge( $userInfo, $db ); } else { $this->createError( 'Token failure' ); } -- To view, visit https://gerrit.wikimedia.org/r/226577 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2380d7e6031434fa87a1dd642ebf5a7adb493994 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GoogleLogin Gerrit-Branch: master Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits