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';
|
2017-03-16 11:46:09 +00:00
|
|
|
import constants from '../../../utils/constants';
|
2016-07-07 18:54:16 -07:00
|
|
|
|
|
|
|
export default Ember.Route.extend({
|
2017-03-16 11:46:09 +00:00
|
|
|
appMeta: Ember.inject.service(),
|
|
|
|
kcAuth: Ember.inject.service(),
|
2017-03-17 19:01:32 +00:00
|
|
|
localStorage: Ember.inject.service(),
|
2017-03-17 11:02:04 +00:00
|
|
|
showLogin: false,
|
2017-03-16 11:46:09 +00:00
|
|
|
|
|
|
|
beforeModel(/*transition*/) {
|
|
|
|
let authProvider = this.get('appMeta.authProvider');
|
|
|
|
|
|
|
|
switch (authProvider) {
|
|
|
|
case constants.AuthProvider.Keycloak:
|
2017-03-17 11:02:04 +00:00
|
|
|
this.set('showLogin', false);
|
|
|
|
|
2017-03-20 13:54:53 +00:00
|
|
|
this.get('kcAuth').boot().then(() => {
|
2017-03-16 11:46:09 +00:00
|
|
|
this.get('kcAuth').login().then(() => {
|
|
|
|
}, (reject) => {
|
2017-03-17 19:01:32 +00:00
|
|
|
this.get('localStorage').storeSessionItem('kc-error', reject);
|
|
|
|
this.transitionTo('auth.keycloak', { queryParams: { mode: 'reject' }});
|
2017-03-16 11:46:09 +00:00
|
|
|
});
|
|
|
|
}, (reject) => {
|
2017-03-17 19:01:32 +00:00
|
|
|
this.get('localStorage').storeSessionItem('kc-error', reject);
|
|
|
|
this.transitionTo('auth.keycloak', { queryParams: { mode: 'reject' }});
|
2017-03-16 11:46:09 +00:00
|
|
|
});
|
|
|
|
|
2017-03-17 11:02:04 +00:00
|
|
|
break;
|
2017-03-17 19:01:32 +00:00
|
|
|
|
2017-03-17 11:02:04 +00:00
|
|
|
default:
|
|
|
|
this.set('showLogin', true);
|
2017-03-16 11:46:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-17 11:02:04 +00:00
|
|
|
model() {
|
|
|
|
return {
|
|
|
|
showLogin: this.get('showLogin')
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-07-07 18:54:16 -07:00
|
|
|
setupController: function (controller, model) {
|
|
|
|
controller.set('model', model);
|
|
|
|
controller.reset();
|
|
|
|
this.browser.setTitleAsPhrase("Login");
|
2017-03-16 11:46:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
activate() {
|
|
|
|
$('body').addClass('background-color-off-white');
|
|
|
|
},
|
|
|
|
|
|
|
|
deactivate() {
|
|
|
|
$('body').removeClass('background-color-off-white');
|
2016-07-07 18:54:16 -07:00
|
|
|
}
|
|
|
|
});
|