mediawiki-extensions-OATHAuth/special/SpecialOATHDisable.php
Bryan Davis a6b60d2465 Apply rate limits to all token verifications
Extend the token validation failure checks introduced in I4884f6e to the
other interactions where OATHAuthKey::verifyToken is used.

Depends-On: Ia3add8bbbab0307f036e9b77e752c382da3a0d04
Change-Id: Icbe5cdf561c683dc971a099d61cedff311b26b43
2016-10-07 17:24:32 -07:00

119 lines
2.5 KiB
PHP

<?php
/**
* Special page to display key information to the user
*
* @ingroup Extensions
*/
class SpecialOATHDisable extends FormSpecialPage {
/** @var OATHUserRepository */
private $OATHRepository;
/** @var OATHUser */
private $OATHUser;
/**
* Initialize the OATH user based on the current local User object in the context
*
* @param OATHUserRepository $repository
* @param OATHUser $user
*/
public function __construct( OATHUserRepository $repository, OATHUser $user ) {
parent::__construct( 'OATH', '', false );
$this->OATHRepository = $repository;
$this->OATHUser = $user;
}
public function doesWrites() {
return true;
}
/**
* Set the page title and add JavaScript RL modules
*
* @param HTMLForm $form
*/
public function alterForm( HTMLForm $form ) {
$form->setMessagePrefix( 'oathauth' );
$form->setWrapperLegend( false );
$form->getOutput()->setPageTitle( $this->msg( 'oathauth-disable' ) );
}
/**
* @return string
*/
protected function getDisplayFormat() {
return 'vform';
}
/**
* @return bool
*/
public function requiresUnblock() {
return false;
}
/**
* Require users to be logged in
*
* @param User $user
*
* @return bool|void
*/
protected function checkExecutePermissions( User $user ) {
parent::checkExecutePermissions( $user );
$this->requireLogin();
}
/**
* @return array[]
*/
protected function getFormFields() {
return [
'token' => [
'type' => 'text',
'label-message' => 'oathauth-entertoken',
'name' => 'token',
],
'returnto' => [
'type' => 'hidden',
'default' => $this->getRequest()->getVal( 'returnto' ),
'name' => 'returnto',
],
'returntoquery' => [
'type' => 'hidden',
'default' => $this->getRequest()->getVal( 'returntoquery' ),
'name' => 'returntoquery',
]
];
}
/**
* @param array $formData
*
* @return array|bool
*/
public function onSubmit( array $formData ) {
// Don't increase pingLimiter, just check for limit exceeded.
if ( $this->OATHUser->getUser()->pingLimiter( 'badoath', 0 ) ) {
// Arbitrary duration given here
return [ 'oauthauth-throttled', Message::durationParam( 60 ) ];
}
if ( !$this->OATHUser->getKey()->verifyToken( $formData['token'], $this->OATHUser ) ) {
return [ 'oathauth-failedtovalidateoauth' ];
}
$this->OATHUser->setKey( null );
$this->OATHRepository->remove( $this->OATHUser );
return true;
}
public function onSuccess() {
$this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
$this->getOutput()->returnToMain();
}
}