MediaWiki  1.33.0
SpecialOATHDisable.php
Go to the documentation of this file.
1 <?php
26  private $OATHRepository;
27 
29  private $OATHUser;
30 
37  public function __construct( OATHUserRepository $repository, OATHUser $user ) {
38  parent::__construct( 'OATH', '', false );
39  $this->OATHRepository = $repository;
40  $this->OATHUser = $user;
41  }
42 
43  public function doesWrites() {
44  return true;
45  }
46 
52  public function alterForm( HTMLForm $form ) {
53  $form->setMessagePrefix( 'oathauth' );
54  $form->setWrapperLegend( false );
55  $form->getOutput()->setPageTitle( $this->msg( 'oathauth-disable' ) );
56  }
57 
61  protected function getDisplayFormat() {
62  return 'ooui';
63  }
64 
68  public function requiresUnblock() {
69  return false;
70  }
71 
79  protected function checkExecutePermissions( User $user ) {
80  parent::checkExecutePermissions( $user );
81 
82  $this->requireLogin();
83  }
84 
88  protected function getFormFields() {
89  return [
90  'token' => [
91  'type' => 'text',
92  'label-message' => 'oathauth-entertoken',
93  'name' => 'token',
94  'required' => true,
95  'autofocus' => true,
96  ],
97  'returnto' => [
98  'type' => 'hidden',
99  'default' => $this->getRequest()->getVal( 'returnto' ),
100  'name' => 'returnto',
101  ],
102  'returntoquery' => [
103  'type' => 'hidden',
104  'default' => $this->getRequest()->getVal( 'returntoquery' ),
105  'name' => 'returntoquery',
106  ]
107  ];
108  }
109 
115  public function onSubmit( array $formData ) {
116  // Don't increase pingLimiter, just check for limit exceeded.
117  if ( $this->OATHUser->getUser()->pingLimiter( 'badoath', 0 ) ) {
118  // Arbitrary duration given here
119  \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' )->info(
120  'OATHAuth {user} rate limited while disabling 2FA from {clientip}', [
121  'user' => $this->getUser()->getName(),
122  'clientip' => $this->getRequest()->getIP(),
123  ]
124  );
125  return [ 'oathauth-throttled', Message::durationParam( 60 ) ];
126  }
127 
128  if ( !$this->OATHUser->getKey()->verifyToken( $formData['token'], $this->OATHUser ) ) {
129  \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' )->info(
130  'OATHAuth {user} failed to provide a correct token while disabling 2FA from {clientip}', [
131  'user' => $this->getUser()->getName(),
132  'clientip' => $this->getRequest()->getIP(),
133  ]
134  );
135  return [ 'oathauth-failedtovalidateoath' ];
136  }
137 
138  $this->OATHUser->setKey( null );
139  $this->OATHRepository->remove( $this->OATHUser, $this->getRequest()->getIP() );
140 
141  return true;
142  }
143 
144  public function onSuccess() {
145  $this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
146  $this->getOutput()->returnToMain();
147  }
148 }
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
SpecialOATHDisable\onSubmit
onSubmit(array $formData)
Definition: SpecialOATHDisable.php:115
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
OATHUserRepository
Definition: OATHUserRepository.php:23
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
SpecialOATHDisable\$OATHRepository
OATHUserRepository $OATHRepository
Definition: SpecialOATHDisable.php:26
SpecialOATHDisable\alterForm
alterForm(HTMLForm $form)
Set the page title and add JavaScript RL modules.
Definition: SpecialOATHDisable.php:52
SpecialOATHDisable\requiresUnblock
requiresUnblock()
Definition: SpecialOATHDisable.php:68
FormSpecialPage
Special page which uses an HTMLForm to handle processing.
Definition: FormSpecialPage.php:31
SpecialOATHDisable\checkExecutePermissions
checkExecutePermissions(User $user)
Require users to be logged in.
Definition: SpecialOATHDisable.php:79
SpecialOATHDisable
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: SpecialOATHDisable.php:24
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:152
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:112
SpecialOATHDisable\__construct
__construct(OATHUserRepository $repository, OATHUser $user)
Initialize the OATH user based on the current local User object in the context.
Definition: SpecialOATHDisable.php:37
OATHUser
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: OATHUser.php:24
SpecialOATHDisable\getDisplayFormat
getDisplayFormat()
Definition: SpecialOATHDisable.php:61
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:735
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1563
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
OATHUser\getUser
getUser()
Definition: OATHUser.php:44
SpecialPage\requireLogin
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:339
SpecialOATHDisable\doesWrites
doesWrites()
Indicates whether this special page may perform database writes.
Definition: SpecialOATHDisable.php:43
SpecialOATHDisable\$OATHUser
OATHUser $OATHUser
Definition: SpecialOATHDisable.php:29
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:715
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1530
SpecialOATHDisable\getFormFields
getFormFields()
Definition: SpecialOATHDisable.php:88
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
OATHUser\setKey
setKey(OATHAuthKey $key=null)
Set the key associated with this user.
Definition: OATHUser.php:80
SpecialOATHDisable\onSuccess
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
Definition: SpecialOATHDisable.php:144
OATHUser\getKey
getKey()
Get the key associated with this user.
Definition: OATHUser.php:71
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:133