1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-08 23:15:29 +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.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,

View file

@ -10,6 +10,7 @@
// 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.

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");
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";
}

View file

@ -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
getAppUrl,
isAjaxAccessError,
};