2017-03-16 11:46:09 +00: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 { Promise as EmberPromise } from 'rsvp';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Route from '@ember/routing/route';
|
2017-03-16 11:46:09 +00:00
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
export default Route.extend({
|
|
|
|
session: service(),
|
|
|
|
appMeta: service(),
|
|
|
|
kcAuth: service(),
|
|
|
|
localStorage: service(),
|
2017-03-16 11:46:09 +00:00
|
|
|
queryParams: {
|
|
|
|
mode: {
|
2017-03-20 17:56:15 +00:00
|
|
|
refreshModel: true
|
2017-03-16 11:46:09 +00:00
|
|
|
}
|
|
|
|
},
|
2017-03-20 17:56:15 +00:00
|
|
|
message: '',
|
2017-03-16 11:46:09 +00:00
|
|
|
|
|
|
|
beforeModel(transition) {
|
2017-11-16 13:28:05 +00:00
|
|
|
return new EmberPromise((resolve) => {
|
2018-04-20 14:38:10 +01:00
|
|
|
let constants = this.get('constants');
|
|
|
|
|
2017-03-20 17:56:15 +00:00
|
|
|
this.set('mode', is.not.undefined(transition.queryParams.mode) ? transition.queryParams.mode : 'reject');
|
2017-03-17 19:01:32 +00:00
|
|
|
|
2017-03-20 17:56:15 +00:00
|
|
|
if (this.get('mode') === 'reject' || this.get('appMeta.authProvider') !== constants.AuthProvider.Keycloak) {
|
|
|
|
resolve();
|
2017-03-16 11:46:09 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 10:25:32 +01:00
|
|
|
this.get('kcAuth').fetchProfile().then((profile) => {
|
|
|
|
let data = this.get('kcAuth').mapProfile(profile);
|
2017-03-20 17:56:15 +00:00
|
|
|
|
2017-03-28 10:25:32 +01:00
|
|
|
this.get("session").authenticate('authenticator:keycloak', data).then(() => {
|
|
|
|
this.transitionTo('folders');
|
2017-03-17 08:46:33 +00:00
|
|
|
}, (reject) => {
|
2018-08-20 17:17:25 +01:00
|
|
|
if (is.not.undefined(reject.Error)) {
|
|
|
|
this.set('message', reject.Error);
|
|
|
|
} else {
|
|
|
|
this.set('message', reject);
|
|
|
|
}
|
2017-03-20 13:54:53 +00:00
|
|
|
this.set('mode', 'reject');
|
2017-03-20 17:56:15 +00:00
|
|
|
resolve();
|
2017-03-17 08:46:33 +00:00
|
|
|
});
|
2017-03-28 10:25:32 +01:00
|
|
|
|
|
|
|
}, (reject) => {
|
|
|
|
this.set('mode', 'reject');
|
|
|
|
this.set('message', reject);
|
|
|
|
resolve();
|
|
|
|
});
|
2017-03-16 11:46:09 +00:00
|
|
|
});
|
|
|
|
},
|
2017-03-17 19:01:32 +00:00
|
|
|
|
|
|
|
model() {
|
|
|
|
return {
|
2017-03-20 17:56:15 +00:00
|
|
|
mode: this.get('mode'),
|
|
|
|
message: this.get('message')
|
2017-03-17 19:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-16 11:46:09 +00:00
|
|
|
});
|