Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7435662
RecoveryCodesStatusForm.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
RecoveryCodesStatusForm.php
View Options
<?php
namespace
MediaWiki\Extension\OATHAuth\HTMLForm
;
use
MediaWiki\Extension\OATHAuth\Key\RecoveryCodeKeys
;
use
MediaWiki\Logger\LoggerFactory
;
use
MediaWiki\Status\Status
;
use
UnexpectedValueException
;
class
RecoveryCodesStatusForm
extends
OATHAuthOOUIHTMLForm
{
use
KeySessionStorageTrait
;
use
RecoveryCodesTrait
;
/**
* @param array|bool|Status|string $submitResult
* @return string
*/
public
function
getHTML
(
$submitResult
)
{
$out
=
$this
->
getOutput
();
$out
->
addModuleStyles
(
'ext.oath.recovery.styles'
);
$out
->
addModules
(
'ext.oath.recovery'
);
$out
->
setPageTitleMsg
(
$this
->
msg
(
'oathauth-recoverycodes-header-create'
)
);
return
parent
::
getHTML
(
$submitResult
);
}
/** @inheritDoc */
protected
function
getDescriptors
()
{
if
(
$this
->
oathUser
->
userHasNonSpecialEnabledKeys
()
)
{
$submitMsg
=
$this
->
msg
(
'oathauth-recoverycodes-create-label'
,
$this
->
getConfig
()->
get
(
'OATHRecoveryCodesCount'
)
);
$this
->
setSubmitTextMsg
(
$submitMsg
);
$this
->
setSubmitDestructive
();
$this
->
showCancel
();
$this
->
setCancelTarget
(
$this
->
getTitle
()
);
}
else
{
$this
->
suppressDefaultSubmit
();
}
return
[
'warning'
=>
[
'type'
=>
'info'
,
'default'
=>
$this
->
msg
(
'oathauth-recoverycodes-regenerate-warning'
,
$this
->
getConfig
()->
get
(
'OATHRecoveryCodesCount'
)
)->
parse
(),
'raw'
=>
true
,
]
];
}
/**
* Add content to output when operation was successful
*/
public
function
onSuccess
()
{
$moduleDbKeys
=
$this
->
oathUser
->
getKeysForModule
(
$this
->
module
->
getName
()
);
if
(
count
(
$moduleDbKeys
)
>
RecoveryCodeKeys
::
RECOVERY_CODE_MODULE_COUNT
)
{
throw
new
UnexpectedValueException
(
$this
->
msg
(
'oathauth-recoverycodes-too-many-instances'
)->
escaped
()
);
}
if
(
array_key_exists
(
0
,
$moduleDbKeys
)
)
{
$recoveryCodes
=
$this
->
getRecoveryCodesForDisplay
(
array_shift
(
$moduleDbKeys
)
);
$output
=
$this
->
getOutput
();
$output
->
addModuleStyles
(
'ext.oath.recovery.styles'
);
$output
->
addModules
(
'ext.oath.recovery'
);
$output
->
addHtml
(
$this
->
generateRecoveryCodesContent
(
$recoveryCodes
)
);
}
}
/**
* @param array $formData
* @return array|bool
*/
public
function
onSubmit
(
array
$formData
)
{
$keys
=
$this
->
oathUser
->
getKeysForModule
(
$this
->
module
->
getName
()
);
if
(
$keys
)
{
/** @var RecoveryCodeKeys $objRecoveryCodeKeys */
$objRecoveryCodeKeys
=
array_shift
(
$keys
);
'@phan-var RecoveryCodeKeys $objRecoveryCodeKeys'
;
$objRecoveryCodeKeys
->
regenerateRecoveryCodeKeys
();
}
RecoveryCodeKeys
::
maybeCreateOrUpdateRecoveryCodeKeys
(
$this
->
oathUser
);
LoggerFactory
::
getInstance
(
'authentication'
)->
info
(
"OATHAuth {user} generated new recovery codes from {clientip}"
,
[
'user'
=>
$this
->
getUser
()->
getName
(),
'clientip'
=>
$this
->
getRequest
()->
getIP
(),
]
);
return
true
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 13:01 (1 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
84/01/d3446a830a9327e9a6d691764838
Default Alt Text
RecoveryCodesStatusForm.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment