Improve JavaScript of SOGoRootPage module
This commit is contained in:
parent
2d6f8e4ea6
commit
e817a3b3d0
|
@ -7,10 +7,10 @@
|
||||||
xmlns:const="http://www.skyrix.com/od/constant"
|
xmlns:const="http://www.skyrix.com/od/constant"
|
||||||
xmlns:rsrc="OGo:url"
|
xmlns:rsrc="OGo:url"
|
||||||
xmlns:label="OGo:label"
|
xmlns:label="OGo:label"
|
||||||
const:jsFiles="SOGo/SOGoAuthentication.js"
|
const:jsFiles="Common/SOGoAuthentication.js"
|
||||||
const:popup="YES"
|
const:popup="YES"
|
||||||
><var:string var:value="doctype" const:escapeHTML="NO"/>
|
><var:string var:value="doctype" const:escapeHTML="NO"/>
|
||||||
<div data-ng-app="SOGoRootPage">
|
<div data-ng-app="SOGo.RootPage">
|
||||||
<div id="aboutBox" style="display:none;">
|
<div id="aboutBox" style="display:none;">
|
||||||
<div>
|
<div>
|
||||||
<p class="logo"><img const:alt="SOGo" rsrc:src="sogo-logo.png"/></p>
|
<p class="logo"><img const:alt="SOGo" rsrc:src="sogo-logo.png"/></p>
|
||||||
|
@ -34,17 +34,18 @@
|
||||||
<div id="logo">
|
<div id="logo">
|
||||||
<img const:alt="*" id="splash" rsrc:src="img/sogo-logo.png"/>
|
<img const:alt="*" id="splash" rsrc:src="img/sogo-logo.png"/>
|
||||||
</div>
|
</div>
|
||||||
<form name="loginForm" data-ng-controller="loginController" data-ng-submit="login($event)">
|
<form name="loginForm" data-ng-controller="loginController" data-ng-submit="login(creds)">
|
||||||
<var:if condition="hasLoginSuffix"><input type="hidden" data-ng-model="loginSuffix" var:value="loginSuffix"/></var:if>
|
<var:if condition="hasLoginSuffix"><input type="hidden" data-ng-model="creds.loginSuffix" var:value="loginSuffix"/></var:if>
|
||||||
<div data-ng-show="warning" data-ng-cloak="ng-cloak" data-alert="data-alert" class="alert-box radius warning">{{warning}}</div>
|
<div data-ng-show="warning" data-ng-cloak="ng-cloak" data-alert="data-alert" class="alert-box radius warning">{{warning}}</div>
|
||||||
<label><var:string label:value="Username:"/>
|
<label><var:string label:value="Username:"/>
|
||||||
<input type="text" data-ng-model="username" var:data-ng-init="cookieUsername" required="required" />
|
<input type="text" data-ng-model="creds.username" var:data-ng-init="cookieUsername" required="required" />
|
||||||
</label>
|
</label>
|
||||||
<label><var:string label:value="Password:"/>
|
<label><var:string label:value="Password:"/>
|
||||||
<input type="password" data-ng-model="password" required="required" />
|
<input type="password" data-ng-model="creds.password" required="required" />
|
||||||
</label>
|
</label>
|
||||||
<label><var:string label:value="Language:"/>
|
<label><var:string label:value="Language:"/>
|
||||||
<var:popup const:name="language"
|
<var:popup const:name="language"
|
||||||
|
const:data-ng-model="creds.language"
|
||||||
list="languages"
|
list="languages"
|
||||||
item="item"
|
item="item"
|
||||||
var:value="item"
|
var:value="item"
|
||||||
|
@ -55,6 +56,7 @@
|
||||||
<var:if condition="hasLoginDomains">
|
<var:if condition="hasLoginDomains">
|
||||||
<label><var:string label:value="Domain:"/><br/>
|
<label><var:string label:value="Domain:"/><br/>
|
||||||
<var:popup const:name="domain"
|
<var:popup const:name="domain"
|
||||||
|
const:data-ng-model="creds.domain"
|
||||||
list="loginDomains"
|
list="loginDomains"
|
||||||
item="item"
|
item="item"
|
||||||
var:selection="item"
|
var:selection="item"
|
||||||
|
@ -63,7 +65,7 @@
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</var:if>
|
</var:if>
|
||||||
<label><input id="rememberLogin" type="checkbox" class="checkBox" var:checked="rememberLogin"/> <var:string label:value="Remember username"/></label>
|
<label><input id="rememberLogin" type="checkbox" class="checkBox" var:checked="rememberLogin" data-ng-model="creds.rememberLogin"/> <var:string label:value="Remember username"/></label>
|
||||||
<label>
|
<label>
|
||||||
<button type="submit" class="small" data-ng-disabled='!loginForm.$valid'>
|
<button type="submit" class="small" data-ng-disabled='!loginForm.$valid'>
|
||||||
<var:string label:value="Connect" /></button>
|
<var:string label:value="Connect" /></button>
|
||||||
|
|
165
UI/WebServerResources/js/Common/SOGoAuthentication.js
Normal file
165
UI/WebServerResources/js/Common/SOGoAuthentication.js
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/* JavaScript for SOGoContacts */
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('SOGo.Authentication', [])
|
||||||
|
|
||||||
|
.constant('passwordPolicyConfig', {
|
||||||
|
'PolicyPasswordChangeUnsupported': -3,
|
||||||
|
'PolicyPasswordSystemUnknown': -2,
|
||||||
|
'PolicyPasswordUnknown': -1,
|
||||||
|
'PolicyPasswordExpired': 0,
|
||||||
|
'PolicyAccountLocked': 1,
|
||||||
|
'PolicyChangeAfterReset': 2,
|
||||||
|
'PolicyPasswordModNotAllowed': 3,
|
||||||
|
'PolicyMustSupplyOldPassword': 4,
|
||||||
|
'PolicyInsufficientPasswordQuality': 5,
|
||||||
|
'PolicyPasswordTooShort': 6,
|
||||||
|
'PolicyPasswordTooYoung': 7,
|
||||||
|
'PolicyPasswordInHistory': 8,
|
||||||
|
'PolicyNoError': 65535
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO: convert to a Factory recipe?
|
||||||
|
.provider('Authentication', function(passwordPolicyConfig) {
|
||||||
|
this.readCookie = function(name) {
|
||||||
|
var foundCookie = null;
|
||||||
|
|
||||||
|
var prefix = name + "=";
|
||||||
|
var pairs = document.cookie.split(';');
|
||||||
|
for (var i = 0; !foundCookie && i < pairs.length; i++) {
|
||||||
|
var currentPair = pairs[i];
|
||||||
|
var start = 0;
|
||||||
|
while (currentPair.charAt(start) == " ")
|
||||||
|
start++;
|
||||||
|
if (start > 0)
|
||||||
|
currentPair = currentPair.substr(start);
|
||||||
|
if (currentPair.indexOf(prefix) == 0)
|
||||||
|
foundCookie = currentPair.substr(prefix.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundCookie;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.readLoginCookie = function() {
|
||||||
|
var loginValues = null;
|
||||||
|
var cookie = this.readCookie("0xHIGHFLYxSOGo");
|
||||||
|
if (cookie && cookie.length > 8) {
|
||||||
|
var value = decodeURIComponent(cookie.substr(8));
|
||||||
|
loginValues = value.base64decode().split(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
return loginValues;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.redirectUrl = function(username, domain) {
|
||||||
|
var userName = username;
|
||||||
|
if (domain)
|
||||||
|
userName += '@' + domain.value;
|
||||||
|
var address = "" + window.location.href;
|
||||||
|
var baseAddress = ApplicationBaseURL + "/" + encodeURIComponent(userName);
|
||||||
|
var altBaseAddress;
|
||||||
|
if (baseAddress[0] == "/") {
|
||||||
|
var parts = address.split("/");
|
||||||
|
var hostpart = parts[2];
|
||||||
|
var protocol = parts[0];
|
||||||
|
baseAddress = protocol + "//" + hostpart + baseAddress;
|
||||||
|
}
|
||||||
|
var altBaseAddress;
|
||||||
|
var parts = baseAddress.split("/");
|
||||||
|
parts.splice(0, 3);
|
||||||
|
altBaseAddress = parts.join("/");
|
||||||
|
var newAddress;
|
||||||
|
if ((address.startsWith(baseAddress)
|
||||||
|
|| address.startsWith(altBaseAddress))
|
||||||
|
&& !address.endsWith("/logoff")) {
|
||||||
|
newAddress = address;
|
||||||
|
} else {
|
||||||
|
newAddress = baseAddress;
|
||||||
|
}
|
||||||
|
if (/theme=mobile/.test(window.location.search)) {
|
||||||
|
return baseAddress + '/Contacts' + '?theme=mobile';
|
||||||
|
}
|
||||||
|
return newAddress.replace(/(Calendar|Mail)/, 'Contacts');
|
||||||
|
return newAddress;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$get = ['$q', '$http', function($q, $http) {
|
||||||
|
var self = this;
|
||||||
|
var service = {
|
||||||
|
// login: function(username, password, domain, language, rememberLogin) {
|
||||||
|
// var d = $q.defer();
|
||||||
|
login: function(data) {
|
||||||
|
var d = $q.defer(),
|
||||||
|
username = data.username,
|
||||||
|
password = data.password,
|
||||||
|
domain = data.domain,
|
||||||
|
language,
|
||||||
|
rememberLogin = data.rememberLogin ? 1 : 0;
|
||||||
|
|
||||||
|
if (data.loginSuffix && !username.endsWith(data.loginSuffix)) {
|
||||||
|
username += loginSuffix;
|
||||||
|
domain = false;
|
||||||
|
}
|
||||||
|
if (data.language && data.language != 'WONoSelectionString') {
|
||||||
|
language = data.language;
|
||||||
|
}
|
||||||
|
|
||||||
|
$http({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/SOGo/connect',
|
||||||
|
data: {'userName': username,
|
||||||
|
'password': password,
|
||||||
|
'domain': domain,
|
||||||
|
'language': language,
|
||||||
|
'rememberLogin': rememberLogin}
|
||||||
|
}).success(function(data, status) {
|
||||||
|
// Make sure browser's cookies are enabled
|
||||||
|
var loginCookie = self.readLoginCookie();
|
||||||
|
if (!loginCookie) {
|
||||||
|
d.reject(l("cookiesNotEnabled"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Check password policy
|
||||||
|
if (typeof(data['expire']) != 'undefined' && typeof(data['grace']) != 'undefined') {
|
||||||
|
if (data['expire'] < 0 && data['grace'] > 0) {
|
||||||
|
d.reject({'grace': data['grace']});
|
||||||
|
//showPasswordDialog('grace', createPasswordGraceDialog, data['grace']);
|
||||||
|
} else if (data['expire'] > 0 && data['grace'] == -1) {
|
||||||
|
d.reject({'expire': data['expire']});
|
||||||
|
//showPasswordDialog('expiration', createPasswordExpirationDialog, data['expire']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
d.resolve(self.redirectUrl(username, domain));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
d.resolve(self.redirectUrl(username, domain));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).error(function(data, status) {
|
||||||
|
var msg;
|
||||||
|
if (data && data['LDAPPasswordPolicyError']) {
|
||||||
|
var perr = data['LDAPPasswordPolicyError'];
|
||||||
|
if (perr == passwordPolicyConfig.PolicyNoError) {
|
||||||
|
msg = l("Wrong username or password.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg = l("Login failed due to unhandled error case: " + perr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg = l("Unhandled error response");
|
||||||
|
}
|
||||||
|
d.reject({error: msg});
|
||||||
|
});
|
||||||
|
return d.promise;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return service;
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
|
||||||
|
})();
|
|
@ -1,45 +1,23 @@
|
||||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
/* JavaScript for SOGoContacts */
|
/* JavaScript for SOGoRootPage */
|
||||||
|
|
||||||
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var SOGoRootPageApp = angular.module('SOGoRootPage', ['SOGoAuthentication']);
|
angular.module('SOGo.RootPage', ['SOGo.Authentication'])
|
||||||
|
|
||||||
SOGoRootPageApp.controller('loginController', ['$scope', '$http', 'SOGoAuthentication', function($scope, $http, SOGoAuthentication) {
|
.controller('loginController', ['$scope', 'Authentication', function($scope, Authentication) {
|
||||||
$scope.warning = false;
|
$scope.warning = false;
|
||||||
$scope.login = function($event) {
|
$scope.creds = { 'username': null, 'password': null };
|
||||||
//$event.stopPropagation();
|
$scope.login = function(creds) {
|
||||||
$scope.warning = false;
|
$scope.warning = false;
|
||||||
|
Authentication.login(creds)
|
||||||
var username = $scope.username,
|
|
||||||
password = $scope.password,
|
|
||||||
domain = $scope.domain,
|
|
||||||
language,
|
|
||||||
rememberLogin = $scope.rememberLogin ? 1 : 0;
|
|
||||||
|
|
||||||
if ($scope.loginSuffix && !username.endsWith($scope.loginSuffix)) {
|
|
||||||
username += loginSuffix;
|
|
||||||
domain = false;
|
|
||||||
}
|
|
||||||
if ($scope.language && $scope.language != 'WONoSelectionString') {
|
|
||||||
language = $scope.language;
|
|
||||||
}
|
|
||||||
|
|
||||||
SOGoAuthentication.login(username, password, domain, language, rememberLogin)
|
|
||||||
.then(function(url) {
|
.then(function(url) {
|
||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
}, function(msg) {
|
}, function(msg) {
|
||||||
$scope.warning = msg;
|
$scope.warning = msg.error;
|
||||||
});
|
});
|
||||||
// $http({
|
|
||||||
// method: 'POST',
|
|
||||||
// url: 'http://debian.inverse.ca/SOGo/connect',
|
|
||||||
// params: postData})
|
|
||||||
// .success(function(data, status, headers, config) {
|
|
||||||
// alert('success: ' + status);
|
|
||||||
// }).error(function(data, status, headers, config) {
|
|
||||||
// alert('error: ' + status);
|
|
||||||
// });
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
})();
|
||||||
|
|
Loading…
Reference in a new issue