mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 20:53:53 +01:00
MDL-81551 factor_webauthn: inform user on successful key registration.
This commit is contained in:
parent
fc29adddf9
commit
0d616b13e1
@ -6,6 +6,6 @@
|
||||
* @author Alex Morris <alex.morris@catalyst.net.nz>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("factor_webauthn/register",["factor_webauthn/utils","core/log"],(function(utils,Log){async function registerSecurityKey(createArgs){try{if(!navigator.credentials||!navigator.credentials.create)throw new Error("Browser not supported.");if(!1===createArgs.success)throw new Error(createArgs.msg||"unknown error occurred");utils.recursiveBase64StrToArrayBuffer(createArgs);const cred=await navigator.credentials.create(createArgs),authenticatorResponse={transports:cred.response.getTransports?cred.response.getTransports():null,clientDataJSON:cred.response.clientDataJSON?utils.arrayBufferToBase64(cred.response.clientDataJSON):null,attestationObject:cred.response.attestationObject?utils.arrayBufferToBase64(cred.response.attestationObject):null};document.getElementById("id_response_input").value=JSON.stringify(authenticatorResponse),document.getElementById("id_submitbutton").disabled=!1}catch(e){Log.debug("The request timed out or you have canceled the request. Please try again later.")}}return{init:function(createArgs){document.getElementById("id_submitbutton").disabled=!0,createArgs=JSON.parse(createArgs),document.getElementById("factor_webauthn-register").addEventListener("click",(function(){registerSecurityKey(createArgs)})),document.getElementById("factor_webauthn-register").addEventListener("keypress",(function(){registerSecurityKey(createArgs)}))}}}));
|
||||
define("factor_webauthn/register",["factor_webauthn/utils","core/log","core/prefetch","core/str","core/toast"],(function(utils,Log,Prefetch,Str,Toast){async function registerSecurityKey(createArgs){try{if(!navigator.credentials||!navigator.credentials.create)throw new Error("Browser not supported.");if(!1===createArgs.success)throw new Error(createArgs.msg||"unknown error occurred");utils.recursiveBase64StrToArrayBuffer(createArgs);const cred=await navigator.credentials.create(createArgs),authenticatorResponse={transports:cred.response.getTransports?cred.response.getTransports():null,clientDataJSON:cred.response.clientDataJSON?utils.arrayBufferToBase64(cred.response.clientDataJSON):null,attestationObject:cred.response.attestationObject?utils.arrayBufferToBase64(cred.response.attestationObject):null},registerSuccess=await Str.getString("registersuccess","factor_webauthn");await Toast.add(registerSuccess,{type:"success"}),document.getElementById("id_response_input").value=JSON.stringify(authenticatorResponse),document.getElementById("id_submitbutton").disabled=!1}catch(e){Log.debug("The request timed out or you have canceled the request. Please try again later.")}}return{init:function(createArgs){document.getElementById("id_submitbutton").disabled=!0,Prefetch.prefetchStrings("factor_webauthn",["registersuccess"]),createArgs=JSON.parse(createArgs),document.getElementById("factor_webauthn-register").addEventListener("click",(function(){registerSecurityKey(createArgs)})),document.getElementById("factor_webauthn-register").addEventListener("keypress",(function(){registerSecurityKey(createArgs)}))}}}));
|
||||
|
||||
//# sourceMappingURL=register.min.js.map
|
File diff suppressed because one or more lines are too long
@ -22,7 +22,20 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define(['factor_webauthn/utils', 'core/log'], function(utils, Log) {
|
||||
define([
|
||||
'factor_webauthn/utils',
|
||||
'core/log',
|
||||
'core/prefetch',
|
||||
'core/str',
|
||||
'core/toast',
|
||||
], function(
|
||||
utils,
|
||||
Log,
|
||||
Prefetch,
|
||||
Str,
|
||||
Toast,
|
||||
) {
|
||||
|
||||
/**
|
||||
* Register the security key.
|
||||
*
|
||||
@ -47,6 +60,10 @@ define(['factor_webauthn/utils', 'core/log'], function(utils, Log) {
|
||||
attestationObject: cred.response.attestationObject ?
|
||||
utils.arrayBufferToBase64(cred.response.attestationObject) : null,
|
||||
};
|
||||
|
||||
const registerSuccess = await Str.getString('registersuccess', 'factor_webauthn');
|
||||
await Toast.add(registerSuccess, {type: 'success'});
|
||||
|
||||
document.getElementById('id_response_input').value = JSON.stringify(authenticatorResponse);
|
||||
// Enable the submit button so that we can proceed.
|
||||
document.getElementById('id_submitbutton').disabled = false;
|
||||
@ -59,8 +76,13 @@ define(['factor_webauthn/utils', 'core/log'], function(utils, Log) {
|
||||
init: function(createArgs) {
|
||||
// Disable the submit button until we have registered a security key.
|
||||
document.getElementById('id_submitbutton').disabled = true;
|
||||
createArgs = JSON.parse(createArgs);
|
||||
|
||||
Prefetch.prefetchStrings('factor_webauthn', [
|
||||
'registersuccess',
|
||||
]);
|
||||
|
||||
// Register event listeners.
|
||||
createArgs = JSON.parse(createArgs);
|
||||
document.getElementById('factor_webauthn-register').addEventListener('click', function() {
|
||||
registerSecurityKey(createArgs);
|
||||
});
|
||||
|
@ -42,6 +42,7 @@ $string['logintitle'] = 'Verify it\'s you by security key';
|
||||
$string['pluginname'] = 'Security key';
|
||||
$string['privacy:metadata'] = 'The Security key factor plugin does not store any personal data.';
|
||||
$string['register'] = 'Register security key';
|
||||
$string['registersuccess'] = 'Registered security key';
|
||||
$string['replacefactor'] = 'Replace security key';
|
||||
$string['replacefactorconfirmation'] = 'Replace \'{$a}\' security key?';
|
||||
$string['revokefactorconfirmation'] = 'Remove \'{$a}\' security key?';
|
||||
|
Loading…
x
Reference in New Issue
Block a user