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 );
92 $key = $this->
getRequest()->getSessionData(
'oathauth_key' );
94 if ( $key ===
null ) {
96 $this->
getRequest()->setSessionData(
'oathauth_key', $key );
99 $secret = $key->getSecret();
100 $label =
"{$this->OATHUser->getIssuer()}:{$this->OATHUser->getAccount()}";
101 $qrcodeUrl =
"otpauth://totp/"
102 . rawurlencode( $label )
104 . rawurlencode( $secret )
108 $qrcodeElement = Html::element(
'div', [
109 'data-mw-qrcode-url' => $qrcodeUrl,
110 'class' =>
'mw-display-qrcode',
113 'style' =>
'width: 256px; height: 256px;'
119 'default' => $this->
msg(
'oathauth-step1-test' )->escaped(),
121 'section' =>
'step1',
125 'default' => $qrcodeElement,
127 'section' =>
'step2',
131 'label-message' =>
'oathauth-step2alt',
133 '<strong>' . $this->
msg(
'oathauth-account' )->escaped() .
'</strong><br/>'
135 .
'<strong>' . $this->
msg(
'oathauth-secret' )->escaped() .
'</strong><br/>'
138 'section' =>
'step2',
143 $this->
msg(
'oathauth-scratchtokens' )
146 'section' =>
'step3',
151 'label-message' =>
'oathauth-entertoken',
153 'section' =>
'step4',
157 'default' => $this->
getRequest()->getVal(
'returnto' ),
158 'name' =>
'returnto',
162 'default' => $this->
getRequest()->getVal(
'returntoquery' ),
163 'name' =>
'returntoquery', ]
174 $key = $this->
getRequest()->getSessionData(
'oathauth_key' );
176 if ( $key->isScratchToken( $formData[
'token'] ) ) {
178 return [
'oathauth-noscratchforvalidation' ];
180 if ( !$key->verifyToken( $formData[
'token'], $this->OATHUser ) ) {
181 return [
'oathauth-failedtovalidateoath' ];
184 $this->
getRequest()->setSessionData(
'oathauth_key',
null );
186 $this->OATHRepository->persist( $this->
OATHUser );
192 $this->
getOutput()->addWikiMsg(
'oathauth-validatedoath' );
202 foreach ( $resources as $resource ) {
203 $resourceList .= Html::rawElement(
'li', [], Html::rawElement(
'kbd', [], $resource ) );
205 return Html::rawElement(
'ul', [], $resourceList );
229 return array_map( [ $this,
'tokenFormatterFunction' ], $key->
getScratchTokens() );
239 return implode(
' ', str_split( $token, 4 ) );
Special page which uses an HTMLForm to handle processing.
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 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.
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
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))