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

75 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-08-19 13:02:56 -04:00
/* eslint-disable ember/no-classic-classes */
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 { inject as service } from '@ember/service';
2016-07-07 18:54:16 -07:00
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
import netUtil from '../utils/net';
2018-09-04 17:19:26 +01:00
import Route from '@ember/routing/route';
2016-07-07 18:54:16 -07:00
export default Route.extend(ApplicationRouteMixin, {
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, '').then(data => {
if (sa !== "authenticator:documize" && sa !== "authenticator:keycloak" && sa !== "authenticator:ldap" && sa != "authenticator:cas" && data.allowAnonymousAccess) {
2017-08-29 17:55:41 +01:00
if (!this.get('appMeta.setupMode') && !this.get('appMeta.secureMode')) {
2017-07-18 11:13:20 +01:00
return this.get('session').authenticate('authenticator:anonymous', data);
}
2016-07-07 18:54:16 -07:00
}
});
},
2017-05-03 11:37:39 +01:00
sessionAuthenticated() {
2017-08-29 17:55:41 +01:00
if (this.get('appMeta.setupMode') || this.get('appMeta.secureMode')) {
2017-08-27 16:39:09 +01:00
this.get('localStorage').clearAll();
2017-07-18 11:13:20 +01:00
return;
}
2017-05-03 11:37:39 +01:00
let next = this.get('localStorage').getSessionItem('entryUrl');
2017-07-18 11:13:20 +01:00
if (!_.isNull(next) && !_.isUndefined(next)) {
2017-05-03 11:37:39 +01:00
this.get('localStorage').clearSessionItem('entryUrl')
if (!_.includes(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();
},
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')) {
this.get('localStorage').clearAll();
2016-07-07 18:54:16 -07:00
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
}
}
});