1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-09 07:25:23 +02:00

improved 401/403 detection (token validation)

This commit is contained in:
Harvey Kandola 2016-06-24 10:51:40 -07:00
parent 01e5d59bad
commit ed429a749b
4 changed files with 28 additions and 26 deletions

View file

@ -18,10 +18,10 @@ let App;
Ember.MODEL_FACTORY_INJECTIONS = true; Ember.MODEL_FACTORY_INJECTIONS = true;
Ember.RSVP.on('error', function(error) { // Ember.RSVP.on('error', function(error) {
console.log("App:"); // console.log("App:");
console.log(error); // console.log(error);
}); // });
App = Ember.Application.extend({ App = Ember.Application.extend({
modulePrefix: config.modulePrefix, modulePrefix: config.modulePrefix,

View file

@ -10,6 +10,7 @@
// https://documize.com // https://documize.com
import Ember from 'ember'; import Ember from 'ember';
import netUtil from '../utils/net';
export default Ember.Route.extend({ export default Ember.Route.extend({
userService: Ember.inject.service('user'), userService: Ember.inject.service('user'),
@ -43,7 +44,8 @@ export default Ember.Route.extend({
error(error, transition) { // jshint ignore: line error(error, transition) { // jshint ignore: line
if (error) { if (error) {
if (error.status === 401 || error.status === 403) { if (netUtil.isAjaxAccessError(error)) {
localStorage.clear();
return this.transitionTo('auth.login'); return this.transitionTo('auth.login');
} }
} }

View file

@ -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"); let url = this.get('appMeta').getUrl("public/meta");
return this.get('ajax').request(url) return this.get('ajax').request(url)
@ -196,7 +187,7 @@ export default Ember.Service.extend({
this.setSession(token, models.UserModel.create(user)); this.setSession(token, models.UserModel.create(user));
this.set('ready', true); this.set('ready', true);
}).catch((reason) => { }).catch((reason) => {
if (reason.status === 401 || reason.status === 403) { if (netUtil.isAjaxAccessError(reason)) {
localStorage.clear(); localStorage.clear();
window.location.href = "/auth/login"; window.location.href = "/auth/login";
} }

View file

@ -39,7 +39,16 @@ function getAppUrl(domain) {
return window.location.protocol + "//" + domain + leftOvers; 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 { export default {
getSubdomain, getSubdomain,
getAppUrl getAppUrl,
isAjaxAccessError,
}; };