1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 21:29:42 +02:00
documize/gui/app/routes/application.js

80 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// 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 <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
import netUtil from '../utils/net';
import TooltipMixin from '../mixins/tooltip';
2016-07-07 18:54:16 -07:00
const {
inject: { service }
} = Ember;
export default Ember.Route.extend(ApplicationRouteMixin, TooltipMixin, {
2016-07-07 18:54:16 -07:00
appMeta: service(),
session: service(),
2016-11-21 19:27:18 -08:00
pinned: service(),
2017-05-03 11:37:39 +01:00
localStorage: service(),
2016-07-07 18:54:16 -07:00
beforeModel(transition) {
2017-03-22 11:34:49 +00:00
this._super(...arguments);
2017-05-03 11:37:39 +01:00
let sa = this.get('session.session.authenticator');
return this.get('appMeta').boot(transition.targetName, window.location.href).then(data => {
if (sa !== "authenticator:documize" && sa !== "authenticator:keycloak" && data.allowAnonymousAccess) {
2017-07-18 11:13:20 +01:00
if (!this.get('appMeta.setupMode')) {
return this.get('session').authenticate('authenticator:anonymous', data);
}
2016-07-07 18:54:16 -07:00
}
return;
});
},
2017-05-03 11:37:39 +01:00
sessionAuthenticated() {
2017-07-18 11:13:20 +01:00
if (this.get('appMeta.setupMode')) {
return;
}
2017-05-03 11:37:39 +01:00
let next = this.get('localStorage').getSessionItem('entryUrl');
2017-07-18 11:13:20 +01:00
2017-05-03 11:37:39 +01:00
if (is.not.null(next) && is.not.undefined(next)) {
this.get('localStorage').clearSessionItem('entryUrl')
if (is.not.include(next, '/auth/')) {
window.location.href= next;
}
2017-05-03 11:37:39 +01:00
}
},
2016-07-07 18:54:16 -07:00
actions: {
2016-10-07 10:58:49 -07:00
willTransition: function( /*transition*/ ) {
2016-07-07 18:54:16 -07:00
Mousetrap.reset();
this.destroyTooltips();
2016-07-07 18:54:16 -07:00
},
error(error, transition) {
2016-07-07 18:54:16 -07:00
if (error) {
console.log(error); // eslint-disable-line no-console
console.log(transition); // eslint-disable-line no-console
2016-11-06 20:11:21 -08:00
2017-07-18 11:13:20 +01:00
if (netUtil.isAjaxAccessError(error) && !this.get('appMeta.setupMode')) {
2016-07-07 18:54:16 -07:00
localStorage.clear();
return this.transitionTo('auth.login');
}
}
2017-03-22 11:34:49 +00:00
return true; // bubble this event to any parent route
2016-07-07 18:54:16 -07:00
}
}
});