38 parent::__construct(
'OATH',
'oathauth-enable',
false );
54 $form->setMessagePrefix(
'oathauth' );
55 $form->setWrapperLegend(
false );
56 $form->getOutput()->setPageTitle( $this->
msg(
'oathauth-enable' ) );
57 $form->
getOutput()->addModules(
'ext.oath.showqrcode' );
58 $form->getOutput()->addModuleStyles(
'ext.oath.showqrcode.styles' );
83 parent::checkExecutePermissions( $user );
93 parent::execute(
$par );
100 $key = $this->
getRequest()->getSessionData(
'oathauth_key' );
102 if ( $key ===
null ) {
104 $this->
getRequest()->setSessionData(
'oathauth_key', $key );
107 $secret = $key->getSecret();
108 $label =
"{$this->OATHUser->getIssuer()}:{$this->OATHUser->getAccount()}";
109 $qrcodeUrl =
"otpauth://totp/"
116 $qrcodeElement = Html::element(
'div', [
117 'data-mw-qrcode-url' => $qrcodeUrl,
118 'class' =>
'mw-display-qrcode',
121 'style' =>
'width: 256px; height: 256px;'
127 'default' => $this->
msg(
'oathauth-step1-test' )->escaped(),
129 'section' =>
'step1',
135 'section' =>
'step2',
139 'label-message' =>
'oathauth-step2alt',
141 '<strong>' . $this->
msg(
'oathauth-account' )->escaped() .
'</strong><br/>'
143 .
'<strong>' . $this->
msg(
'oathauth-secret' )->escaped() .
'</strong><br/>'
146 'section' =>
'step2',
151 $this->
msg(
'oathauth-scratchtokens' )
154 'section' =>
'step3',
159 'label-message' =>
'oathauth-entertoken',
161 'section' =>
'step4',
165 'default' => $this->
getRequest()->getVal(
'returnto' ),
166 'name' =>
'returnto',
170 'default' => $this->
getRequest()->getVal(
'returntoquery' ),
171 'name' =>
'returntoquery',
183 $key = $this->
getRequest()->getSessionData(
'oathauth_key' );
185 if ( $key->isScratchToken( $formData[
'token'] ) ) {
187 \MediaWiki\Logger\LoggerFactory::getInstance(
'authentication' )->info(
188 'OATHAuth {user} attempted to enable 2FA using a scratch token from {clientip}', [
193 return [
'oathauth-noscratchforvalidation' ];
195 if ( !$key->verifyToken( $formData[
'token'], $this->OATHUser ) ) {
196 \MediaWiki\Logger\LoggerFactory::getInstance(
'authentication' )->info(
197 'OATHAuth {user} failed to provide a correct token while enabling 2FA from {clientip}', [
202 return [
'oathauth-failedtovalidateoath' ];
205 $this->
getRequest()->setSessionData(
'oathauth_key',
null );
213 $this->
getOutput()->addWikiMsg(
'oathauth-validatedoath' );
223 foreach ( $resources as $resource ) {
224 $resourceList .= Html::rawElement(
'li', [], Html::rawElement(
'kbd', [], $resource ) );
226 return Html::rawElement(
'ul', [], $resourceList );
260 return implode(
' ',
str_split( $token, 4 ) );
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.
Class representing a two-factor key.
static newFromRandom()
Make a new key from random values.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
setKey(OATHAuthKey $key=null)
Set the key associated with this user.
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.
onSubmit(array $formData)
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
getSecretForDisplay(OATHAuthKey $key)
Retrieve the current secret for display purposes.
__construct(OATHUserRepository $repository, OATHUser $user)
Initialize the OATH user based on the current local User object in the context.
tokenFormatterFunction( $token)
Formats a key or scratch token by creating groups of 4 separated by space characters.
createResourceList( $resources)
OATHUserRepository $OATHRepository
alterForm(HTMLForm $form)
Set the page title and add JavaScript RL modules.
doesWrites()
Indicates whether this special page may perform database writes.
getScratchTokensForDisplay(OATHAuthKey $key)
Retrieve current scratch tokens for display purposes.
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,...
return true to allow those checks to and false if checking is done & $user
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))