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
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
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
|
|
|
|
2018-12-06 14:10:00 +00: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
|
|
|
|
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');
|
|
|
|
|
2019-05-14 14:52:36 +01:00
|
|
|
return this.get('appMeta').boot(transition.targetName, '').then(data => {
|
2019-08-13 22:10:08 +08:00
|
|
|
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
|
|
|
|
2019-03-03 13:10:04 +00:00
|
|
|
if (!_.isNull(next) && !_.isUndefined(next)) {
|
2017-05-03 11:37:39 +01:00
|
|
|
this.get('localStorage').clearSessionItem('entryUrl')
|
|
|
|
|
2019-03-03 13:10:04 +00:00
|
|
|
if (!_.includes(next, '/auth/')) {
|
2019-05-14 14:52:36 +01:00
|
|
|
// 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();
|
|
|
|
},
|
|
|
|
|
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')) {
|
2017-08-30 13:00:07 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2016-07-24 14:49:40 -07:00
|
|
|
});
|