mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-15 13:24:54 +00:00
(js) Fix dependency injections
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* JavaScript for SOGoContacts */
|
||||
/* JavaScript for Authentication */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
@@ -23,197 +23,196 @@
|
||||
})
|
||||
|
||||
// TODO: convert to a Factory recipe?
|
||||
.provider('Authentication', function(passwordPolicyConfig) {
|
||||
this.readCookie = function(name) {
|
||||
var foundCookie, prefix, pairs, i, currentPair, start;
|
||||
foundCookie = null;
|
||||
prefix = name + '=';
|
||||
pairs = document.cookie.split(';');
|
||||
for (i = 0; !foundCookie && i < pairs.length; i++) {
|
||||
currentPair = pairs[i];
|
||||
start = 0;
|
||||
while (currentPair.charAt(start) == ' ')
|
||||
start++;
|
||||
if (start > 0)
|
||||
currentPair = currentPair.substr(start);
|
||||
if (currentPair.indexOf(prefix) == 0)
|
||||
foundCookie = currentPair.substr(prefix.length);
|
||||
}
|
||||
.provider('Authentication', Authentication);
|
||||
|
||||
return foundCookie;
|
||||
};
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
function Authentication() {
|
||||
function readCookie(name) {
|
||||
var foundCookie, prefix, pairs, i, currentPair, start;
|
||||
foundCookie = null;
|
||||
prefix = name + '=';
|
||||
pairs = document.cookie.split(';');
|
||||
for (i = 0; !foundCookie && i < pairs.length; i++) {
|
||||
currentPair = pairs[i];
|
||||
start = 0;
|
||||
while (currentPair.charAt(start) == ' ')
|
||||
start++;
|
||||
if (start > 0)
|
||||
currentPair = currentPair.substr(start);
|
||||
if (currentPair.indexOf(prefix) == 0)
|
||||
foundCookie = currentPair.substr(prefix.length);
|
||||
}
|
||||
|
||||
this.readLoginCookie = function() {
|
||||
var loginValues = null,
|
||||
cookie = this.readCookie('0xHIGHFLYxSOGo'),
|
||||
value;
|
||||
if (cookie && cookie.length > 8) {
|
||||
value = decodeURIComponent(cookie.substr(8));
|
||||
loginValues = value.base64decode().split(':');
|
||||
}
|
||||
return foundCookie;
|
||||
}
|
||||
|
||||
return loginValues;
|
||||
};
|
||||
function readLoginCookie() {
|
||||
var loginValues = null,
|
||||
cookie = readCookie('0xHIGHFLYxSOGo'),
|
||||
value;
|
||||
if (cookie && cookie.length > 8) {
|
||||
value = decodeURIComponent(cookie.substr(8));
|
||||
loginValues = value.base64decode().split(':');
|
||||
}
|
||||
|
||||
this.redirectUrl = function(username, domain) {
|
||||
var userName, address, baseAddress, altBaseAddress, parts, hostpart, protocol, newAddress;
|
||||
return loginValues;
|
||||
}
|
||||
|
||||
userName = username;
|
||||
if (domain)
|
||||
userName += '@' + domain.value;
|
||||
address = '' + window.location.href;
|
||||
baseAddress = ApplicationBaseURL + '/' + encodeURIComponent(userName);
|
||||
if (baseAddress[0] == '/') {
|
||||
parts = address.split('/');
|
||||
hostpart = parts[2];
|
||||
protocol = parts[0];
|
||||
baseAddress = protocol + '//' + hostpart + baseAddress;
|
||||
}
|
||||
parts = baseAddress.split('/');
|
||||
parts.splice(0, 3);
|
||||
altBaseAddress = parts.join('/');
|
||||
newAddress;
|
||||
if ((address.startsWith(baseAddress)
|
||||
|| address.startsWith(altBaseAddress))
|
||||
&& !address.endsWith('/logoff')) {
|
||||
newAddress = address;
|
||||
} else {
|
||||
newAddress = baseAddress;
|
||||
}
|
||||
function redirectUrl(username, domain) {
|
||||
var userName, address, baseAddress, altBaseAddress, parts, hostpart, protocol, newAddress;
|
||||
|
||||
// if (/theme=mobile/.test(window.location.search)) {
|
||||
// newAddress = baseAddress + '/Contacts' + '?theme=mobile';
|
||||
// }
|
||||
// else {
|
||||
// newAddress = baseAddress + '/Contacts';
|
||||
// }
|
||||
userName = username;
|
||||
if (domain)
|
||||
userName += '@' + domain.value;
|
||||
address = '' + window.location.href;
|
||||
baseAddress = ApplicationBaseURL + '/' + encodeURIComponent(userName);
|
||||
if (baseAddress[0] == '/') {
|
||||
parts = address.split('/');
|
||||
hostpart = parts[2];
|
||||
protocol = parts[0];
|
||||
baseAddress = protocol + '//' + hostpart + baseAddress;
|
||||
}
|
||||
parts = baseAddress.split('/');
|
||||
parts.splice(0, 3);
|
||||
altBaseAddress = parts.join('/');
|
||||
newAddress;
|
||||
if ((address.startsWith(baseAddress)
|
||||
|| address.startsWith(altBaseAddress))
|
||||
&& !address.endsWith('/logoff')) {
|
||||
newAddress = address;
|
||||
} else {
|
||||
newAddress = baseAddress;
|
||||
}
|
||||
|
||||
return newAddress;
|
||||
};
|
||||
return newAddress;
|
||||
}
|
||||
|
||||
this.$get = ['$q', '$http', function($q, $http) {
|
||||
var _this = this, service;
|
||||
this.$get = getService;
|
||||
|
||||
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;
|
||||
getService.$inject = ['$q', '$http', 'passwordPolicyConfig']
|
||||
function getService($q, $http, passwordPolicyConfig) {
|
||||
var _this = this, service;
|
||||
|
||||
if (data.loginSuffix && !username.endsWith(data.loginSuffix)) {
|
||||
username += loginSuffix;
|
||||
domain = false;
|
||||
}
|
||||
if (data.language && data.language != 'WONoSelectionString') {
|
||||
language = data.language;
|
||||
}
|
||||
service = {
|
||||
login: function(data) {
|
||||
var d = $q.defer(),
|
||||
username = data.username,
|
||||
password = data.password,
|
||||
domain = data.domain,
|
||||
language,
|
||||
rememberLogin = data.rememberLogin ? 1 : 0;
|
||||
|
||||
$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 = _this.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(_this.redirectUrl(username, domain));
|
||||
}
|
||||
}
|
||||
else {
|
||||
d.resolve(_this.redirectUrl(username, domain));
|
||||
}
|
||||
}
|
||||
}).error(function(data, status) {
|
||||
var msg, perr;
|
||||
if (data && data.LDAPPasswordPolicyError) {
|
||||
perr = data.LDAPPasswordPolicyError;
|
||||
if (perr == passwordPolicyConfig.PolicyNoError) {
|
||||
msg = l('Wrong username or password.');
|
||||
}
|
||||
else if (perr == passwordPolicyConfig.PolicyAccountLocked) {
|
||||
msg = l('Your account was locked due to too many failed attempts.');
|
||||
}
|
||||
else {
|
||||
msg = l('Login failed due to unhandled error case: ') + perr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
msg = l('Unhandled error response');
|
||||
}
|
||||
d.reject({error: msg});
|
||||
});
|
||||
return d.promise;
|
||||
}, // login: function(data) { ...
|
||||
|
||||
changePassword: function(newPassword) {
|
||||
var d = $q.defer(),
|
||||
loginCookie = _this.readLoginCookie();
|
||||
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: '/SOGo/so/changePassword',
|
||||
data: {
|
||||
userName: loginCookie[0],
|
||||
password: loginCookie[1],
|
||||
newPassword: newPassword }
|
||||
}).success(function(data, status) {
|
||||
d.resolve();
|
||||
}).error(function(data, status) {
|
||||
var error,
|
||||
perr = data["LDAPPasswordPolicyError"];
|
||||
|
||||
if (!perr) {
|
||||
perr = passwordPolicyConfig.PolicyPasswordSystemUnknown;
|
||||
error = _("Unhandled error response");
|
||||
}
|
||||
else if (perr == passwordPolicyConfig.PolicyNoError) {
|
||||
error = l("Password change failed");
|
||||
} else if (perr == passwordPolicyConfig.PolicyPasswordModNotAllowed) {
|
||||
error = l("Password change failed - Permission denied");
|
||||
} else if (perr == passwordPolicyConfig.PolicyInsufficientPasswordQuality) {
|
||||
error = l("Password change failed - Insufficient password quality");
|
||||
} else if (perr == passwordPolicyConfig.PolicyPasswordTooShort) {
|
||||
error = l("Password change failed - Password is too short");
|
||||
} else if (perr == passwordPolicyConfig.PolicyPasswordTooYoung) {
|
||||
error = l("Password change failed - Password is too young");
|
||||
} else if (perr == passwordPolicyConfig.PolicyPasswordInHistory) {
|
||||
error = l("Password change failed - Password is in history");
|
||||
} else {
|
||||
error = l("Unhandled policy error: %{0}").formatted(perr);
|
||||
perr = passwordPolicyConfig.PolicyPasswordUnknown;
|
||||
}
|
||||
|
||||
d.reject(error);
|
||||
});
|
||||
return d.promise;
|
||||
if (data.loginSuffix && !username.endsWith(data.loginSuffix)) {
|
||||
username += loginSuffix;
|
||||
domain = false;
|
||||
}
|
||||
};
|
||||
return service;
|
||||
}];
|
||||
});
|
||||
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 = 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(redirectUrl(username, domain));
|
||||
}
|
||||
}
|
||||
else {
|
||||
d.resolve(redirectUrl(username, domain));
|
||||
}
|
||||
}
|
||||
}).error(function(data, status) {
|
||||
var msg, perr;
|
||||
if (data && data.LDAPPasswordPolicyError) {
|
||||
perr = data.LDAPPasswordPolicyError;
|
||||
if (perr == passwordPolicyConfig.PolicyNoError) {
|
||||
msg = l('Wrong username or password.');
|
||||
}
|
||||
else if (perr == passwordPolicyConfig.PolicyAccountLocked) {
|
||||
msg = l('Your account was locked due to too many failed attempts.');
|
||||
}
|
||||
else {
|
||||
msg = l('Login failed due to unhandled error case: ') + perr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
msg = l('Unhandled error response');
|
||||
}
|
||||
d.reject({error: msg});
|
||||
});
|
||||
return d.promise;
|
||||
}, // login: function(data) { ...
|
||||
|
||||
changePassword: function(newPassword) {
|
||||
var d = $q.defer(),
|
||||
loginCookie = _this.readLoginCookie();
|
||||
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: '/SOGo/so/changePassword',
|
||||
data: {
|
||||
userName: loginCookie[0],
|
||||
password: loginCookie[1],
|
||||
newPassword: newPassword }
|
||||
}).success(function(data, status) {
|
||||
d.resolve();
|
||||
}).error(function(data, status) {
|
||||
var error,
|
||||
perr = data["LDAPPasswordPolicyError"];
|
||||
|
||||
if (!perr) {
|
||||
perr = passwordPolicyConfig.PolicyPasswordSystemUnknown;
|
||||
error = _("Unhandled error response");
|
||||
}
|
||||
else if (perr == passwordPolicyConfig.PolicyNoError) {
|
||||
error = l("Password change failed");
|
||||
} else if (perr == passwordPolicyConfig.PolicyPasswordModNotAllowed) {
|
||||
error = l("Password change failed - Permission denied");
|
||||
} else if (perr == passwordPolicyConfig.PolicyInsufficientPasswordQuality) {
|
||||
error = l("Password change failed - Insufficient password quality");
|
||||
} else if (perr == passwordPolicyConfig.PolicyPasswordTooShort) {
|
||||
error = l("Password change failed - Password is too short");
|
||||
} else if (perr == passwordPolicyConfig.PolicyPasswordTooYoung) {
|
||||
error = l("Password change failed - Password is too young");
|
||||
} else if (perr == passwordPolicyConfig.PolicyPasswordInHistory) {
|
||||
error = l("Password change failed - Password is in history");
|
||||
} else {
|
||||
error = l("Unhandled policy error: %{0}").formatted(perr);
|
||||
perr = passwordPolicyConfig.PolicyPasswordUnknown;
|
||||
}
|
||||
|
||||
d.reject(error);
|
||||
});
|
||||
return d.promise;
|
||||
}
|
||||
};
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular.module('SOGo.Common', ['ngMaterial', 'RecursionHelper'])
|
||||
angular.module('SOGo.Common', ['ngMaterial'])
|
||||
// md break-points values are hard-coded in angular-material/src/core/util/constant.js
|
||||
// $mdMedia has a built-in support for those values but can also evaluate others
|
||||
// For some reasons, angular-material's break-points don't match the specs
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* @ngInject
|
||||
* @example:
|
||||
|
||||
<md-button sg-subscribe="contact" sg-subscribe-on-select="subscribeToFolder">Subscribe ..</md-button>
|
||||
<md-button sg-subscribe="contact" sg-subscribe-on-select="subscribeToFolder">Subscribe ..</md-button>
|
||||
*/
|
||||
sgSubscribe.$inject = ['User'];
|
||||
function sgSubscribe(User) {
|
||||
@@ -28,66 +28,70 @@
|
||||
controllerAs: 'vm',
|
||||
link: link
|
||||
}
|
||||
sgSubscribeDialogController.$inject = ['$mdDialog'];
|
||||
function sgSubscribeDialogController($mdDialog) {
|
||||
var vm = this;
|
||||
vm.showDialog = function() {
|
||||
$mdDialog.show({
|
||||
templateUrl: '../Contacts/UIxContactsUserFolders',
|
||||
clickOutsideToClose: true,
|
||||
//scope: vm,
|
||||
//preserveScope: true,
|
||||
locals: {
|
||||
folderType: vm.folderType,
|
||||
onFolderSelect: vm.onFolderSelect
|
||||
//User: User
|
||||
},
|
||||
controller: sgSubscribeController,
|
||||
controllerAs: 'vm'
|
||||
});
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
sgSubscribeController.$inject = ['folderType', 'onFolderSelect', 'User'];
|
||||
function sgSubscribeController(folderType, onFolderSelect, User) {
|
||||
var vm = this;
|
||||
vm.selectedUser = null;
|
||||
|
||||
vm.searchTextOptions = {
|
||||
updateOn: 'default blur',
|
||||
debounce: {
|
||||
default: 300,
|
||||
blur: 0
|
||||
}
|
||||
};
|
||||
|
||||
vm.onChange = function() {
|
||||
User.$filter(vm.searchText).then(function(matches) {
|
||||
vm.users = matches;
|
||||
});
|
||||
};
|
||||
|
||||
vm.selectUser = function(i) {
|
||||
// Fetch folders of specific type for selected user
|
||||
vm.users[i].$folders(folderType).then(function() {
|
||||
vm.selectedUser = vm.users[i];
|
||||
});
|
||||
};
|
||||
|
||||
// Callback upon subscription to a folder
|
||||
vm.selectFolder = function(folder) {
|
||||
onFolderSelect({folderData: folder});
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
function link(scope, element, attrs, controller) {
|
||||
var inputEl = element.find('input');
|
||||
element.on('click', controller.showDialog);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
sgSubscribeDialogController.$inject = ['$mdDialog'];
|
||||
function sgSubscribeDialogController($mdDialog) {
|
||||
var vm = this;
|
||||
vm.showDialog = function() {
|
||||
$mdDialog.show({
|
||||
templateUrl: '../Contacts/UIxContactsUserFolders',
|
||||
clickOutsideToClose: true,
|
||||
locals: {
|
||||
folderType: vm.folderType,
|
||||
onFolderSelect: vm.onFolderSelect
|
||||
},
|
||||
controller: sgSubscribeController,
|
||||
controllerAs: 'vm'
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
sgSubscribeController.$inject = ['folderType', 'onFolderSelect', 'User'];
|
||||
function sgSubscribeController(folderType, onFolderSelect, User) {
|
||||
var vm = this;
|
||||
vm.selectedUser = null;
|
||||
|
||||
vm.searchTextOptions = {
|
||||
updateOn: 'default blur',
|
||||
debounce: {
|
||||
default: 300,
|
||||
blur: 0
|
||||
}
|
||||
};
|
||||
|
||||
vm.onChange = function() {
|
||||
User.$filter(vm.searchText).then(function(matches) {
|
||||
vm.users = matches;
|
||||
});
|
||||
};
|
||||
|
||||
vm.selectUser = function(i) {
|
||||
// Fetch folders of specific type for selected user
|
||||
vm.users[i].$folders(folderType).then(function() {
|
||||
vm.selectedUser = vm.users[i];
|
||||
});
|
||||
};
|
||||
|
||||
// Callback upon subscription to a folder
|
||||
vm.selectFolder = function(folder) {
|
||||
onFolderSelect({folderData: folder});
|
||||
};
|
||||
}
|
||||
|
||||
function link(scope, element, attrs, controller) {
|
||||
var inputEl = element.find('input');
|
||||
element.on('click', controller.showDialog);
|
||||
}
|
||||
|
||||
|
||||
angular
|
||||
.module('SOGo.Common')
|
||||
.directive('sgSubscribe', sgSubscribe);
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user