38 parent::__construct(
'OATH',
'oathauth-enable',
false );
40 $this->OATHRepository = $repository;
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/"
110 . rawurlencode( $label )
112 . rawurlencode( $secret )
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',
133 'default' => $qrcodeElement,
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', ]
182 $key = $this->
getRequest()->getSessionData(
'oathauth_key' );
184 if ( $key->isScratchToken( $formData[
'token'] ) ) {
186 return [
'oathauth-noscratchforvalidation' ];
188 if ( !$key->verifyToken( $formData[
'token'], $this->OATHUser ) ) {
189 return [
'oathauth-failedtovalidateoath' ];
192 $this->
getRequest()->setSessionData(
'oathauth_key',
null );
194 $this->OATHRepository->persist( $this->
OATHUser );
200 $this->
getOutput()->addWikiMsg(
'oathauth-validatedoath' );
210 foreach ( $resources as $resource ) {
211 $resourceList .= Html::rawElement(
'li', [], Html::rawElement(
'kbd', [], $resource ) );
213 return Html::rawElement(
'ul', [], $resourceList );
237 return array_map( [ $this,
'tokenFormatterFunction' ], $key->
getScratchTokens() );
247 return implode(
' ', str_split( $token, 4 ) );
Special page which uses an HTMLForm to handle processing.
string $par
The sub-page of the special page.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
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 seperated 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.
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.
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,...
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user