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:
parent
01e5d59bad
commit
ed429a749b
4 changed files with 28 additions and 26 deletions
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue