2015-05-06 18:06:14 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for MainUI (SOGoRootPage) */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2015-08-07 17:04:04 +02:00
|
|
|
angular.module('SOGo.MainUI', ['SOGo.Common', 'SOGo.Authentication']);
|
2015-05-06 18:06:14 +02:00
|
|
|
|
2015-08-07 17:04:04 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-12-14 22:33:21 +01:00
|
|
|
LoginController.$inject = ['$scope', '$window', '$timeout', 'Dialog', '$mdDialog', 'Authentication'];
|
|
|
|
function LoginController($scope, $window, $timeout, Dialog, $mdDialog, Authentication) {
|
2015-08-07 17:04:04 +02:00
|
|
|
var vm = this;
|
|
|
|
|
2017-05-19 04:28:05 +02:00
|
|
|
this.$onInit = function() {
|
|
|
|
this.creds = {
|
|
|
|
username: $window.cookieUsername,
|
|
|
|
password: null,
|
|
|
|
rememberLogin: angular.isDefined($window.cookieUsername) && $window.cookieUsername.length > 0
|
|
|
|
};
|
2017-08-30 20:18:23 +02:00
|
|
|
// Send selected language only if user has changed it
|
|
|
|
if (/\blanguage=/.test($window.location.search))
|
|
|
|
this.creds.language = $window.language;
|
2017-05-19 04:28:05 +02:00
|
|
|
this.loginState = false;
|
2015-08-07 17:04:04 +02:00
|
|
|
|
2017-05-19 04:28:05 +02:00
|
|
|
// Show login once everything is initialized
|
|
|
|
this.showLogin = false;
|
|
|
|
$timeout(function() { vm.showLogin = true; }, 100);
|
|
|
|
};
|
2015-09-15 17:42:47 +02:00
|
|
|
|
2017-05-19 04:28:05 +02:00
|
|
|
this.login = function() {
|
2016-07-15 20:03:16 +02:00
|
|
|
vm.loginState = 'authenticating';
|
2015-08-07 17:04:04 +02:00
|
|
|
Authentication.login(vm.creds)
|
2016-08-31 20:32:30 +02:00
|
|
|
.then(function(data) {
|
2016-07-15 20:03:16 +02:00
|
|
|
vm.loginState = 'logged';
|
2016-08-31 20:32:30 +02:00
|
|
|
vm.cn = data.cn;
|
2016-07-15 20:03:16 +02:00
|
|
|
|
|
|
|
// Let the user see the succesfull message before reloading the page
|
|
|
|
$timeout(function() {
|
2016-12-14 22:33:21 +01:00
|
|
|
if ($window.location.href === data.url)
|
|
|
|
$window.location.reload(true);
|
2016-07-15 20:03:16 +02:00
|
|
|
else
|
2016-12-14 22:33:21 +01:00
|
|
|
$window.location.href = data.url;
|
2016-07-15 20:03:16 +02:00
|
|
|
}, 1000);
|
2015-05-06 18:06:14 +02:00
|
|
|
}, function(msg) {
|
2016-07-15 20:03:16 +02:00
|
|
|
vm.loginState = 'error';
|
|
|
|
vm.errorMessage = msg.error;
|
2015-05-06 18:06:14 +02:00
|
|
|
});
|
|
|
|
return false;
|
2017-05-19 04:28:05 +02:00
|
|
|
};
|
2015-08-07 17:04:04 +02:00
|
|
|
|
2017-05-19 04:28:05 +02:00
|
|
|
this.showAbout = function($event) {
|
2015-05-20 20:46:12 +02:00
|
|
|
$mdDialog.show({
|
|
|
|
targetEvent: $event,
|
|
|
|
templateUrl: 'aboutBox.html',
|
2015-08-07 17:04:04 +02:00
|
|
|
controller: AboutDialogController,
|
|
|
|
controllerAs: 'about'
|
2015-05-06 18:06:14 +02:00
|
|
|
});
|
2015-08-07 17:04:04 +02:00
|
|
|
AboutDialogController.$inject = ['$mdDialog'];
|
|
|
|
function AboutDialogController($mdDialog) {
|
|
|
|
this.closeDialog = function() {
|
2015-05-20 20:46:12 +02:00
|
|
|
$mdDialog.hide();
|
|
|
|
};
|
|
|
|
}
|
2017-05-19 04:28:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this.changeLanguage = function($event) {
|
|
|
|
// Reload page
|
|
|
|
$window.location.href = ApplicationBaseURL + 'login?language=' + this.creds.language;
|
|
|
|
};
|
2015-05-06 18:06:14 +02:00
|
|
|
}
|
2015-08-07 17:04:04 +02:00
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.MainUI')
|
|
|
|
.controller('LoginController', LoginController);
|
2015-05-06 18:06:14 +02:00
|
|
|
})();
|