2014-05-22 07:33:40 +00:00
|
|
|
<?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;
|
|
|
|
}
|
|
|
|
|
2016-05-25 19:25:10 +00:00
|
|
|
public function doesWrites() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-22 07:33:40 +00:00
|
|
|
/**
|
|
|
|
* Set the page title and add JavaScript RL modules
|
|
|
|
*
|
|
|
|
* @param HTMLForm $form
|
|
|
|
*/
|
|
|
|
public function alterForm( HTMLForm $form ) {
|
|
|
|
$form->setMessagePrefix( 'oathauth' );
|
|
|
|
$form->setWrapperLegend( false );
|
2016-09-16 23:18:35 +00:00
|
|
|
$form->getOutput()->setPageTitle( $this->msg( 'oathauth-disable' ) );
|
2014-05-22 07:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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() {
|
2016-09-16 23:18:35 +00:00
|
|
|
return [
|
|
|
|
'token' => [
|
2014-05-22 07:33:40 +00:00
|
|
|
'type' => 'text',
|
|
|
|
'label-message' => 'oathauth-entertoken',
|
|
|
|
'name' => 'token',
|
2016-11-16 22:00:27 +00:00
|
|
|
'required' => true,
|
|
|
|
'autofocus' => true,
|
2016-09-16 23:18:35 +00:00
|
|
|
],
|
|
|
|
'returnto' => [
|
2014-05-22 07:33:40 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'default' => $this->getRequest()->getVal( 'returnto' ),
|
|
|
|
'name' => 'returnto',
|
2016-09-16 23:18:35 +00:00
|
|
|
],
|
|
|
|
'returntoquery' => [
|
2014-05-22 07:33:40 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'default' => $this->getRequest()->getVal( 'returntoquery' ),
|
|
|
|
'name' => 'returntoquery',
|
2016-09-16 23:18:35 +00:00
|
|
|
]
|
|
|
|
];
|
2014-05-22 07:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $formData
|
|
|
|
*
|
|
|
|
* @return array|bool
|
|
|
|
*/
|
|
|
|
public function onSubmit( array $formData ) {
|
2016-10-03 04:32:30 +00:00
|
|
|
// 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 ) ];
|
|
|
|
}
|
|
|
|
|
2014-05-22 07:33:40 +00:00
|
|
|
if ( !$this->OATHUser->getKey()->verifyToken( $formData['token'], $this->OATHUser ) ) {
|
2016-09-16 23:18:35 +00:00
|
|
|
return [ 'oathauth-failedtovalidateoauth' ];
|
2014-05-22 07:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->OATHUser->setKey( null );
|
|
|
|
$this->OATHRepository->remove( $this->OATHUser );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onSuccess() {
|
|
|
|
$this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
|
|
|
|
$this->getOutput()->returnToMain();
|
|
|
|
}
|
|
|
|
}
|