From 0f38c2a2374350e0768dca1f38d30501e8ff3a73 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Tue, 25 Oct 2022 09:08:27 -0700 Subject: [PATCH] TOTP: Add locally generated QR codes. --- providers/class-two-factor-totp.php | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/providers/class-two-factor-totp.php b/providers/class-two-factor-totp.php index e451f536..93646f47 100644 --- a/providers/class-two-factor-totp.php +++ b/providers/class-two-factor-totp.php @@ -50,6 +50,7 @@ class Two_Factor_Totp extends Two_Factor_Provider { * @codeCoverageIgnore */ protected function __construct() { + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); add_action( 'two_factor_user_options_' . __CLASS__, array( $this, 'user_two_factor_options' ) ); add_action( 'personal_options_update', array( $this, 'user_two_factor_options_update' ) ); add_action( 'edit_user_profile_update', array( $this, 'user_two_factor_options_update' ) ); @@ -78,6 +79,21 @@ public function get_label() { return _x( 'Time Based One-Time Password (TOTP)', 'Provider Label', 'two-factor' ); } + /** + * Enqueue scripts + */ + public function enqueue_assets() { + $environment_prefix = file_exists( TWO_FACTOR_DIR . '/dist' ) ? '/dist' : ''; + + wp_enqueue_script( + 'two-factor-qr-code-generator', + plugins_url( $environment_prefix . '/includes/qrcode-generator/qrcode.js', __DIR__ ), + array(), + TWO_FACTOR_VERSION, + true + ); + } + /** * Trigger our custom user settings actions. * @@ -136,6 +152,40 @@ public function user_two_factor_options( $user ) {

+

+ + + + +