diff --git a/app/app/app.js b/app/app/app.js index 39e6de86..24f3e5cc 100644 --- a/app/app/app.js +++ b/app/app/app.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -18,10 +18,10 @@ let App; Ember.MODEL_FACTORY_INJECTIONS = true; -Ember.RSVP.on('error', function(error) { - console.log("App:"); - console.log(error); -}); +// Ember.RSVP.on('error', function(error) { +// console.log("App:"); +// console.log(error); +// }); App = Ember.Application.extend({ modulePrefix: config.modulePrefix, @@ -31,4 +31,4 @@ App = Ember.Application.extend({ loadInitializers(App, config.modulePrefix); -export default App; \ No newline at end of file +export default App; diff --git a/app/app/routes/application.js b/app/app/routes/application.js index da384933..af1ef9b8 100644 --- a/app/app/routes/application.js +++ b/app/app/routes/application.js @@ -1,15 +1,16 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com import Ember from 'ember'; +import netUtil from '../utils/net'; export default Ember.Route.extend({ userService: Ember.inject.service('user'), @@ -43,9 +44,10 @@ export default Ember.Route.extend({ error(error, transition) { // jshint ignore: line if (error) { - if (error.status === 401 || error.status === 403) { - return this.transitionTo('auth.login'); - } + if (netUtil.isAjaxAccessError(error)) { + localStorage.clear(); + return this.transitionTo('auth.login'); + } } // Return true to bubble this event to any parent route. diff --git a/app/app/services/session.js b/app/app/services/session.js index 1de1fa04..53599916 100644 --- a/app/app/services/session.js +++ b/app/app/services/session.js @@ -164,15 +164,6 @@ export default Ember.Service.extend({ }); } - // var blockedPopupTest = window.open("http://maintenance.documize.com", "directories=no,height=1,width=1,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no"); - // - // if (!blockedPopupTest) { - // this.set('popupBlocked', true); - // } else { - // blockedPopupTest.close(); - // this.set('popupBlocked', false); - // } - let url = this.get('appMeta').getUrl("public/meta"); return this.get('ajax').request(url) @@ -196,7 +187,7 @@ export default Ember.Service.extend({ this.setSession(token, models.UserModel.create(user)); this.set('ready', true); }).catch((reason) => { - if (reason.status === 401 || reason.status === 403) { + if (netUtil.isAjaxAccessError(reason)) { localStorage.clear(); window.location.href = "/auth/login"; } diff --git a/app/app/utils/net.js b/app/app/utils/net.js index cc75ee1f..0bce88e1 100644 --- a/app/app/utils/net.js +++ b/app/app/utils/net.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -39,7 +39,16 @@ function getAppUrl(domain) { return window.location.protocol + "//" + domain + leftOvers; } +function isAjaxAccessError(reason) { + if (reason.errors.length > 0 && (reason.errors[0].status === "401" || reason.errors[0].status === "403")) { + return true; + } + + return false; +} + export default { getSubdomain, - getAppUrl -}; \ No newline at end of file + getAppUrl, + isAjaxAccessError, +};