Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into profile-ux
Browse files Browse the repository at this point in the history
# Conflicts:
#	class-two-factor-core.php
  • Loading branch information
kasparsd committed Dec 3, 2024
2 parents 90d5957 + 636dc0b commit 2eee45d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
34 changes: 17 additions & 17 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,8 @@ public static function manage_users_custom_column( $output, $column_name, $user_
* @param WP_User $user WP_User object of the logged-in user.
*/
public static function user_two_factor_options( $user ) {
$notices = [];

wp_enqueue_style( 'user-edit-2fa', plugins_url( 'user-edit.css', __FILE__ ), array(), TWO_FACTOR_VERSION );

$enabled_providers = array_keys( self::get_available_providers_for_user( $user ) );
Expand All @@ -1802,17 +1804,17 @@ public static function user_two_factor_options( $user ) {
// This is specific to the current session, not the displayed user.
$show_2fa_options = self::current_user_can_update_two_factor_options() || true;

if ( ! $show_2fa_options && false ) {
$url = self::get_user_two_factor_revalidate_url();
$url = add_query_arg( 'redirect_to', urlencode( self::get_user_settings_page_url( $user->ID ) . '#two-factor-options' ), $url );
if ( ! $show_2fa_options ) {
$url = add_query_arg(
'redirect_to',
urlencode( self::get_user_settings_page_url( $user->ID ) . '#two-factor-options' ),
self::get_user_two_factor_revalidate_url()
);

printf(
'<div class="notice notice-warning inline"><p>%s</p></div>',
sprintf(
__( 'To update your Two-Factor options, you must first revalidate your session.', 'two-factor' ) .
'<br><a class="button" href="%s">' . __( 'Revalidate now', 'two-factor' ) . '</a>',
$notices['warning two-factor-warning-revalidate-session'] = sprintf(
esc_html__( 'To update your Two-Factor options, you must first revalidate your session.', 'two-factor' ) .
' <a class="button" href="%s">' . esc_html__( 'Revalidate now', 'two-factor' ) . '</a>',
esc_url( $url )
)
);
}

Expand All @@ -1821,22 +1823,20 @@ public static function user_two_factor_options( $user ) {
$show_2fa_options ? '' : 'disabled="disabled"'
);

$notices = [];
if ( empty( $enabled_providers ) ) {
$notices[] = __( 'Configure a primary two-factor method along with a backup method, such as Recovery Codes, to avoid being locked out if you lose access to your primary method.', 'two-factor' );
} elseif ( 1 === count( $enabled_providers ) ) {
$notices['warning'] = __( 'To prevent being locked out of your account, consider enabling a backup method like Recovery Codes in case you lose access to your primary authentication method.', 'two-factor' );
if ( 1 === count( $enabled_providers ) ) {
$notices['warning two-factor-warning-suggest-backup'] = esc_html__( 'To prevent being locked out of your account, consider enabling a backup method like Recovery Codes in case you lose access to your primary authentication method.', 'two-factor' );
}

?>
<h2><?php esc_html_e( 'Two-Factor Options', 'two-factor' ); ?></h2>

<?php foreach ( $notices as $notice_type => $notice ) : ?>
<div class="<?php echo esc_attr( $notice_type ? 'notice inline notice-' . $notice_type : '' ); ?>">
<p><?php echo esc_html( $notice ); ?></p>
<p><?php echo wp_kses_post( $notice ); ?></p>
</div>
<?php endforeach; ?>

<p>
<?php esc_html_e( 'Configure a primary two-factor method along with a backup method, such as Recovery Codes, to avoid being locked out if you lose access to your primary method.', 'two-factor' ); ?>
</p>
<?php wp_nonce_field( 'user_two_factor_options', '_nonce_user_two_factor_options', false ); ?>
<input type="hidden" name="<?php echo esc_attr( self::ENABLED_PROVIDERS_USER_META_KEY ); ?>[]" value="<?php /* Dummy input so $_POST value is passed when no providers are enabled. */ ?>" />

Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions providers/class-two-factor-totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ public function user_two_factor_options( $user ) {

<script>
(function($){
// Focus the auth code input when the checkbox is clicked.
document.getElementById('enabled-Two_Factor_Totp').addEventListener('click', function(e) {
if ( e.target.checked ) {
document.getElementById('two-factor-totp-authcode').focus();
}
});

$('.totp-submit').click( function( e ) {
e.preventDefault();
var key = $('#two-factor-totp-key').val(),
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: georgestephanis, valendesigns, stevenkword, extendwings, sgrant, aaroncampbell, johnbillion, stevegrunwell, netweb, kasparsd, alihusnainarshad, passoniate
Tags: 2fa, mfa, totp, authentication, security
Tested up to: 6.6
Stable tag: 0.9.1
Stable tag: 0.10.0
License: GPL-2.0-or-later
License URI: https://spdx.org/licenses/GPL-2.0-or-later.html

Expand Down
4 changes: 2 additions & 2 deletions two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Two Factor
* Plugin URI: https://wordpress.org/plugins/two-factor/
* Description: Enable Two-Factor Authentication using time-based one-time passwords, Universal 2nd Factor (FIDO U2F, YubiKey), email, and backup verification codes.
* Version: 0.9.1
* Version: 0.10.0
* Requires at least: 6.3
* Requires PHP: 7.2
* Author: WordPress.org Contributors
Expand All @@ -30,7 +30,7 @@
/**
* Version of the plugin.
*/
define( 'TWO_FACTOR_VERSION', '0.9.1' );
define( 'TWO_FACTOR_VERSION', '0.10.0' );

/**
* Include the base class here, so that other plugins can also extend it.
Expand Down

0 comments on commit 2eee45d

Please sign in to comment.