Browse Source

Fixed backup-restore configuration

pull/1922/head
Ramiro Saenz 7 years ago
parent
commit
bc8dd7b12d
  1. 16
      app/ux/Auth0.js
  2. 26
      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) {
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: '<i class="fa fa-check fa-3x fa-pull-left" aria-hidden="true"></i> 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)();

26
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 ) {

1
env-sample.js

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

Loading…
Cancel
Save