v1.0.0
This commit is contained in:
parent
968211baad
commit
d405d8587d
1 changed files with 232 additions and 223 deletions
|
|
@ -287,44 +287,23 @@ class Login_Form_Manager {
|
|||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $alternates ) ) {
|
||||
$link_markup = array();
|
||||
|
||||
foreach ( $alternates as $alternate ) {
|
||||
$link_markup[] = sprintf(
|
||||
'<a href="%1$s">%2$s</a>',
|
||||
esc_url( $alternate['url'] ),
|
||||
esc_html( $alternate['label'] )
|
||||
);
|
||||
}
|
||||
|
||||
printf(
|
||||
'<p class="robotstxt-2fa-alternate description robotstxt-2fa-stage-field">%1$s %2$s</p>',
|
||||
esc_html__( 'Prefer a different verification method?', 'robotstxt-2fa' ),
|
||||
wp_kses_post( implode( ' <span class="robotstxt-2fa-links-separator" aria-hidden="true">•</span> ', $link_markup ) )
|
||||
);
|
||||
}
|
||||
|
||||
$back_url = wp_login_url( $this->get_requested_redirect() );
|
||||
?>
|
||||
<p class="robotstxt-2fa-login-links robotstxt-2fa-stage-field">
|
||||
<a class="robotstxt-2fa-back-link" href="<?php echo esc_url( $back_url ); ?>"><?php esc_html_e( 'Back to login', 'robotstxt-2fa' ); ?></a>
|
||||
<?php if ( 'email' === $method && '' !== $stage_token ) : ?>
|
||||
<span class="robotstxt-2fa-links-separator" aria-hidden="true">•</span>
|
||||
<a class="robotstxt-2fa-resend-link" href="
|
||||
<?php
|
||||
echo esc_url(
|
||||
$this->get_stage_url(
|
||||
array(
|
||||
self::QUERY_RESEND => '1',
|
||||
self::QUERY_NOTICE => null,
|
||||
)
|
||||
)
|
||||
);
|
||||
?>
|
||||
"><?php esc_html_e( 'Send the code again', 'robotstxt-2fa' ); ?></a>
|
||||
<ul class="robotstxt-2fa-login-links robotstxt-2fa-stage-field">
|
||||
<?php if ( 'email' === $method && '' !== $stage_token ) : ?>
|
||||
<li>
|
||||
<a class="robotstxt-2fa-resend-link" href="<?php echo esc_url( $this->get_stage_url( array( self::QUERY_RESEND => '1', self::QUERY_NOTICE => null ) ) ); ?>">
|
||||
<?php esc_html_e( 'Send the code again', 'robotstxt-2fa' ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<?php foreach ( $alternates as $alternate ) : ?>
|
||||
<li>
|
||||
<a href="<?php echo esc_url( $alternate['url'] ); ?>"><?php echo esc_html( $alternate['label'] ); ?></a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<li><a class="robotstxt-2fa-back-link" href="<?php echo esc_url( $back_url ); ?>"><?php esc_html_e( 'Back to login', 'robotstxt-2fa' ); ?></a></li>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
|
@ -348,6 +327,14 @@ class Login_Form_Manager {
|
|||
#loginform .wp-hide-pw {
|
||||
display: none !important;
|
||||
}
|
||||
.robotstxt-2fa-login-links {
|
||||
list-style: none;
|
||||
margin: 0.5em 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
.robotstxt-2fa-login-links li {
|
||||
margin: 0.4em 0;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
|
@ -412,7 +399,18 @@ class Login_Form_Manager {
|
|||
return;
|
||||
}
|
||||
|
||||
$login = $this->get_requested_login();
|
||||
$login = $this->get_requested_login();
|
||||
$method = $this->get_requested_method();
|
||||
$sent_at = 0;
|
||||
|
||||
if ( 'email' === $method && '' !== $login ) {
|
||||
$user = get_user_by( 'login', $login );
|
||||
|
||||
if ( $user instanceof \WP_User ) {
|
||||
$challenge = $this->user_settings_repository->get_email_challenge( $user->ID );
|
||||
$sent_at = $challenge['sent_at'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
(function() {
|
||||
|
|
@ -467,6 +465,32 @@ class Login_Form_Manager {
|
|||
if ( tokenField ) {
|
||||
tokenField.focus();
|
||||
}
|
||||
|
||||
/* Resend link cooldown */
|
||||
var resendLink = document.querySelector('.robotstxt-2fa-resend-link');
|
||||
if ( resendLink ) {
|
||||
var sentAt = <?php echo absint( $sent_at ); ?>;
|
||||
var cooldown = <?php echo absint( $this->email_code_sender->get_resend_interval() ); ?>;
|
||||
var label = resendLink.textContent.trim();
|
||||
|
||||
function updateResend() {
|
||||
var remaining = cooldown - ( Math.floor( Date.now() / 1000 ) - sentAt );
|
||||
if ( remaining <= 0 ) {
|
||||
resendLink.removeAttribute('aria-disabled');
|
||||
resendLink.style.opacity = '';
|
||||
resendLink.style.pointerEvents = '';
|
||||
resendLink.textContent = label;
|
||||
} else {
|
||||
resendLink.setAttribute('aria-disabled', 'true');
|
||||
resendLink.style.opacity = '0.45';
|
||||
resendLink.style.pointerEvents = 'none';
|
||||
resendLink.textContent = label + ' (' + remaining + 's)';
|
||||
setTimeout( updateResend, 1000 );
|
||||
}
|
||||
}
|
||||
|
||||
updateResend();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
|
|
@ -811,7 +835,17 @@ class Login_Form_Manager {
|
|||
}
|
||||
}
|
||||
|
||||
return $available;
|
||||
// Return methods in canonical priority order: OTP first, email second, recovery last.
|
||||
$priority = array( 'otp', 'email', 'recovery' );
|
||||
$sorted = array();
|
||||
|
||||
foreach ( $priority as $p ) {
|
||||
if ( in_array( $p, $available, true ) ) {
|
||||
$sorted[] = $p;
|
||||
}
|
||||
}
|
||||
|
||||
return $sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue