first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
if (!defined('WORDFENCE_LS_VERSION')) { exit; }
|
||||
/**
|
||||
* Presents a modal prompt.
|
||||
*
|
||||
* @var string|\WordfenceLS\Text\Model_HTML $title The title for the prompt. Required.
|
||||
* @var string|\WordfenceLS\Text\Model_HTML $message The message for the prompt. Required.
|
||||
* @var array $primaryButton The parameters for the primary button. The array is in the format array('id' => <element id>, 'label' => <button text>, 'link' => <href value>). Optional.
|
||||
* @var array $secondaryButtons The parameters for any secondary buttons. It is an array of arrays in the format array('id' => <element id>, 'label' => <button text>, 'link' => <href value>). The ordering of entries is the right-to-left order the buttons will be displayed. Optional.
|
||||
*/
|
||||
|
||||
$titleHTML = \WordfenceLS\Text\Model_HTML::esc_html($title);
|
||||
$messageHTML = \WordfenceLS\Text\Model_HTML::esc_html($message);
|
||||
$embedded = isset($embedded) ? $embedded : false;
|
||||
|
||||
if (!isset($secondaryButtons)) {
|
||||
$secondaryButtons = array();
|
||||
}
|
||||
$secondaryButtons = array_reverse($secondaryButtons);
|
||||
?>
|
||||
<div class="wfls-modal">
|
||||
<div class="wfls-modal-header">
|
||||
<div class="wfls-modal-header-content">
|
||||
<div class="wfls-modal-title">
|
||||
<strong><?php echo $titleHTML; ?></strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wfls-modal-header-action">
|
||||
<div class="wfls-padding-add-left-small wfls-modal-header-action-close"><a href="#" onclick="WFLS.panelClose(); return false"><i class="<?php echo (\WordfenceLS\Controller_WordfenceLS::shared()->should_use_core_font_awesome_styles() ? 'wf-fa wf-fa-times-circle' : 'wfls-fa wfls-fa-times-circle'); ?>" aria-hidden="true"></i></a></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wfls-modal-content">
|
||||
<?php echo $messageHTML; ?>
|
||||
</div>
|
||||
<div class="wfls-modal-footer">
|
||||
<ul class="wfls-flex-horizontal wfls-flex-align-right wfls-full-width">
|
||||
<?php foreach ($secondaryButtons as $button): ?>
|
||||
<li class="wfls-padding-add-left-small"><a href="<?php echo esc_url($button['link']); ?>" class="wfls-btn <?php echo isset($button['type']) ? $button['type'] : 'wfls-btn-default'; ?> wfls-btn-callout-subtle" id="<?php echo esc_attr($button['id']); ?>"><?php echo isset($button['labelHTML']) ? $button['labelHTML'] : esc_html($button['label']); ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
<?php if (isset($primaryButton) && is_array($primaryButton)): ?>
|
||||
<li class="wfls-padding-add-left-small"><a href="<?php echo esc_url($primaryButton['link']); ?>" class="wfls-btn <?php echo isset($primaryButton['type']) ? $primaryButton['type'] : 'wfls-btn-primary'; ?> wfls-btn-callout-subtle" id="<?php echo esc_attr($primaryButton['id']); ?>"><?php echo isset($primaryButton['labelHTML']) ? $primaryButton['labelHTML'] : esc_html($primaryButton['label']); ?></a></li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
if (!defined('WORDFENCE_LS_VERSION')) { exit; }
|
||||
|
||||
if (!isset($defaultGracePeriod))
|
||||
$defaultGracePeriod = \WordfenceLS\Controller_Settings::shared()->get_user_2fa_grace_period();
|
||||
$defaultGracePeriod = max($defaultGracePeriod, 1);
|
||||
$errorMessage = $gracePeriod === null ? __('Unable to Activate Grace Period', 'wordfence-2fa') : __('Unable to Reset Grace Period', 'wordfence-2fa');
|
||||
?>
|
||||
<div class="wfls-add-top wfls-add-bottom wfls-grace-period-container">
|
||||
<div class="wfls-grace-period-input-container">
|
||||
<label for="wfls-user-grace-period-override" style="display: none"><?php esc_html_e('Grace Period Override', 'wordfence-2fa') ?></label>
|
||||
<input type="text" id="wfls-user-grace-period-override" maxlength="2" pattern="[0-9]+" value="<?php echo (int) $defaultGracePeriod ?>">
|
||||
<label for="wfls-user-grace-period-override"><?php esc_html_e('days', 'wordfence-2fa') ?></label>
|
||||
</div>
|
||||
<div class="wfls-grace-period-button-container">
|
||||
<button class="wfls-btn wfls-btn-default" id="wfls-reset-grace-period">
|
||||
<?php echo $gracePeriod === null ? esc_html__('Activate Grace Period', 'wordfence-2fa') : esc_html__('Reset Grace Period', 'wordfence-2fa') ?>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p id="wfls-reset-grace-period-failed" style="display: none"><strong><?php echo esc_html($errorMessage) ?></strong></p>
|
||||
</div>
|
||||
<script type="application/javascript">
|
||||
(function($) {
|
||||
$(function() {
|
||||
var failureMessage = $('#wfls-reset-grace-period-failed');
|
||||
var overrideInput = $('#wfls-user-grace-period-override');
|
||||
var button = $('#wfls-reset-grace-period');
|
||||
function reset2faGracePeriod(userId, gracePeriodOverride, success, failure) {
|
||||
var ajaxContext = (typeof WFLS === 'undefined' ? GWFLS : WFLS);
|
||||
ajaxContext.ajax(
|
||||
'wordfence_ls_reset_2fa_grace_period',
|
||||
{
|
||||
user_id: userId,
|
||||
grace_period_override: gracePeriodOverride
|
||||
},
|
||||
success,
|
||||
failure
|
||||
);
|
||||
}
|
||||
function handleError() {
|
||||
if (typeof WFLS === 'object') {
|
||||
WFLS.panelModal(
|
||||
(WFLS.screenSize(500) ? '300px' : '400px'),
|
||||
<?php echo json_encode($errorMessage) ?>,
|
||||
<?php echo json_encode($gracePeriod === null ? __('An unexpected error occurred while attempting to activate the grace period.', 'wordfence-2fa') : __('An unexpected error occurred while attempting to reset the grace period.', 'wordfence-2fa')) ?>
|
||||
);
|
||||
}
|
||||
else {
|
||||
failureMessage.show();
|
||||
}
|
||||
button.prop('disabled', false);
|
||||
overrideInput.prop('disabled', false);
|
||||
}
|
||||
button.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
button.prop('disabled', true);
|
||||
overrideInput.prop('disabled', true);
|
||||
failureMessage.hide();
|
||||
reset2faGracePeriod(
|
||||
<?php echo json_encode($user->ID, true) ?>,
|
||||
overrideInput.val(),
|
||||
function(data) {
|
||||
if ('error' in data) {
|
||||
handleError();
|
||||
return;
|
||||
}
|
||||
if (typeof WFLS === 'undefined')
|
||||
window.location.href = '#wfls-user-settings';
|
||||
window.location.reload();
|
||||
},
|
||||
handleError
|
||||
);
|
||||
});
|
||||
overrideInput.on('input', function(e) {
|
||||
var value = $(this).val();
|
||||
value = value.replace(/[^0-9]/g, '');
|
||||
value = parseInt(value);
|
||||
if (isNaN(value) || value === 0)
|
||||
value = '';
|
||||
button.prop('disabled', value < 1);
|
||||
$(this).val(value);
|
||||
}).trigger('input');
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
if (!defined('WORDFENCE_LS_VERSION')) { exit; }
|
||||
|
||||
$errorMessage = __('Unable to Revoke Grace Period', 'wordfence-2fa');
|
||||
?>
|
||||
<div class="wfls-add-top wfls-add-bottom wfls-grace-period-container">
|
||||
<div class="wfls-grace-period-button-container">
|
||||
<button class="wfls-btn wfls-btn-default" id="wfls-revoke-grace-period">
|
||||
<?php esc_html_e('Revoke Grace Period', 'wordfence-2fa') ?>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p id="wfls-revoke-grace-period-failed" style="display: none"><strong><?php echo esc_html($errorMessage) ?></strong></p>
|
||||
</div>
|
||||
<script type="application/javascript">
|
||||
(function($) {
|
||||
$(function() {
|
||||
var failureMessage = $('#wfls-revoke-grace-period-failed');
|
||||
var button = $('#wfls-revoke-grace-period');
|
||||
function revoke2faGracePeriod(userId, success, failure) {
|
||||
var ajaxContext = (typeof WFLS === 'undefined' ? GWFLS : WFLS);
|
||||
ajaxContext.ajax(
|
||||
'wordfence_ls_revoke_2fa_grace_period',
|
||||
{
|
||||
user_id: userId
|
||||
},
|
||||
success,
|
||||
failure
|
||||
);
|
||||
}
|
||||
function handleError() {
|
||||
if (typeof WFLS === 'object') {
|
||||
WFLS.panelModal(
|
||||
(WFLS.screenSize(500) ? '300px' : '400px'),
|
||||
<?php echo json_encode($errorMessage) ?>,
|
||||
<?php echo json_encode(__('An unexpected error occurred while attempting to revoke the grace period.', 'wordfence-2fa')) ?>
|
||||
);
|
||||
}
|
||||
else {
|
||||
failureMessage.show();
|
||||
}
|
||||
button.prop('disabled', false);
|
||||
}
|
||||
button.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
button.prop('disabled', true);
|
||||
failureMessage.hide();
|
||||
revoke2faGracePeriod(
|
||||
<?php echo json_encode($user->ID, true) ?>,
|
||||
function(data) {
|
||||
if ('error' in data) {
|
||||
handleError();
|
||||
return;
|
||||
}
|
||||
if (typeof WFLS === 'undefined')
|
||||
window.location.href = '#wfls-user-settings';
|
||||
window.location.reload();
|
||||
},
|
||||
handleError
|
||||
);
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
Reference in New Issue
Block a user