mediawiki-extensions-OATHAuth/special/SpecialOATH.php
Tyler Anthony Romeo 1a8006317d Move token login to separate page
Rather than have an extraneous form on the login page,
move the token input to a separate page. The actual
logic for logging in is identical, the only difference
is that the token is added to the form data on a second
page request.

Bug: 53195
Change-Id: I39859cc59f1811de42b72f6167d332ea48812f97
2016-03-29 16:02:54 -07:00

48 lines
1.2 KiB
PHP

<?php
/**
* Proxy page that redirects to the proper OATH special page
*/
class SpecialOATH extends ProxySpecialPage {
/**
* If the user already has OATH enabled, show them a page to disable
* If the user has OATH disabled, show them a page to enable
*
* @return SpecialOATHDisable|SpecialOATHEnable|SpecialOATHLogin|SpecialPage
*/
protected function getTargetPage() {
$repo = OATHAuthHooks::getOATHUserRepository();
/** @var array $sessionUser */
$loginInfo = $this->getRequest()->getSessionData( 'oath_login' );
/** @var SpecialOATHDisable|SpecialOATHEnable|SpecialOATHLogin|SpecialPage $page */
$page = null;
if ( $this->getUser()->isAnon() && $loginInfo !== null ) {
// User is anonymous, so they are logging in
$page = new SpecialOATHLogin(
$repo->findByUser(User::newFromName( $loginInfo['wpName'] ) ),
new DerivativeRequest(
$this->getRequest(),
$loginInfo,
$this->getRequest()->wasPosted()
)
);
} else {
$user = $repo->findByUser( $this->getUser() );
if ( $user->getKey() === null ) {
$page = new SpecialOATHEnable( $repo, $user );
} else {
$page = new SpecialOATHDisable( $repo, $user );
}
}
return $page;
}
protected function getGroupName() {
return 'oath';
}
}