From bc8dd7b12d0a2da2e7d6c8967ff0661fafc472d1 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Wed, 17 Oct 2018 15:51:36 -0300 Subject: [PATCH] Fixed backup-restore configuration --- app/ux/Auth0.js | 16 +++++++++------- app/view/main/MainController.js | 26 ++++++++++++++++---------- env-sample.js | 1 + 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/ux/Auth0.js b/app/ux/Auth0.js index d9790095..7e420e08 100644 --- a/app/ux/Auth0.js +++ b/app/ux/Auth0.js @@ -142,10 +142,10 @@ Ext.define('Rambox.ux.Auth0', { me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) { if ( err ) { - if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration); + if ( err.code === 401 ) return me.renewToken(me.restoreConfiguration); return Ext.Msg.show({ title: 'Error' - ,message: 'There was an error getting the profile: ' + err.error_description + ,message: 'There was an error getting the profile: ' + err.description ,icon: Ext.Msg.ERROR ,buttons: Ext.Msg.OK }); @@ -173,10 +173,10 @@ Ext.define('Rambox.ux.Auth0', { me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) { if ( err ) { - if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration); + if ( err.code === 401 ) return me.renewToken(me.checkConfiguration); return Ext.Msg.show({ title: 'Error' - ,message: 'There was an error getting the profile: ' + err.error_description + ,message: 'There was an error getting the profile: ' + err.description ,icon: Ext.Msg.ERROR ,buttons: Ext.Msg.OK }); @@ -206,7 +206,7 @@ Ext.define('Rambox.ux.Auth0', { }); } else { Ext.toast({ - html: 'Latest backup is already applied.' + html: ' Latest backup is already applied.' ,title: 'Synchronize Configuration' ,width: 300 ,align: 't' @@ -220,16 +220,18 @@ Ext.define('Rambox.ux.Auth0', { var me = this; Ext.Ajax.request({ - url: 'https://rambox.auth0.com/delegation' + url: 'https://rambox.auth0.com/oauth/token' ,method: 'POST' ,jsonData: { - grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer' + grant_type: 'refresh_token' ,client_id: auth0Cfg.clientID + ,client_secret: auth0Cfg.clientSecret ,refresh_token: localStorage.getItem('refresh_token') ,api_type: 'app' } ,success: function(response) { var json = Ext.decode(response.responseText); + localStorage.setItem('access_token', json.access_token); localStorage.setItem('id_token', json.id_token); if ( Ext.isFunction(callback) ) callback.bind(me)(); diff --git a/app/view/main/MainController.js b/app/view/main/MainController.js index 75824b51..51b56070 100644 --- a/app/view/main/MainController.js +++ b/app/view/main/MainController.js @@ -125,7 +125,7 @@ Ext.define('Rambox.view.main.MainController', { }); } - ,removeServiceFn: function(serviceId, total, actual) { + ,removeServiceFn: function(serviceId, total, actual, callback) { var me = this; if ( !serviceId ) return false; @@ -167,7 +167,10 @@ Ext.define('Rambox.view.main.MainController', { // Close tab tab.close(); // Close waiting message - if ( total === actual ) Ext.Msg.hide(); + if ( total === actual ) { + Ext.Msg.hide(); + if ( Ext.isFunction(callback) ) callback(); + } }); }); }); @@ -200,11 +203,10 @@ Ext.define('Rambox.view.main.MainController', { const count = Ext.getStore('Services').getCount(); var i = 1; Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { - me.removeServiceFn(serviceId, count, i++); + me.removeServiceFn(serviceId, count, i++, callback || false); }); - if ( Ext.isFunction(callback) ) callback(); + if ( count === 0 && Ext.isFunction(callback) ) callback(); Ext.cq1('app-main').resumeEvent('remove'); - document.title = 'Rambox'; } }); } else { @@ -213,11 +215,10 @@ Ext.define('Rambox.view.main.MainController', { const count = Ext.getStore('Services').getCount(); var i = 1; Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { - me.removeServiceFn(serviceId, count, i++); + me.removeServiceFn(serviceId, count, i++, callback || false); }); - if ( Ext.isFunction(callback) ) callback(); + if ( count === 0 && Ext.isFunction(callback) ) callback(); Ext.cq1('app-main').resumeEvent('remove'); - document.title = 'Rambox'; } } @@ -485,8 +486,13 @@ Ext.define('Rambox.view.main.MainController', { Ext.cq1('app-main').getViewModel().set('username', ''); Ext.cq1('app-main').getViewModel().set('avatar', ''); - if ( Ext.isFunction(callback) ) callback(); - Ext.Msg.hide(); + if ( Ext.isFunction(callback) ) { + callback(false, function() { + Ext.Msg.hide(); + }); + } else { + Ext.Msg.hide(); + } } if ( btn ) { diff --git a/env-sample.js b/env-sample.js index ffeba058..70292222 100644 --- a/env-sample.js +++ b/env-sample.js @@ -1,4 +1,5 @@ var auth0Cfg = { clientID: '' + ,clientSecret: '' ,domain: '' };