| 1 |
<?php |
| 2 |
/** |
| 3 |
* Two-Factor Authentication User Profile Section |
| 4 |
* |
| 5 |
* Displays 2FA settings and enrollment UI on the user profile page. |
| 6 |
* |
| 7 |
* @package AtomicEdge |
| 8 |
* @since 1.7.0 |
| 9 |
* |
| 10 |
* @var WP_User $user User object. |
| 11 |
* @var array $status 2FA status array from AtomicEdge_2FA::get_user_status(). |
| 12 |
*/ |
| 13 |
|
| 14 |
// Prevent direct access. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
// Check if encryption is available. |
| 20 |
$is_available = AtomicEdge_2FA::is_available(); |
| 21 |
?> |
| 22 |
|
| 23 |
<div class="atomicedge-2fa-section" id="atomicedge-2fa-section"> |
| 24 |
<h2> |
| 25 |
<span class="dashicons dashicons-lock"></span> |
| 26 |
<?php esc_html_e( 'Two-Factor Authentication', 'atomic-edge-security' ); ?> |
| 27 |
<?php if ( $status['enabled'] ) : ?> |
| 28 |
<span class="atomicedge-2fa-badge active"><?php esc_html_e( 'Active', 'atomic-edge-security' ); ?></span> |
| 29 |
<?php else : ?> |
| 30 |
<span class="atomicedge-2fa-badge inactive"><?php esc_html_e( 'Inactive', 'atomic-edge-security' ); ?></span> |
| 31 |
<?php endif; ?> |
| 32 |
</h2> |
| 33 |
|
| 34 |
<?php if ( ! $is_available ) : ?> |
| 35 |
<div class="notice notice-error inline"> |
| 36 |
<p> |
| 37 |
<?php esc_html_e( 'Two-factor authentication requires PHP 7.2+ with the Sodium extension. Please contact your hosting provider.', 'atomic-edge-security' ); ?> |
| 38 |
</p> |
| 39 |
</div> |
| 40 |
<?php elseif ( $status['enabled'] ) : ?> |
| 41 |
<!-- 2FA is enabled - show status and management options --> |
| 42 |
<div id="atomicedge-2fa-enabled"> |
| 43 |
<dl class="atomicedge-2fa-status"> |
| 44 |
<dt><?php esc_html_e( 'Method', 'atomic-edge-security' ); ?></dt> |
| 45 |
<dd><?php esc_html_e( 'Authenticator App (TOTP)', 'atomic-edge-security' ); ?></dd> |
| 46 |
|
| 47 |
<?php if ( $status['setup_date'] ) : ?> |
| 48 |
<dt><?php esc_html_e( 'Enabled', 'atomic-edge-security' ); ?></dt> |
| 49 |
<dd><?php echo esc_html( $status['setup_date'] ); ?></dd> |
| 50 |
<?php endif; ?> |
| 51 |
|
| 52 |
<?php if ( $status['last_used'] ) : ?> |
| 53 |
<dt><?php esc_html_e( 'Last Used', 'atomic-edge-security' ); ?></dt> |
| 54 |
<dd><?php echo esc_html( $status['last_used'] ); ?></dd> |
| 55 |
<?php endif; ?> |
| 56 |
|
| 57 |
<dt><?php esc_html_e( 'Backup Codes', 'atomic-edge-security' ); ?></dt> |
| 58 |
<dd> |
| 59 |
<?php |
| 60 |
printf( |
| 61 |
/* translators: 1: Remaining codes count, 2: Total codes count */ |
| 62 |
esc_html__( '%1$d of %2$d remaining', 'atomic-edge-security' ), |
| 63 |
(int) $status['codes_remaining'], |
| 64 |
(int) $status['codes_total'] |
| 65 |
); |
| 66 |
?> |
| 67 |
<?php if ( $status['codes_remaining'] <= 2 ) : ?> |
| 68 |
<span style="color: #d63638;"> |
| 69 |
<?php esc_html_e( '(Low - consider regenerating)', 'atomic-edge-security' ); ?> |
| 70 |
</span> |
| 71 |
<?php endif; ?> |
| 72 |
</dd> |
| 73 |
</dl> |
| 74 |
|
| 75 |
<p class="submit"> |
| 76 |
<button type="button" class="button" id="atomicedge-2fa-regenerate-codes"> |
| 77 |
<?php esc_html_e( 'Regenerate Backup Codes', 'atomic-edge-security' ); ?> |
| 78 |
</button> |
| 79 |
<button type="button" class="button button-link-delete" id="atomicedge-2fa-disable"> |
| 80 |
<?php esc_html_e( 'Disable Two-Factor', 'atomic-edge-security' ); ?> |
| 81 |
</button> |
| 82 |
</p> |
| 83 |
</div> |
| 84 |
|
| 85 |
<!-- Backup codes display (shown after regeneration) --> |
| 86 |
<div id="atomicedge-2fa-codes-display" style="display: none;"> |
| 87 |
<div class="atomicedge-2fa-warning"> |
| 88 |
<p><strong><?php esc_html_e( '⚠️ Save These Backup Codes', 'atomic-edge-security' ); ?></strong></p> |
| 89 |
<p><?php esc_html_e( 'Each code can only be used once. Store them in a safe place.', 'atomic-edge-security' ); ?></p> |
| 90 |
</div> |
| 91 |
|
| 92 |
<div class="atomicedge-2fa-codes" id="atomicedge-2fa-codes-list"> |
| 93 |
<!-- Codes inserted by JavaScript --> |
| 94 |
</div> |
| 95 |
|
| 96 |
<p class="submit"> |
| 97 |
<button type="button" class="button button-primary" id="atomicedge-2fa-download-codes"> |
| 98 |
<span class="dashicons dashicons-download" style="vertical-align: middle;"></span> |
| 99 |
<?php esc_html_e( 'Download Backup Codes', 'atomic-edge-security' ); ?> |
| 100 |
</button> |
| 101 |
<button type="button" class="button" id="atomicedge-2fa-codes-done"> |
| 102 |
<?php esc_html_e( 'I\'ve Saved My Codes', 'atomic-edge-security' ); ?> |
| 103 |
</button> |
| 104 |
</p> |
| 105 |
</div> |
| 106 |
|
| 107 |
<!-- Password confirmation dialog for disable --> |
| 108 |
<div id="atomicedge-2fa-disable-confirm" style="display: none;"> |
| 109 |
<p><?php esc_html_e( 'Enter your password to disable two-factor authentication:', 'atomic-edge-security' ); ?></p> |
| 110 |
<p> |
| 111 |
<label for="atomicedge-2fa-password"><?php esc_html_e( 'Password', 'atomic-edge-security' ); ?></label> |
| 112 |
<input type="password" id="atomicedge-2fa-password" class="regular-text" /> |
| 113 |
</p> |
| 114 |
<p class="submit"> |
| 115 |
<button type="button" class="button button-link-delete" id="atomicedge-2fa-disable-confirm-btn"> |
| 116 |
<?php esc_html_e( 'Disable Two-Factor', 'atomic-edge-security' ); ?> |
| 117 |
</button> |
| 118 |
<button type="button" class="button" id="atomicedge-2fa-disable-cancel"> |
| 119 |
<?php esc_html_e( 'Cancel', 'atomic-edge-security' ); ?> |
| 120 |
</button> |
| 121 |
</p> |
| 122 |
</div> |
| 123 |
|
| 124 |
<?php else : ?> |
| 125 |
<!-- 2FA is not enabled - show enrollment UI --> |
| 126 |
|
| 127 |
<!-- Step 1: Introduction --> |
| 128 |
<div class="atomicedge-2fa-step active" id="atomicedge-2fa-step-intro"> |
| 129 |
<p> |
| 130 |
<?php esc_html_e( 'Two-factor authentication adds an extra layer of security to your account by requiring a code from your authenticator app in addition to your password.', 'atomic-edge-security' ); ?> |
| 131 |
</p> |
| 132 |
<p class="submit"> |
| 133 |
<button type="button" class="button button-primary button-hero" id="atomicedge-2fa-start"> |
| 134 |
<?php esc_html_e( 'Enable Two-Factor Authentication', 'atomic-edge-security' ); ?> |
| 135 |
</button> |
| 136 |
</p> |
| 137 |
</div> |
| 138 |
|
| 139 |
<!-- Step 2: QR Code and Secret --> |
| 140 |
<div class="atomicedge-2fa-step" id="atomicedge-2fa-step-setup"> |
| 141 |
<p><strong><?php esc_html_e( 'Step 1:', 'atomic-edge-security' ); ?></strong> <?php esc_html_e( 'Scan this QR code with your authenticator app:', 'atomic-edge-security' ); ?></p> |
| 142 |
|
| 143 |
<div class="atomicedge-2fa-qr"> |
| 144 |
<canvas id="atomicedge-2fa-qrcode"></canvas> |
| 145 |
<p> |
| 146 |
<?php esc_html_e( 'Or enter this code manually:', 'atomic-edge-security' ); ?><br> |
| 147 |
<code class="atomicedge-2fa-secret" id="atomicedge-2fa-secret-display"></code> |
| 148 |
</p> |
| 149 |
</div> |
| 150 |
|
| 151 |
<p><strong><?php esc_html_e( 'Step 2:', 'atomic-edge-security' ); ?></strong> <?php esc_html_e( 'Enter the 6-digit code from your app to verify:', 'atomic-edge-security' ); ?></p> |
| 152 |
|
| 153 |
<div class="atomicedge-2fa-verify-form"> |
| 154 |
<input type="text" id="atomicedge-2fa-verify-code" class="regular-text" placeholder="000000" maxlength="6" pattern="[0-9]*" inputmode="numeric" autocomplete="one-time-code" /> |
| 155 |
<p id="atomicedge-2fa-verify-error" class="description" style="color: #d63638; display: none;"></p> |
| 156 |
</div> |
| 157 |
|
| 158 |
<p class="submit"> |
| 159 |
<button type="button" class="button button-primary" id="atomicedge-2fa-verify"> |
| 160 |
<?php esc_html_e( 'Verify & Enable', 'atomic-edge-security' ); ?> |
| 161 |
</button> |
| 162 |
<button type="button" class="button" id="atomicedge-2fa-cancel"> |
| 163 |
<?php esc_html_e( 'Cancel', 'atomic-edge-security' ); ?> |
| 164 |
</button> |
| 165 |
</p> |
| 166 |
</div> |
| 167 |
|
| 168 |
<!-- Step 3: Backup Codes --> |
| 169 |
<div class="atomicedge-2fa-step" id="atomicedge-2fa-step-codes"> |
| 170 |
<div class="notice notice-success inline"> |
| 171 |
<p><strong><?php esc_html_e( '✓ Two-factor authentication is now enabled!', 'atomic-edge-security' ); ?></strong></p> |
| 172 |
</div> |
| 173 |
|
| 174 |
<div class="atomicedge-2fa-warning"> |
| 175 |
<p><strong><?php esc_html_e( '⚠️ Save These Backup Codes', 'atomic-edge-security' ); ?></strong></p> |
| 176 |
<p><?php esc_html_e( 'If you lose access to your authenticator app, you can use these codes to log in. Each code can only be used once.', 'atomic-edge-security' ); ?></p> |
| 177 |
</div> |
| 178 |
|
| 179 |
<div class="atomicedge-2fa-codes" id="atomicedge-2fa-new-codes"> |
| 180 |
<!-- Codes inserted by JavaScript --> |
| 181 |
</div> |
| 182 |
|
| 183 |
<p class="submit"> |
| 184 |
<button type="button" class="button button-primary" id="atomicedge-2fa-download-new-codes"> |
| 185 |
<span class="dashicons dashicons-download" style="vertical-align: middle;"></span> |
| 186 |
<?php esc_html_e( 'Download Backup Codes', 'atomic-edge-security' ); ?> |
| 187 |
</button> |
| 188 |
<button type="button" class="button" id="atomicedge-2fa-finish"> |
| 189 |
<?php esc_html_e( 'I\'ve Saved My Codes', 'atomic-edge-security' ); ?> |
| 190 |
</button> |
| 191 |
</p> |
| 192 |
</div> |
| 193 |
<?php endif; ?> |
| 194 |
|
| 195 |
<!-- Loading indicator --> |
| 196 |
<div id="atomicedge-2fa-loading" style="display: none;"> |
| 197 |
<span class="spinner is-active" style="float: none; margin: 0;"></span> |
| 198 |
<?php esc_html_e( 'Please wait...', 'atomic-edge-security' ); ?> |
| 199 |
</div> |
| 200 |
</div> |
| 201 |
|