Browse Source

Fixed backup-restore configuration

pull/1922/head
Ramiro Saenz 7 years ago
parent
commit
bc8dd7b12d
  1. 16
      app/ux/Auth0.js
  2. 24
      app/view/main/MainController.js
  3. 1
      env-sample.js

16
app/ux/Auth0.js

@ -142,10 +142,10 @@ Ext.define('Rambox.ux.Auth0', {
me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) { me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) {
if ( err ) { 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({ return Ext.Msg.show({
title: 'Error' 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 ,icon: Ext.Msg.ERROR
,buttons: Ext.Msg.OK ,buttons: Ext.Msg.OK
}); });
@ -173,10 +173,10 @@ Ext.define('Rambox.ux.Auth0', {
me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) { me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) {
if ( err ) { 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({ return Ext.Msg.show({
title: 'Error' 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 ,icon: Ext.Msg.ERROR
,buttons: Ext.Msg.OK ,buttons: Ext.Msg.OK
}); });
@ -206,7 +206,7 @@ Ext.define('Rambox.ux.Auth0', {
}); });
} else { } else {
Ext.toast({ Ext.toast({
html: 'Latest backup is already applied.' html: '<i class="fa fa-check fa-3x fa-pull-left" aria-hidden="true"></i> Latest backup is already applied.'
,title: 'Synchronize Configuration' ,title: 'Synchronize Configuration'
,width: 300 ,width: 300
,align: 't' ,align: 't'
@ -220,16 +220,18 @@ Ext.define('Rambox.ux.Auth0', {
var me = this; var me = this;
Ext.Ajax.request({ Ext.Ajax.request({
url: 'https://rambox.auth0.com/delegation' url: 'https://rambox.auth0.com/oauth/token'
,method: 'POST' ,method: 'POST'
,jsonData: { ,jsonData: {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer' grant_type: 'refresh_token'
,client_id: auth0Cfg.clientID ,client_id: auth0Cfg.clientID
,client_secret: auth0Cfg.clientSecret
,refresh_token: localStorage.getItem('refresh_token') ,refresh_token: localStorage.getItem('refresh_token')
,api_type: 'app' ,api_type: 'app'
} }
,success: function(response) { ,success: function(response) {
var json = Ext.decode(response.responseText); var json = Ext.decode(response.responseText);
localStorage.setItem('access_token', json.access_token);
localStorage.setItem('id_token', json.id_token); localStorage.setItem('id_token', json.id_token);
if ( Ext.isFunction(callback) ) callback.bind(me)(); if ( Ext.isFunction(callback) ) callback.bind(me)();

24
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; var me = this;
if ( !serviceId ) return false; if ( !serviceId ) return false;
@ -167,7 +167,10 @@ Ext.define('Rambox.view.main.MainController', {
// Close tab // Close tab
tab.close(); tab.close();
// Close waiting message // 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(); const count = Ext.getStore('Services').getCount();
var i = 1; var i = 1;
Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { 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'); Ext.cq1('app-main').resumeEvent('remove');
document.title = 'Rambox';
} }
}); });
} else { } else {
@ -213,11 +215,10 @@ Ext.define('Rambox.view.main.MainController', {
const count = Ext.getStore('Services').getCount(); const count = Ext.getStore('Services').getCount();
var i = 1; var i = 1;
Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { 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'); Ext.cq1('app-main').resumeEvent('remove');
document.title = 'Rambox';
} }
} }
@ -485,9 +486,14 @@ Ext.define('Rambox.view.main.MainController', {
Ext.cq1('app-main').getViewModel().set('username', ''); Ext.cq1('app-main').getViewModel().set('username', '');
Ext.cq1('app-main').getViewModel().set('avatar', ''); Ext.cq1('app-main').getViewModel().set('avatar', '');
if ( Ext.isFunction(callback) ) callback(); if ( Ext.isFunction(callback) ) {
callback(false, function() {
Ext.Msg.hide();
});
} else {
Ext.Msg.hide(); Ext.Msg.hide();
} }
}
if ( btn ) { if ( btn ) {
Ext.Msg.confirm(locale['app.main[21]'], locale['app.window[38]'], function(btnId) { Ext.Msg.confirm(locale['app.main[21]'], locale['app.window[38]'], function(btnId) {

1
env-sample.js

@ -1,4 +1,5 @@
var auth0Cfg = { var auth0Cfg = {
clientID: '' clientID: ''
,clientSecret: ''
,domain: '' ,domain: ''
}; };

Loading…
Cancel
Save