loleaflet/html/signing-identities.html | 20 +++ loleaflet/src/control/Signing.js | 186 ++++++++++++++++++++++++++++++--- 2 files changed, 194 insertions(+), 12 deletions(-)
New commits: commit 91218de5b03b45448f6e8cb0ea2c7cabb7fb9c2e Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu Nov 22 14:41:43 2018 +0100 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Thu Nov 29 21:47:31 2018 +0100 extract vereign server URL Change-Id: I11fb8b26a1919550817f07502bb3dca0541487be Reviewed-on: https://gerrit.libreoffice.org/63838 Reviewed-by: Tomaž Vajngerl <[email protected]> Tested-by: Tomaž Vajngerl <[email protected]> diff --git a/loleaflet/src/control/Signing.js b/loleaflet/src/control/Signing.js index aa0550065..af890a434 100644 --- a/loleaflet/src/control/Signing.js +++ b/loleaflet/src/control/Signing.js @@ -9,6 +9,8 @@ var library = null; var identity = null; var currentPassport = null; +var vereignURL = 'https://integration2.vereign.com'; + function isSuccess(result) { return result.code == '200'; } @@ -325,9 +327,8 @@ L.Map.include({ } } }, - 'https://integration2.vereign.com/api/js/iframe' - ).then(function(lib) - { + vereignURL + '/api/js/iframe' + ).then(function(lib) { library = lib; adjustUIState(); }); commit 15b8f9600933d3ec74beaec6f5ce262d4aba9602 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu Nov 22 12:20:12 2018 +0100 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Thu Nov 29 21:47:23 2018 +0100 Vereign login logic and dialogs This adds various Vereign login dialogs: - pin code dialog - QR dialog - email/sms dialog Change-Id: I2400c76a7dbbb44ead10f6baaac561a71d3acd7f Reviewed-on: https://gerrit.libreoffice.org/63837 Reviewed-by: Tomaž Vajngerl <[email protected]> Tested-by: Tomaž Vajngerl <[email protected]> diff --git a/loleaflet/html/signing-identities.html b/loleaflet/html/signing-identities.html new file mode 100644 index 000000000..c40b5f8cc --- /dev/null +++ b/loleaflet/html/signing-identities.html @@ -0,0 +1,20 @@ +<style type="text/css"> +.identity-button { + background-color: #994392; + border: none; + color: white; + padding: 20px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 32px; + margin: 4px 2px; + cursor: pointer; + border-radius: 50%; +} +</style> + +<p>Select identity:</p> +<p><div id="identites"></div></p> +<p><a href="#" id="login-qr">Login from mobile</a></p> +<p><a href="#" id="recover-from-email">Recover from email</a></p> diff --git a/loleaflet/src/control/Signing.js b/loleaflet/src/control/Signing.js index 5318b3089..aa0550065 100644 --- a/loleaflet/src/control/Signing.js +++ b/loleaflet/src/control/Signing.js @@ -3,7 +3,7 @@ * Document Signing */ -/* global window setupViamAPI w2ui */ +/* global window setupViamAPI w2ui vex $ */ var library = null; var identity = null; @@ -107,6 +107,120 @@ function adjustUIState() { w2ui['document-signing-bar'].refresh(); } +function vereignPinCodeDialog(selectedIdentityKey) { + vex.dialog.open({ + message: 'PIN Code', + input: '<input name="pincode" type="text" value="" required />', + callback: function(data) { + console.log(data.pincode); + if (data.pincode) { + if (library) { + return library.loadIdentity(selectedIdentityKey, data.pincode).then(function(result) { + if (isSuccess(result)) { + identity = result.data; + vereignLogin(); + } + else { + identity = null; + } + }); + } + } + } + }); +} + +function vereignLogin() { + if (library && identity) { + library.login(identity, 'previousaddeddevice').then(function(result) { + console.log(result); + if (isSuccess(result)) { + updateIndentity(); + updatePassportList(); + adjustUIState(); + } + }); + } +} + +function verignQrDialog() { + if (library) { + library.createIdentity('00000000').then(function(result) { + if (isSuccess(result)) { + library.login(result.data, 'newdevice').then(function(result) { + vex.open({ + content: '<div id="image-container"></div>', + showCloseButton: true, + escapeButtonCloses: true, + overlayClosesOnClick: true, + buttons: {}, + afterOpen: function($vexContent) { + var container = $vexContent.find('#image-container'); + var image = $('<img style="display: block; margin-left: auto; margin-right: auto"/>'); + image.attr('src', result.data.image); + container.append(image); + }, + }); + }); + } + }); + } +} + +function vereignRecoverFromEmail() { + if (library == null) { + return; + } + vex.dialog.open({ + message: 'Login from email or mobile number', + input: '<input name="emailOrMobileNumber" type="text" value="" required />', + callback: function(data) { + if (data.emailOrMobileNumber) { + library.createIdentity('00000000').then(function(result) { + if (isSuccess(result)) { + var createdIdentity = result.data; + library.identityRestoreAccess(result.data, data.emailOrMobileNumber).then(function(result) { + if (isSuccess(result)) { + vex.dialog.open({ + message: 'PIN Code', + input: '<p>Check your email</p><input name="pincode" type="text" value="" required />', + callback: function(data) { + console.log(data.pincode); + if (data.pincode) { + if (library) { + library.login(createdIdentity, 'sms', data.pincode).then(function(result) { + if (isSuccess(result)) { + vereignRestoreIdentity(); + } + }); + } + } + } + }); + } + }); + } + }); + } + } + }); +} + +function vereignRestoreIdentity() { + if (library == null) { + return; + } + library.getCurrentlyAuthenticatedIdentity().then(function(result) { + if (isSuccess(result)) { + vex.closeAll(); + identity = result.data; + updateIndentity(); + updatePassportList(); + adjustUIState(); + } + }); +} + L.Map.include({ showSignDocument: function() { this.initializeLibrary(); @@ -141,6 +255,57 @@ L.Map.include({ } }, signingLogin: function() { + var w = window.innerWidth / 2; + + var loginWithQR = false; + var recoverFromEmail = false; + var selectedIdentityKey = null; + + $.get('signing-identities.html', function(data) { + vex.open({ + content: data, + showCloseButton: true, + escapeButtonCloses: true, + overlayClosesOnClick: true, + contentCSS: { width: w + 'px' }, + buttons: {}, + afterOpen: function($vexContent) { + library.listIdentities().then(function(response) { + var identities = response.data; + var identitiesDiv = $vexContent.find('#identites'); + for (var key in identities) { + var button = $('<input class="identity-button" type="button"/>'); + button.attr('value', identities[key].initials); + button.css('background-color', identities[key].identityColor); + button.click({ key: key }, function(current) { + selectedIdentityKey = current.data.key; + vex.close($vexContent.data().vex.id); + }); + identitiesDiv.append(button); + } + }); + $('#login-qr').click(function() { + loginWithQR = true; + vex.close($vexContent.data().vex.id); + }); + $('#recover-from-email').click(function() { + recoverFromEmail = true; + vex.close($vexContent.data().vex.id); + }); + }, + afterClose: function () { + if (loginWithQR) { + verignQrDialog(); + } + else if (recoverFromEmail) { + vereignRecoverFromEmail(); + } + else if (selectedIdentityKey) { + vereignPinCodeDialog(selectedIdentityKey); + } + } + }); + }); }, initializeLibrary: function() { setupViamAPI( @@ -148,15 +313,11 @@ L.Map.include({ { onEvent: function(event) { switch (event.type) { + case 'ActionConfirmedAndExecuted': + console.log('ActionConfirmedAndExecuted'); + break; case 'Authenticated': - library.getCurrentlyAuthenticatedIdentity().then(function(result) { - if (isSuccess(result)) { - identity = result.data; - updateIndentity(); - updatePassportList(); - adjustUIState(); - } - }); + vereignRestoreIdentity(); break; default: console.log('UNKNOWN EVENT: ' + event.type); @@ -164,7 +325,7 @@ L.Map.include({ } } }, - 'https://integration1.vereign.com/api/js/iframe' + 'https://integration2.vereign.com/api/js/iframe' ).then(function(lib) { library = lib; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
