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
|
|
|
|
|
|
|
|
import Ember from 'ember';
|
|
|
|
import constants from '../../../utils/constants';
|
|
|
|
|
|
|
|
export default Ember.Route.extend({
|
|
|
|
session: Ember.inject.service(),
|
|
|
|
appMeta: Ember.inject.service(),
|
2017-03-17 19:01:32 +00:00
|
|
|
kcAuth: Ember.inject.service(),
|
|
|
|
localStorage: Ember.inject.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-03-20 17:56:15 +00:00
|
|
|
return new Ember.RSVP.Promise((resolve) => {
|
|
|
|
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) => {
|
2017-03-28 10:25:32 +01:00
|
|
|
this.set('message', reject.Error);
|
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
|
|
|
});
|