diff --git a/js/admin-backup-codes.js b/js/admin-backup-codes.js new file mode 100644 index 00000000..d81f3575 --- /dev/null +++ b/js/admin-backup-codes.js @@ -0,0 +1,38 @@ +(function(){ + const backupCodes = document.getElementById( 'two-factor-backup-codes' ), + generateCodesButton = backupCodes.querySelector( '.button-two-factor-backup-codes-generate' ), + userId = backupCodes.dataset.userid || 0; + + // Backup Codes generation + generateCodesButton.addEventListener( 'click', function(e) { + const codesCountDiv = backupCodes.querySelector( '.two-factor-backup-codes-count' ), + codeWrapper = backupCodes.querySelector( '.two-factor-backup-codes-wrapper' ), + codeList = backupCodes.querySelector( '.two-factor-backup-codes-unused-codes' ), + downloadButton = backupCodes.querySelector( '.button-two-factor-backup-codes-download' ); + + wp.apiRequest( { + method: 'POST', + path: 'two-factor/1.0/generate-backup-codes', + data: { + user_id: userId + } + } ).then( function( response ) { + codeList.innerHTML = ''; + + // Append the codes. + for ( i = 0; i < response.codes.length; i++ ) { + codeList.innerHTML += '
+
- - - get_user_totp_key( $user->ID ); - wp_enqueue_script( 'two-factor-qr-code-generator' ); + wp_enqueue_script( 'two-factor-totp' ); ?> -
@@ -384,23 +333,6 @@ public function user_two_factor_options( $user ) { -
', $buffer ); + $this->assertStringContainsString( '