MediaWiki REL1_33
SpecialOATHDisable.php
Go to the documentation of this file.
1<?php
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 public function execute( $par ) {
89 $this->getOutput()->disallowUserJs();
90 parent::execute( $par );
91 }
92
96 protected function getFormFields() {
97 return [
98 'token' => [
99 'type' => 'text',
100 'label-message' => 'oathauth-entertoken',
101 'name' => 'token',
102 'required' => true,
103 'autofocus' => true,
104 ],
105 'returnto' => [
106 'type' => 'hidden',
107 'default' => $this->getRequest()->getVal( 'returnto' ),
108 'name' => 'returnto',
109 ],
110 'returntoquery' => [
111 'type' => 'hidden',
112 'default' => $this->getRequest()->getVal( 'returntoquery' ),
113 'name' => 'returntoquery',
114 ]
115 ];
116 }
117
123 public function onSubmit( array $formData ) {
124 // Don't increase pingLimiter, just check for limit exceeded.
125 if ( $this->OATHUser->getUser()->pingLimiter( 'badoath', 0 ) ) {
126 // Arbitrary duration given here
127 \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' )->info(
128 'OATHAuth {user} rate limited while disabling 2FA from {clientip}', [
129 'user' => $this->getUser()->getName(),
130 'clientip' => $this->getRequest()->getIP(),
131 ]
132 );
133 return [ 'oathauth-throttled', Message::durationParam( 60 ) ];
134 }
135
136 if ( !$this->OATHUser->getKey()->verifyToken( $formData['token'], $this->OATHUser ) ) {
137 \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' )->info(
138 'OATHAuth {user} failed to provide a correct token while disabling 2FA from {clientip}', [
139 'user' => $this->getUser()->getName(),
140 'clientip' => $this->getRequest()->getIP(),
141 ]
142 );
143 return [ 'oathauth-failedtovalidateoath' ];
144 }
145
146 $this->OATHUser->setKey( null );
147 $this->OATHRepository->remove( $this->OATHUser, $this->getRequest()->getIP() );
148
149 return true;
150 }
151
152 public function onSuccess() {
153 $this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
154 $this->getOutput()->returnToMain();
155 }
156}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition HTMLForm.php:133
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition OATHUser.php:24
getKey()
Get the key associated with this user.
Definition OATHUser.php:71
setKey(OATHAuthKey $key=null)
Set the key associated with this user.
Definition OATHUser.php:80
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
checkExecutePermissions(User $user)
Require users to be logged in.
__construct(OATHUserRepository $repository, OATHUser $user)
Initialize the OATH user based on the current local User object in the context.
onSubmit(array $formData)
doesWrites()
Indicates whether this special page may perform database writes.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
alterForm(HTMLForm $form)
Set the page title and add JavaScript RL modules.
OATHUserRepository $OATHRepository
getName()
Get the name of this Special Page.
getOutput()
Get the OutputPage being used for this instance.
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
getUser()
Shortcut to get the User executing this instance.
msg( $key)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
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))