| 1 |
<div id="defender-totp" class="<?php echo esc_attr( $class ); ?>"> |
| 2 |
<div class="card"> |
| 3 |
<strong> |
| 4 |
<?php _e( '1. Install the Verification app', 'wpdef' ); ?> |
| 5 |
</strong> |
| 6 |
<p> |
| 7 |
<?php |
| 8 |
_e( 'Download and install the authenticator app on your device using the links below.', 'wpdef' ); |
| 9 |
?> |
| 10 |
<select id="auth-app"> |
| 11 |
<?php |
| 12 |
foreach ( $auth_apps as $key => $app ) { ?> |
| 13 |
<option value="<?php echo $key; ?>"><?php echo $app; ?></option> |
| 14 |
<?php } ?> |
| 15 |
</select> |
| 16 |
</p> |
| 17 |
<a id="ios-app" target="_blank" href="https://itunes.apple.com/vn/app/google-authenticator/id388497605?mt=8"> |
| 18 |
<img src="<?php echo defender_asset_url( '/assets/img/ios-download.svg' ); ?>" /> |
| 19 |
</a> |
| 20 |
<a id="android-app" target="_blank" |
| 21 |
href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2"> |
| 22 |
<img src="<?php echo defender_asset_url( '/assets/img/android-download.svg' ); ?> "/> |
| 23 |
</a> |
| 24 |
<div class="line"></div> |
| 25 |
<strong> |
| 26 |
<?php _e( '2. Scan the QR code or enter the key', 'wpdef' ); ?> |
| 27 |
</strong> |
| 28 |
<p class="wd_text_wrap"> |
| 29 |
<?php |
| 30 |
_e( |
| 31 |
'Open the authenticator app, and scan the QR code below or manually enter the setup key to add your new site.', |
| 32 |
'wpdef' |
| 33 |
) |
| 34 |
?> |
| 35 |
</p> |
| 36 |
<?php |
| 37 |
WP_Defender\Component\Two_Factor\Providers\Totp::generate_qr_code( $secret_key ); |
| 38 |
?> |
| 39 |
<p class="wd_code_wrap"> |
| 40 |
<code id="wd_clipboard"><?php echo esc_html( $secret_key ); ?></code> |
| 41 |
<button type="button" class="button" id="wd_copy_2fa_key" |
| 42 |
data-clipborad-action="copy" data-clipboard-target="#wd_clipboard"> |
| 43 |
<?php _e( 'Copy', 'wpdef' ); ?> |
| 44 |
</button> |
| 45 |
</p> |
| 46 |
<div class="line"></div> |
| 47 |
<strong> |
| 48 |
<?php _e( '3. Enter passcode', 'wpdef' ); ?> |
| 49 |
</strong> |
| 50 |
<p> |
| 51 |
<?php |
| 52 |
_e( |
| 53 |
'Enter the 6 digit passcode that is shown on your device into the input field below and hit "Verify".', |
| 54 |
'wpdef' |
| 55 |
) |
| 56 |
?> |
| 57 |
</p> |
| 58 |
<div class="well" style="width: auto;"> |
| 59 |
<p class="error"></p> |
| 60 |
<input type="text" id="otp-code" class="def-small-text" |
| 61 |
placeholder="<?php _e( 'Enter passcode', 'wpdef' ); ?>" /> |
| 62 |
<button type="button" class="button button-primary" id="verify-otp"> |
| 63 |
<?php _e( 'Verify', 'wpdef' ); ?> |
| 64 |
</button> |
| 65 |
</div> |
| 66 |
</div> |
| 67 |
</div> |
| 68 |
<script type="text/javascript"> |
| 69 |
jQuery(function ($) { |
| 70 |
// Copy/past the key. |
| 71 |
new ClipboardJS('#wd_copy_2fa_key'); |
| 72 |
// Toggle. |
| 73 |
$('body').on('click', '#field-totp', function(){ |
| 74 |
$( '#defender-totp' ).toggle(); |
| 75 |
}); |
| 76 |
|
| 77 |
var links = { |
| 78 |
'google-authenticator': { |
| 79 |
android: 'https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2', |
| 80 |
ios: 'https://apps.apple.com/app/google-authenticator/id388497605' |
| 81 |
}, |
| 82 |
'microsoft-authenticator': { |
| 83 |
android: 'https://play.google.com/store/apps/details?id=com.azure.authenticator', |
| 84 |
ios: 'https://apps.apple.com/app/microsoft-authenticator/id983156458' |
| 85 |
}, |
| 86 |
'authy': { |
| 87 |
android: 'https://play.google.com/store/apps/details?id=com.authy.authy', |
| 88 |
ios: 'https://apps.apple.com/app/authy/id494168017' |
| 89 |
} |
| 90 |
}; |
| 91 |
$('body').on('change', '#auth-app', function () { |
| 92 |
var value = $(this).val(); |
| 93 |
var app = links[value]; |
| 94 |
if (typeof app !== 'undefined') { |
| 95 |
$('#android-app').attr('href', app.android); |
| 96 |
$('#ios-app').attr('href', app.ios) |
| 97 |
} |
| 98 |
}) |
| 99 |
|
| 100 |
function verify_otp(el) { |
| 101 |
var data = { |
| 102 |
data: JSON.stringify({ |
| 103 |
otp: $('#otp-code').val(), |
| 104 |
}) |
| 105 |
} |
| 106 |
$.ajax({ |
| 107 |
type: 'POST', |
| 108 |
url: '<?php echo $url; ?>', |
| 109 |
data: data, |
| 110 |
beforeSend: function () { |
| 111 |
el.attr('disabled', 'disabled'); |
| 112 |
}, |
| 113 |
success: function (data) { |
| 114 |
if (data.success == true) { |
| 115 |
location.reload(); |
| 116 |
} else { |
| 117 |
el.removeAttr('disabled'); |
| 118 |
el.closest('.well').find('.error').text(data.data.message).show(); |
| 119 |
} |
| 120 |
} |
| 121 |
}); |
| 122 |
} |
| 123 |
|
| 124 |
$('body').on('click', '#verify-otp', function () { |
| 125 |
verify_otp($(this)); |
| 126 |
}) |
| 127 |
|
| 128 |
$(window).on('keydown', function (event) { |
| 129 |
if (event.keyCode == 13) { |
| 130 |
if (jQuery(event.target).attr('id') === 'otp-code') { |
| 131 |
verify_otp(jQuery(event.target)) |
| 132 |
} |
| 133 |
} |
| 134 |
}); |
| 135 |
}) |
| 136 |
</script> |
| 137 |
|