Allow customization of portal JS code with jQuery events
Summary
I sometimes need to add custom JS code to the portal. A typical example is doing something after a TOTP registration.
Currently, I have to modify totpregistration.js
to do so. But this makes maintenance difficult.
I think the JS files provided by the portal should trigger events in some situations, and these events can be caught by custom code
Design proposition
Example in totpregistration.js
# Right after the AJAX call to register the TOTP device:
success: (data) ->
if data.error
if data.error.match /bad(Code|Name)/
setMsg data.error, 'warning'
else
setMsg data.error, 'danger'
else
# Trigger a mfaAdded event
$(document).trigger "mfaAdded", [ { "type": "totp" } ]
setMsg 'yourKeyIsRegistered', 'success'
And now, in your skin's custom JS file:
$(document).on( "mfaAdded", { }, function( event, info ) {
console.log( "Added a new " + info.type + "MFA" );
// Your code here: info popup, redirection, etc.
});