MediaWiki  1.34.0
TOTPDisableForm.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use Message;
8 use MWException;
9 
14  public function onSuccess() {
15  $this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
16  }
17 
18  protected function getDescriptors() {
19  return [
20  'token' => [
21  'type' => 'text',
22  'label-message' => 'oathauth-entertoken',
23  'name' => 'token',
24  'required' => true,
25  'autofocus' => true,
26  'dir' => 'ltr',
27  'autocomplete' => false,
28  'spellcheck' => false,
29  ]
30  ];
31  }
32 
38  public function onSubmit( array $formData ) {
39  // Don't increase pingLimiter, just check for limit exceeded.
40  if ( $this->oathUser->getUser()->pingLimiter( 'badoath', 0 ) ) {
41  // Arbitrary duration given here
42  LoggerFactory::getInstance( 'authentication' )->info(
43  'OATHAuth {user} rate limited while disabling 2FA from {clientip}', [
44  'user' => $this->getUser()->getName(),
45  'clientip' => $this->getRequest()->getIP(),
46  ]
47  );
48  return [ 'oathauth-throttled', Message::durationParam( 60 ) ];
49  }
50 
51  $module = $this->oathUser->getModule();
52  if ( $module instanceof TOTP ) {
53  if ( !$module->verify( $this->oathUser, [ 'token' => $formData['token'] ] ) ) {
54  LoggerFactory::getInstance( 'authentication' )->info(
55  'OATHAuth {user} failed to provide a correct token while disabling 2FA from {clientip}', [
56  'user' => $this->getUser()->getName(),
57  'clientip' => $this->getRequest()->getIP(),
58  ]
59  );
60  return [ 'oathauth-failedtovalidateoath' ];
61  }
62  }
63 
64  $this->oathUser->setKeys();
65  $this->oathRepo->remove( $this->oathUser, $this->getRequest()->getIP() );
66 
67  return true;
68  }
69 }
MediaWiki\Extension\OATHAuth\HTMLForm\TOTPDisableForm\onSuccess
onSuccess()
Add content to output when operation was successful.
Definition: TOTPDisableForm.php:14
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
MediaWiki\Extension\OATHAuth\IModule\verify
verify(OATHUser $user, array $data)
Run the validation.
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm
Definition: OATHAuthOOUIHTMLForm.php:17
MediaWiki\Extension\OATHAuth\HTMLForm\TOTPDisableForm
Definition: TOTPDisableForm.php:10
MediaWiki\Extension\OATHAuth\HTMLForm\TOTPDisableForm\getDescriptors
getDescriptors()
Definition: TOTPDisableForm.php:18
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:71
Message
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
MediaWiki\Extension\OATHAuth\Module\TOTP
Definition: TOTP.php:18
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:112
MediaWiki\Extension\OATHAuth\HTMLForm
Definition: IManageForm.php:3
MediaWiki\Extension\OATHAuth\HTMLForm\TOTPDisableForm\onSubmit
onSubmit(array $formData)
Definition: TOTPDisableForm.php:38
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\$module
IModule $module
Definition: OATHAuthOOUIHTMLForm.php:29
MediaWiki\Extension\OATHAuth\HTMLForm\IManageForm
Definition: IManageForm.php:10