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,
|
2021-05-05 18:41:08 +02:00
|
|
|
domain: null,
|
2017-05-19 04:28:05 +02:00
|
|
|
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;
|
2020-05-07 22:45:37 +02:00
|
|
|
|
2021-06-16 20:59:02 +02:00
|
|
|
// Code pattern for TOTP verification code
|
2020-05-07 22:45:37 +02:00
|
|
|
this.verificationCodePattern = '\\d{6}';
|
2015-08-07 17:04:04 +02:00
|
|
|
|
2021-05-05 18:41:08 +02:00
|
|
|
// Password policy - change expired password
|
|
|
|
this.passwords = { newPassword: null, newPasswordConfirmation: null, oldPassword: null };
|
|
|
|
|
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
|
|
|
|
2021-06-16 20:59:02 +02:00
|
|
|
if (data.totpmissingkey) {
|
|
|
|
vm.loginState = 'totpcode';
|
2020-05-07 13:22:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
vm.loginState = 'logged';
|
|
|
|
vm.cn = data.cn;
|
2021-05-05 18:41:08 +02:00
|
|
|
vm.url = data.url;
|
2020-05-07 13:22:24 +02:00
|
|
|
|
|
|
|
// Let the user see the succesfull message before reloading the page
|
|
|
|
$timeout(function() {
|
2021-05-05 18:41:08 +02:00
|
|
|
vm.continueLogin();
|
2020-05-07 13:22:24 +02:00
|
|
|
}, 1000);
|
|
|
|
}
|
2015-05-06 18:06:14 +02:00
|
|
|
}, function(msg) {
|
2016-07-15 20:03:16 +02:00
|
|
|
vm.loginState = 'error';
|
2021-05-05 18:41:08 +02:00
|
|
|
|
|
|
|
if (msg.error) {
|
|
|
|
vm.errorMessage = msg.error;
|
|
|
|
}
|
|
|
|
else if (msg.grace > 0) {
|
|
|
|
// Password is expired, grace logins limit is not yet reached
|
|
|
|
vm.loginState = 'passwordwillexpire';
|
|
|
|
vm.cn = msg.cn;
|
|
|
|
vm.url = msg.url;
|
|
|
|
vm.errorMessage = l('You have %{0} logins remaining before your account is locked. Please change your password in the preference dialog.', msg.grace);
|
|
|
|
}
|
|
|
|
else if (msg.expire > 0) {
|
|
|
|
// Password will soon expire
|
|
|
|
var value, string;
|
|
|
|
if (msg.expire > 86400) {
|
|
|
|
value = Math.round(msg.expire/86400);
|
|
|
|
string = l("days");
|
|
|
|
}
|
|
|
|
else if (msg.expire > 3600) {
|
|
|
|
value = Math.round(msg.expire/3600);
|
|
|
|
string = l("hours");
|
|
|
|
}
|
|
|
|
else if (msg.expire > 60) {
|
|
|
|
value = Math.round(msg.expire/60);
|
|
|
|
string = l("minutes");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
value = msg.expire;
|
|
|
|
string = l("seconds");
|
|
|
|
}
|
|
|
|
vm.loginState = 'passwordwillexpire';
|
|
|
|
vm.cn = msg.cn;
|
|
|
|
vm.url = msg.url;
|
|
|
|
vm.errorMessage = l('Your password is going to expire in %{0} %{1}.', value, string);
|
|
|
|
}
|
|
|
|
else if (msg.passwordexpired) {
|
|
|
|
vm.loginState = 'passwordexpired';
|
|
|
|
vm.url = msg.url;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-05-07 22:45:37 +02:00
|
|
|
this.restoreLogin = function() {
|
|
|
|
vm.loginState = false;
|
|
|
|
delete vm.creds.verificationCode;
|
|
|
|
};
|
|
|
|
|
2021-05-05 18:41:08 +02:00
|
|
|
this.continueLogin = function() {
|
|
|
|
if ($window.location.href === vm.url)
|
|
|
|
$window.location.reload(true);
|
|
|
|
else
|
|
|
|
$window.location.href = vm.url;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
2021-05-05 18:41:08 +02:00
|
|
|
|
|
|
|
this.canChangePassword = function(form) {
|
|
|
|
if (this.passwords.newPasswordConfirmation && this.passwords.newPasswordConfirmation.length &&
|
|
|
|
this.passwords.newPassword != this.passwords.newPasswordConfirmation) {
|
|
|
|
form.newPasswordConfirmation.$setValidity('newPasswordMismatch', false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
form.newPasswordConfirmation.$setValidity('newPasswordMismatch', true);
|
|
|
|
}
|
|
|
|
if (this.passwords.newPassword && this.passwords.newPassword.length > 0 &&
|
|
|
|
this.passwords.newPasswordConfirmation && this.passwords.newPasswordConfirmation.length &&
|
|
|
|
this.passwords.newPassword == this.passwords.newPasswordConfirmation &&
|
|
|
|
this.passwords.oldPassword && this.passwords.oldPassword.length > 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.changePassword = function() {
|
|
|
|
Authentication.changePassword(this.creds.username, this.creds.domain, this.passwords.newPassword, this.passwords.oldPassword).then(function(data) {
|
|
|
|
vm.loginState = 'message';
|
|
|
|
vm.url = data.url;
|
|
|
|
vm.errorMessage = l('The password was changed successfully.');
|
|
|
|
}, function(msg) {
|
|
|
|
vm.loginState = 'error';
|
|
|
|
vm.errorMessage = msg;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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
|
|
|
})();
|