PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 1.7.0
WP 2FA – Two-factor authentication for WordPress v1.7.0
4.1.0 4.0.0 1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / Admin / Views / WizardSteps.php
wp-2fa / includes / classes / Admin / Views Last commit date
FirstTimeWizardSteps.php 5 years ago WizardSteps.php 5 years ago
WizardSteps.php
685 lines
1 <?php
2
3 namespace WP2FA\Admin\Views;
4
5 use WP2FA\WP2FA;
6 use WP2FA\Admin\User;
7 use WP2FA\Utils\UserUtils;
8 use WP2FA\Admin\Controllers\Settings;
9 use WP2FA\Authenticator\Authentication;
10
11 defined( 'ABSPATH' ) || exit; // Exit if accessed directly
12
13 /**
14 * WP2FA Wizard Settings view controller
15 *
16 * @since 1.7
17 */
18 class WizardSteps {
19
20 /**
21 * Holds the current user
22 *
23 * @since 1.7
24 *
25 * @var \WP2FA\Admin\User
26 */
27 private static $user = null;
28
29 /**
30 * Is the totp method enabled
31 *
32 * @since 1.7
33 *
34 * @var bool
35 */
36 private static $totpEnabled = null;
37
38 /**
39 * Is the mail enabled
40 *
41 * @since 1.7
42 *
43 * @var bool
44 */
45 private static $emailEnabled = null;
46
47 /**
48 * Holds the nonce for json calls
49 *
50 * @since 1.7
51 *
52 * @var string
53 */
54 private static $jsonNonce = null;
55
56 /**
57 * Introduction step form
58 *
59 * @since 1.7
60 *
61 * @return void
62 */
63 public static function introductionStep() {
64 ?>
65 <form method="post" class="wp2fa-setup-form">
66 <?php wp_nonce_field( 'wp2fa-step-addon' ); ?>
67 <h3><?php esc_html_e( 'You are required to configure 2FA.', 'wp-2fa' ); ?></h3>
68 <p><?php esc_html_e( 'In order to keep this site - and your details secure, this website’s administrator requires you to enable 2FA authentication to continue.', 'wp-2fa' ); ?></p>
69 <p><?php esc_html_e( 'Two factor authentication ensures only you have access to your account by creating an added layer of security when logging in -', 'wp-2fa' ); ?> <a href="https://www.wpwhitesecurity.com/two-factor-authentication-wordpress/" target="_blank" rel="noopener"><?php esc_html_e( 'Learn more', 'wp-2fa' ); ?></a></p>
70
71 <div class="wp2fa-setup-actions">
72 <button class="button button-primary"
73 type="submit"
74 name="save_step"
75 value="<?php esc_attr_e( 'Next', 'wp-2fa' ); ?>">
76 <?php esc_html_e( 'Next', 'wp-2fa' ); ?>
77 </button>
78 </div>
79 </form>
80 <?php
81 }
82
83 /**
84 * Welcome step of the wizard
85 *
86 * @since 1.7
87 *
88 * @param string $nextStep - url of the nex step
89 *
90 * @return void
91 */
92 public static function welcomeStep( $nextStep ) {
93 $redirect = Settings::getSettingsPageLink();
94
95 ?>
96 <h3><?php esc_html_e( 'Let us help you get started', 'wp-2fa' ); ?></h3>
97 <p><?php esc_html_e( 'Thank you for installing the WP 2FA plugin. This quick wizard will assist you with configuring the plugin and the two-factor authentication (2FA) settings for your user and the users on this website.', 'wp-2fa' ); ?></p>
98
99 <div class="wp2fa-setup-actions">
100 <a class="button button-primary"
101 href="<?php echo esc_url( $nextStep ); ?>">
102 <?php esc_html_e( 'Let’s get started!', 'wp-2fa' ); ?>
103 </a>
104 <a class="button button-secondary first-time-wizard"
105 href="<?php echo esc_url( $redirect ); ?>">
106 <?php esc_html_e( 'Skip Wizard - I know how to do this', 'wp-2fa' ); ?>
107 </a>
108 </div>
109 <?php
110 }
111
112 /**
113 * Shows the initial totp setup options based on enabled methods
114 *
115 * @since 1.7
116 *
117 * @return void
118 */
119 public static function totpOption() {
120 if ( self::isTotpEnabled() ) {
121 ?>
122 <div class="option-pill">
123 <label for="basic">
124 <input id="basic" name="wp_2fa_enabled_methods" type="radio" value="totp" checked>
125 <?php esc_html_e( 'One-time code generated with your app of choice (most reliable and secure)', 'wp-2fa' ); ?>
126 </label>
127 <?php
128 echo '<p class="description">';
129 printf(
130 /* translators: link to the knowledge base website */
131 esc_html__( 'Refer to the %s for more information on how to setup these apps and which apps are supported.', 'wp-2fa' ),
132 '<a href="https://www.wpwhitesecurity.com/support/kb/configuring-2fa-apps/" target="_blank">' . esc_html__( '2FA apps article on our knowledge base', 'wp-2fa' ) . '</a>'
133 );
134 echo '</p>';
135 ?>
136 </div>
137 <?php
138 }
139 }
140
141 /**
142 * Shows the initial email setup option based on enabled methods
143 *
144 * @since 1.7
145 *
146 * @return void
147 */
148 public static function emailOption() {
149 if ( self::isMailEnabled() ) {
150 ?>
151 <div class="option-pill">
152 <label for="geek">
153 <input id="geek" name="wp_2fa_enabled_methods" type="radio" value="email">
154 <?php esc_html_e( 'One-time code sent to you over email', 'wp-2fa' ); ?>
155 </label>
156 <?php
157 if ( current_user_can( 'administrator' ) ) {
158 printf( '<p class="description">%1$s <a href="https://wordpress.org/plugins/wp-mail-smtp/" target="_blank">%2$s</a>.</p>', esc_html__( 'Email reliability and deliverability is important when using this method, otherwise you might have problems logging in. To ensure emails are always delivered we recommend using the free plugin', 'wp-2fa' ), esc_html__( 'WP Mail SMTP', 'wp-2fa' ) );
159 }
160 ?>
161 </div>
162 <?php
163 }
164 }
165
166 /**
167 * Shows the option to reconfigure email (if applicable)
168 *
169 * @since 1.7
170 *
171 * @return void
172 */
173 public static function totpReConfigure() {
174
175 if ( ! self::isTotpEnabled() ) {
176 return;
177 }
178
179 $nonce = self::jsonNonce();
180
181 ?>
182 <div class="option-pill">
183 <h3>
184 <?php esc_html_e( 'Reconfigure the 2FA App', 'wp-2fa' ); ?>
185 </h3>
186 <p>
187 <?php esc_html_e( 'Click the below button to reconfigure the current 2FA method. Note that once reset you will have to re-scan the QR code on all devices you want this to work on because the previous codes will stop working.', 'wp-2fa' ); ?>
188 </p>
189 <div class="wp2fa-setup-actions">
190 <a href="#" class="button button-primary" data-name="next_step_setting_modal_wizard" data-trigger-reset-key data-nonce="<?php echo esc_attr( $nonce ); ?>" data-user-id="<?php echo esc_attr( self::getUser()->getUser()->ID ); ?>" data-next-step="2fa-wizard-totp"><?php esc_html_e( 'Reset Key', 'wp-2fa' ); ?></a>
191 </div>
192 </div>
193 <?php
194 }
195
196 /**
197 * Shows the option for email method reconfiguring (if applicable)
198 *
199 * @since 1.7
200 *
201 * @return void
202 */
203 public static function emailReConfigure() {
204
205 if ( ! self::isMailEnabled() ) {
206 return;
207 }
208
209 $setupnonce = wp_create_nonce( 'wp-2fa-send-setup-email' );
210 ?>
211 <div class="option-pill">
212 <h3><?php esc_html_e( 'Reconfigure email', 'wp-2fa' ); ?></h3>
213 <p>
214 <?php esc_html_e( 'Please select the email address where the one-time code should be sent:', 'wp-2fa' ); ?>
215 </p>
216 <div class="wp2fa-setup-actions">
217 <a class="button button-primary" data-name="next_step_setting_modal_wizard" value="<?php esc_attr_e( 'I\'m Ready', 'wp-2fa' ); ?>" data-user-id="<?php echo esc_attr( self::getUser()->getUser()->ID ); ?>" data-nonce="<?php echo esc_attr( $setupnonce ); ?>" data-next-step="2fa-wizard-email"><?php esc_html_e( 'Change email address', 'wp-2fa' ); ?></a>
218 </div>
219 </div>
220 <?php
221 }
222
223 /**
224 * Reconfigures the totp form
225 *
226 * @since 1.7
227 *
228 * @return void
229 */
230 public static function totpConfigure() {
231
232 if ( ! self::isTotpEnabled() ) {
233 return;
234 }
235 /**
236 * Active on modal, additional attribute is required on standard HTML (check below)
237 */
238 $addStepAttributes = 'active';
239
240 /**
241 * Closing div for extra modal wrappers see lines above
242 */
243 $closeDiv = '';
244
245 $qrCode = '<img class="qr-code" src="' . esc_url( self::getQRCode() ) . '" id="wp-2fa-totp-qrcode" />';
246 $open30Wrapper = '
247 <div class="mb-30 clear-both">
248 ';
249 $open50Wrapper = '
250 <div class="modal-50">
251 ';
252 $closeDiv = '
253 </div>
254 ';
255 $validateNonce = wp_create_nonce( 'wp-2fa-validate-authcode' );
256
257 ?>
258 <div class="step-setting-wrapper <?php echo $addStepAttributes; ?>">
259 <h3><?php esc_html_e( 'Setup the 2FA method', 'wp-2fa' ); ?></h3>
260 <?php echo $open30Wrapper . $open50Wrapper; ?>
261 <div class="option-pill">
262 <ol>
263 <li><?php esc_html_e( 'Download and start the application of your choice (for detailed steps on setting it up click on the application icon of our choice below)', 'wp-2fa' ); ?></li>
264 <li><?php esc_html_e( 'From within the application scan the QR code provided on the right. Otherwise, enter the following code manually in the application:', 'wp-2fa' ); ?>
265 <div><code class="app-key"><?php echo esc_html( self::getUser()->getTotpKey() ); ?></code></div>
266 </li>
267 <li><?php esc_html_e( 'Click the "I\'m ready" button below when you complete the application setup process to proceed with the wizard.', 'wp-2fa' ); ?></li>
268 </ol>
269 </div>
270 <?php
271 echo $closeDiv; // closes 50 wrapper
272 echo $open50Wrapper;
273 ?>
274 <div class="qr-code-wrapper">
275 <?php echo $qrCode; ?>
276 </div>
277 <?php
278 echo $closeDiv; // closes 50 wrapper
279 echo $closeDiv; // closes 30 wrapper
280 ?>
281 <h4><?php esc_html_e( 'For detailed guides for your desired app, click below.', 'wp-2fa' ); ?></h4>
282 <div class="apps-wrapper">
283 <?php foreach ( Authentication::getApps() as $app ) { ?>
284 <a href="https://www.wpwhitesecurity.com/support/kb/configuring-2fa-apps/#<?php echo $app['hash']; ?>" target="_blank" class="app-logo"><img src="<?php echo esc_url( WP_2FA_URL . 'dist/images/' . $app['logo'] ); ?>"></a>
285 <?php } ?>
286 </div>
287 <div class="wp2fa-setup-actions">
288 <button class="button button-primary" name="next_step_setting" value="<?php esc_attr_e( 'I\'m Ready', 'wp-2fa' ); ?>" type="button"><?php esc_html_e( 'I\'m Ready', 'wp-2fa' ); ?></button>
289 </div>
290 </div>
291 <div class="step-setting-wrapper" data-step-title="<?php esc_html_e( 'Verify configuration', 'wp-2fa' ); ?>">
292 <h3><?php esc_html_e( 'Almost there…', 'wp-2fa' ); ?></h3>
293 <p><?php esc_html_e( 'Please type in the one-time code from your Google Authenticator app to finalize the setup.', 'wp-2fa' ); ?></p>
294 <fieldset>
295 <label for="2fa-totp-authcode">
296 <input type="tel" name="wp-2fa-totp-authcode" id="wp-2fa-totp-authcode" class="input" value="" size="20" pattern="[0-9]*" placeholder="<?php esc_html_e( 'Authentication Code', 'wp-2fa' ); ?>"/>
297 </label>
298 <div class="verification-response"></div>
299 </fieldset>
300 <input type="hidden" name="wp-2fa-totp-key" value="<?php echo esc_attr( self::getUser()->getTotpKey() ); ?>" />
301 <br>
302 <a href="#" class="modal__btn button button-primary" data-validate-authcode-ajax data-nonce="<?php echo esc_attr( $validateNonce ); ?>"><?php esc_html_e( 'Validate & Save Configuration', 'wp-2fa' ); ?></a>
303 <button class="modal__btn button" data-close-2fa-modal aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'wp-2fa' ); ?></button>
304 </div>
305
306 <?php
307 }
308
309 /**
310 * Reconfigures email form
311 *
312 * @since 1.7
313 *
314 * @return void
315 */
316 public static function emailConfigure() {
317
318 if ( ! self::isMailEnabled() ) {
319 return;
320 }
321
322 $setupnonce = wp_create_nonce( 'wp-2fa-send-setup-email' );
323
324 $validateNonce = wp_create_nonce( 'wp-2fa-validate-authcode' );
325 ?>
326 <div class="step-setting-wrapper active">
327 <h3><?php esc_html_e( 'Setup the 2FA method', 'wp-2fa' ); ?></h3>
328 <p>
329 <?php esc_html_e( 'Please select the email address where the one-time code should be sent:', 'wp-2fa' ); ?>
330 </p>
331 <fieldset>
332 <div class="option-pill">
333 <label for="use_wp_email">
334 <input type="radio" name="wp_2fa_email_address" id="use_wp_email" value="<?php echo esc_attr( self::getUser()->getUser()->user_email ); ?>" checked>
335 <span><?php esc_html_e( 'Use my user email (', 'wp-2fa' ); ?><small><?php echo esc_attr( self::getUser()->getUser()->user_email ); ?></small><?php esc_html_e( ')', 'wp-2fa' ); ?></span>
336 </label>
337 </div>
338 <div class="option-pill">
339 <label for="use_custom_email">
340 <input type="radio" name="wp_2fa_email_address" id="use_custom_email" value="use_custom_email">
341 <span><?php esc_html_e( 'Use a different email address:', 'wp-2fa' ); ?></span>
342 <input type="email" name="custom-email-address" id="custom-email-address" class="input" value="" placeholder="<?php esc_html_e( 'Email address', 'wp-2fa' ); ?>"/>
343 </label>
344 </div>
345 </fieldset>
346 <p class="description"><?php esc_html_e( 'Note: you should be able to access the mailbox of the email address to complete the following step.', 'wp-2fa' ); ?></p>
347 <div class="wp2fa-setup-actions">
348 <button class="button button-primary" name="next_step_setting" value="<?php esc_attr_e( 'I\'m Ready', 'wp-2fa' ); ?>" data-trigger-setup-email data-user-id="<?php echo esc_attr( self::getUser()->getUser()->ID ); ?>" data-nonce="<?php echo esc_attr( $setupnonce ); ?>" type="button"><?php esc_html_e( 'I\'m Ready', 'wp-2fa' ); ?></button>
349
350 </div>
351 </div>
352
353 <div class="step-setting-wrapper" data-step-title="<?php esc_html_e( 'Verify configuration', 'wp-2fa' ); ?>" id="2fa-wizard-email">
354 <h3><?php esc_html_e( 'Almost there…', 'wp-2fa' ); ?></h3>
355 <p><?php esc_html_e( 'Please type in the one-time code sent to your email address to finalize the setup.', 'wp-2fa' ); ?></p>
356 <fieldset>
357 <label for="2fa-email-authcode">
358 <input type="tel" name="wp-2fa-email-authcode" id="wp-2fa-email-authcode" class="input" value="" size="20" pattern="[0-9]*" placeholder="<?php esc_html_e( 'Authentication Code', 'wp-2fa' ); ?>"/>
359 </label>
360 <div class="verification-response"></div>
361 </fieldset>
362 <br />
363 <input type="hidden" name="wp-2fa-totp-key" value="<?php echo esc_attr( self::getUser()->getTotpKey() ); ?>" />
364 <a href="#" class="modal__btn modal__btn-primary button button-primary" data-validate-authcode-ajax data-nonce="<?php echo esc_attr( $validateNonce ); ?>"><?php esc_html_e( 'Validate & Save Configuration', 'wp-2fa' ); ?></a>
365 <a href="#" class="modal__btn button button-secondary resend-email-code" data-trigger-setup-email data-user-id="<?php echo esc_attr( self::getUser()->getUser()->ID ); ?>" data-nonce="<?php echo esc_attr( $setupnonce ); ?>">
366 <span class="resend-inner"><?php esc_html_e( 'Send me another code', 'wp-2fa' ); ?></span>
367 </a>
368 <button class="modal__btn button" data-close-2fa-modal aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'wp-2fa' ); ?></button>
369 </div>
370 <?php
371 }
372
373 /**
374 * Configure backup codes step
375 *
376 * @since 1.7
377 *
378 * @return void
379 */
380 public static function backupCodesConfigure() {
381
382 $userType = UserUtils::determine_user_2fa_status( self::getUser()->getUser() );
383
384 $redirect = '';
385 if ( '' !== trim( WP2FA::get_wp2fa_setting( 'redirect-user-custom-page-global' ) ) ) {
386 $redirect = \trailingslashit( get_site_url() ) . WP2FA::get_wp2fa_setting( 'redirect-user-custom-page-global' );
387 }
388
389 $nonce = self::jsonNonce();
390 ?>
391 <div class="step-setting-wrapper active">
392 <h3><?php esc_html_e( 'Your login just got more secure', 'wp-2fa' ); ?></h3>
393 <p><?php esc_html_e( 'Congratulations! You have enabled two-factor authentication for your user. You’ve just helped towards making this website more secure!', 'wp-2fa' ); ?></p>
394 <?php
395 if ( in_array( 'user_needs_to_setup_backup_codes', $userType, true ) ) {
396 ?>
397 <p><?php esc_html_e( 'You can exit this wizard now or continue to create backup codes.', 'wp-2fa' ); ?></p>
398 <?php } ?>
399 <div class="wp2fa-setup-actions">
400 <?php if ( in_array( 'user_needs_to_setup_backup_codes', $userType, true ) ) { ?>
401 <button class="button button-primary" name="next_step_setting" value="<?php esc_attr_e( 'Generate backup codes', 'wp-2fa' ); ?>" data-trigger-generate-backup-codes data-nonce="<?php echo esc_attr( $nonce ); ?>" data-user-id="<?php echo esc_attr( self::getUser()->getUser()->ID ); ?>">
402 <?php esc_html_e( 'Generate backup codes', 'wp-2fa' ); ?>
403 </button>
404 <a href="#" class="button button-secondary" data-close-2fa-modal value="<?php esc_attr_e( 'I’ll generate them later', 'wp-2fa' ); ?>">
405 <?php esc_html_e( 'I’ll generate them later', 'wp-2fa' ); ?>
406 </a>
407 <?php } else { ?>
408 <?php
409 if ( ! empty( $redirect ) ) {
410 ?>
411 <a href="<?php echo esc_url( $redirect ); ?>" class="button button-secondary close-first-time-wizard">
412 <?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?>
413 </a>
414 <?php
415 } else {
416 ?>
417 <a href="#" class="button button-secondary" data-reload>
418 <?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?>
419 </a>
420 <?php } ?>
421 <?php } ?>
422 </div>
423 </div>
424 <?php
425 }
426
427 /**
428 * Generate backup codes step
429 *
430 * @since 1.7
431 *
432 * @return void
433 */
434 public static function generateBackupCodes() {
435 $nonce = self::jsonNonce();
436
437 ?>
438 <div class="step-setting-wrapper active" data-step-title="<?php esc_html_e( 'Generate codes', 'wp-2fa' ); ?>">
439 <h3><?php esc_html_e( 'Generate backup codes', 'wp-2fa' ); ?></h3>
440 <p><?php esc_html_e( 'It is recommended to generate and print some backup codes in case you lose access to your primary 2FA method. ', 'wp-2fa' ); ?></p>
441 <div class="wp2fa-setup-actions">
442 <button class="button button-primary" name="next_step_setting" value="<?php esc_attr_e( 'Generate backup codes', 'wp-2fa' ); ?>" data-trigger-generate-backup-codes data-nonce="<?php echo esc_attr( $nonce ); ?>" data-user-id="<?php echo esc_attr( self::getUser()->getUser()->ID ); ?>">
443 <?php esc_html_e( 'Generate backup codes', 'wp-2fa' ); ?>
444 </button>
445 <a href="#" class="button button-secondary" value="<?php esc_attr_e( 'I’ll generate them later', 'wp-2fa' ); ?>" data-close-2fa-modal="">
446 <?php esc_html_e( 'I’ll generate them later', 'wp-2fa' ); ?>
447 </a>
448 </div>
449 </div>
450
451 <?php
452 }
453
454 /**
455 * Creates link for generating the backup codes
456 *
457 * @since 1.7
458 *
459 * @return void
460 */
461 public static function getGenerateCodesLink() {
462 $nonce = self::jsonNonce();
463
464 return '<a href="#" class="button button-primary remove-2fa" data-trigger-generate-backup-codes data-nonce="' . esc_attr( $nonce ) . '" data-user-id="' . esc_attr( self::getUser()->getUser()->ID ) . '" onclick="MicroModal.show( \'configure-2fa-backup-codes\' );">' . __( 'Generate Backup Codes', 'wp-2fa' ) . '</a>';
465 }
466
467 /**
468 * Shows the wrapper where backup code are generated and showed to the user
469 *
470 * @since 1.7
471 *
472 * @return void
473 */
474 public static function generatedBackupCodes( $backupOnly = false ) {
475 $nonce = self::jsonNonce();
476
477 $redirect = '';
478 if ( '' !== trim( WP2FA::get_wp2fa_setting( 'redirect-user-custom-page-global' ) ) ) {
479 $redirect = \trailingslashit( get_site_url() ) . WP2FA::get_wp2fa_setting( 'redirect-user-custom-page-global' );
480 }
481
482 ?>
483 <div class="step-setting-wrapper align-center<?php echo ( $backupOnly ) ? ' active' : ''; ?>" data-step-title="<?php esc_html_e( 'Your backup codes', 'wp-2fa' ); ?>">
484 <h3><?php esc_html_e( 'Backup codes generated', 'wp-2fa' ); ?></h3>
485 <p><?php esc_html_e( 'Here are your backup codes:', 'wp-2fa' ); ?></p>
486 <code id="backup-codes-wrapper"></code>
487 <div class="wp2fa-setup-actions">
488 <button class="button button-primary" type="submit" value="<?php esc_attr_e( 'Download', 'wp-2fa' ); ?>" data-trigger-backup-code-download data-user="<?php echo esc_attr( self::getUser()->getUser()->display_name ); ?>" data-website-url="<?php echo esc_attr( get_home_url() ); ?>">
489 <?php esc_html_e( 'Download', 'wp-2fa' ); ?>
490 </button>
491 <button class="button button-secondary" type="submit" value="<?php esc_attr_e( 'Print', 'wp-2fa' ); ?>" data-trigger-print data-nonce="<?php echo esc_attr( $nonce ); ?>" data-user-id="<?php echo esc_attr( self::getUser()->getUser()->display_name ); ?>" data-website-url="<?php echo esc_attr( get_home_url() ); ?>">
492 <?php esc_html_e( 'Print', 'wp-2fa' ); ?>
493 </button>
494 <?php
495 if ( ! empty( $redirect ) ) {
496 ?>
497 <a href="<?php echo esc_url( $redirect ); ?>" class="button button-secondary close-first-time-wizard">
498 <?php esc_html_e( 'I\'m ready, close the wizard', 'wp-2fa' ); ?>
499 </a>
500 <?php
501 } else {
502 ?>
503 <button class="button button-secondary" type="submit" data-close-2fa-modal-and-refresh>
504 <?php esc_html_e( 'I\'m ready, close the wizard', 'wp-2fa' ); ?>
505 </button>
506 <?php } ?>
507 </div>
508 </div>
509 <?php
510 }
511
512 /**
513 * Final step for congratulating the user
514 *
515 * @since 1.7
516 *
517 * @param boolean $setupWizard
518 *
519 * @return void
520 */
521 public static function congratulationsStep( $setupWizard = false ) {
522
523 if ( $setupWizard ) {
524 self::congratulationsStepPluginWizard();
525 return;
526 }
527 ?>
528
529 <div class="step-setting-wrapper active">
530 <h3><?php esc_html_e( 'Congratulations! You are all set.', 'wp-2fa' ); ?></h3>
531 <div class="wp2fa-setup-actions">
532 <button class="modal__btn button" data-close-2fa-modal aria-label="Close this dialog window"><?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?></button>
533 </div>
534 </div>
535 <?php
536 }
537
538 /**
539 * Final step for congratulating the user
540 *
541 * @since 1.7
542 *
543 * @return void
544 */
545 public static function congratulationsStepPluginWizard() {
546 $redirect = get_edit_profile_url( self::getUser()->getUser()->ID );
547
548 if ( '' !== trim( WP2FA::get_wp2fa_setting( 'redirect-user-custom-page-global' ) ) ) {
549 $redirect = \trailingslashit( get_site_url() ) . WP2FA::get_wp2fa_setting( 'redirect-user-custom-page-global' );
550 }
551 ?>
552 <h3><?php esc_html_e( 'Congratulations, you\'re almost there...', 'wp-2fa' ); ?></h3>
553 <p><?php esc_html_e( 'Great job, the plugin and 2FA policies are now configured. You can always change the plugin settings and 2FA policies at a later stage from the WP 2FA entry in the WordPress menu.', 'wp-2fa' ); ?></p>
554
555 <?php
556 if ( WP2FA::is_user_excluded( self::getUser()->getUser()->ID ) ) {
557 ?>
558 <div class="wp2fa-setup-actions">
559 <a href="<?php echo esc_url( $redirect ); ?>" class="button button-secondary close-first-time-wizard">
560 <?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?>
561 </a>
562 </div>
563 <?php
564 } else {
565 ?>
566 <p><?php esc_html_e( 'Now you need to configure 2FA for your own user account. You can do this now (recommended) or later.', 'wp-2fa' ); ?></p>
567 <div class="wp2fa-setup-actions">
568 <a href="<?php echo esc_url( Settings::getSetupPageLink() ); ?>" class="button button-secondary">
569 <?php esc_html_e( 'Configure 2FA now', 'wp-2fa' ); ?>
570 </a>
571 <a href="<?php echo esc_url( $redirect ); ?>" class="button button-secondary close-first-time-wizard">
572 <?php esc_html_e( 'Close wizard & configure 2FA later', 'wp-2fa' ); ?>
573 </a>
574 </div>
575 <?php } ?>
576 <?php
577 }
578
579 /**
580 * Shows the methods in the modal wizard, so the user can choose from the available ones
581 *
582 * @return void
583 */
584 public static function showModalMethods() {
585 if ( self::isTotpEnabled() ) {
586 ?>
587 <div class="wizard-step" id="2fa-wizard-totp">
588 <fieldset>
589 <?php WizardSteps::totpConfigure(); ?>
590 </fieldset>
591 </div>
592 <?php
593 }
594 if ( self::isMailEnabled() ) {
595 ?>
596 <div class="wizard-step" id="2fa-wizard-email">
597 <fieldset>
598 <?php WizardSteps::emailConfigure(); ?>
599 </fieldset>
600 </div>
601 <?php
602 }
603 }
604
605 /**
606 * Gets the current user
607 *
608 * @since 1.7
609 *
610 * @return \WP2FA\Admin\User
611 */
612 private static function getUser() {
613 if ( null === self::$user ) {
614 self::$user = new User();
615 }
616
617 return self::$user;
618 }
619
620 /**
621 * Returns the status of the totp method (enabled | disabled)
622 *
623 * @since 1.7
624 *
625 * @return boolean
626 */
627 private static function isTotpEnabled(): bool {
628 if ( null === self::$totpEnabled ) {
629 self::$totpEnabled = empty( WP2FA::get_wp2fa_setting( 'enable_totp' ) ) ? false : true;
630 }
631
632 return self::$totpEnabled;
633 }
634
635 /**
636 * Returns the status of the mail method (enabled | disabled)
637 *
638 * @since 1.7
639 *
640 * @return boolean
641 */
642 private static function isMailEnabled(): bool {
643 if ( null === self::$emailEnabled ) {
644 self::$emailEnabled = empty( WP2FA::get_wp2fa_setting( 'enable_email' ) ) ? false : true;
645 }
646
647 return self::$emailEnabled;
648 }
649
650 /**
651 * Retrieves the QR code
652 *
653 * @since 1.7
654 *
655 * @return string
656 */
657 private static function getQRCode(): string {
658
659 // Setup site information, used when generating our QR code.
660 $siteName = get_bloginfo( 'name', 'display' );
661 $totpTitle = apply_filters(
662 'wp_2fa_totp_title',
663 $siteName . ':' . self::getUser()->getUser()->user_login,
664 self::getUser()->getUser()
665 );
666
667 return Authentication::get_google_qr_code( $totpTitle, self::getUser()->getTotpKey(), $siteName );
668 }
669
670 /**
671 * Generates nonce for JSON calls
672 *
673 * @since 1.7
674 *
675 * @return string
676 */
677 private static function jsonNonce() {
678 if ( null === self::$jsonNonce ) {
679 self::$jsonNonce = wp_create_nonce( 'wp-2fa-backup-codes-generate-json-' . self::getUser()->getUser()->ID );
680 }
681
682 return self::$jsonNonce;
683 }
684 }
685