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';
|
2016-11-07 09:55:35 -08:00
|
|
|
import TooltipMixin from '../mixins/tooltip';
|
2016-07-07 18:54:16 -07:00
|
|
|
|
|
|
|
const {
|
|
|
|
inject: { service }
|
|
|
|
} = Ember;
|
|
|
|
|
2016-11-07 09:55:35 -08:00
|
|
|
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
|
|
|
|
2016-07-24 14:49:40 -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-07-17 10:28:32 +01:00
|
|
|
}
|
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();
|
2016-11-07 09:55:35 -08:00
|
|
|
this.destroyTooltips();
|
2016-07-07 18:54:16 -07:00
|
|
|
},
|
|
|
|
|
2017-01-17 15:30:39 +00:00
|
|
|
error(error, transition) {
|
2016-07-07 18:54:16 -07:00
|
|
|
if (error) {
|
2017-03-19 11:37:18 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2016-07-24 14:49:40 -07:00
|
|
|
});
|