feat(password-recovery): Add password recovery with secret question or secondary email

This commit is contained in:
smizrahi committed 2022-10-03 08:56:41 +02:00
1 parent 6931186bba
commit 656807b77d
47 files changed
+1729 -159

No files matched your search

@@ -20,6 +20,8 @@
PolicyPasswordTooShort: 6,
PolicyPasswordTooYoung: 7,
PolicyPasswordInHistory: 8,
PolicyPasswordRecoveryFailed: 9,
PolicyPasswordRecoveryInvalidToken: 10,
PolicyNoError: 65535
})
@@ -168,7 +170,7 @@
return d.promise;
}, // login: function(data) { ...
changePassword: function(userName, domain, newPassword, oldPassword) {
changePassword: function(userName, domain, newPassword, oldPassword, token) {
var d = $q.defer(),
xsrfCookie = $cookies.get('XSRF-TOKEN');
@@ -180,7 +182,7 @@
headers: {
'X-XSRF-TOKEN' : xsrfCookie
},
data: { userName: userName, newPassword: newPassword, oldPassword: oldPassword }
data: { userName: userName, newPassword: newPassword, oldPassword: oldPassword, token: token }
}).then(function() {
d.resolve({url: redirectUrl(userName, domain)});
}, function(response) {
@@ -205,6 +207,8 @@
error = l("Password change failed - Password is too young");
} else if (perr == passwordPolicyConfig.PolicyPasswordInHistory) {
error = l("Password change failed - Password is in history");
} else if (perr == passwordPolicyConfig.PolicyPasswordRecoveryInvalidToken) {
error = l("Invalid token. Could not change password");
} else {
error = l("Unhandled policy error: %{0}").formatted(perr);
perr = passwordPolicyConfig.PolicyPasswordUnknown;
@@ -215,6 +219,113 @@
d.reject(error);
});
return d.promise;
},
passwordRecovery: function (userName, domain) {
const self = this;
var d = $q.defer(),
xsrfCookie = $cookies.get('XSRF-TOKEN');
$cookies.remove('XSRF-TOKEN', { path: '/SOGo/' });
$http({
method: 'POST',
url: '/SOGo/so/passwordRecovery',
headers: {
'X-XSRF-TOKEN': xsrfCookie
},
data: { userName: userName, domain: domain }
}).then(function (response) {
d.resolve(Object.assign(
{ url: redirectUrl(userName, domain) },
response.data,
'SecretQuestion' === response.data.mode ? { secretQuestionLabel: l('passwordRecovery_' + response.data.secretQuestion) } : {},
'SecondaryEmail' === response.data.mode ? { obfuscatedRecoveryEmail: response.data.obfuscatedSecondaryEmail } : {}
));
}, function () {
// Restore the cookie
$cookies.put('XSRF-TOKEN', xsrfCookie, { path: '/SOGo/' });
d.reject(l("Unhandled policy error: %{0}").formatted(passwordPolicyConfig.PolicyPasswordRecoveryFailed));
});
return d.promise;
},
passwordRecoveryEmail: function (userName, domain, mode, mailDomain) {
const self = this;
var d = $q.defer(),
xsrfCookie = $cookies.get('XSRF-TOKEN');
$cookies.remove('XSRF-TOKEN', { path: '/SOGo/' });
$http({
method: 'POST',
url: '/SOGo/so/passwordRecoveryEmail',
headers: {
'X-XSRF-TOKEN': xsrfCookie
},
data: { userName: userName, domain: domain, mode: mode, mailDomain: mailDomain }
}).then(function (response) {
d.resolve(response.data.jwt);
}, function (response) {
// Restore the cookie
$cookies.put('XSRF-TOKEN', xsrfCookie, { path: '/SOGo/' });
d.reject(l(response.data));
});
return d.promise;
},
passwordRecoveryCheck: function (userName, domain, mode, question, answer, mailDomain) {
const self = this;
var d = $q.defer(),
xsrfCookie = $cookies.get('XSRF-TOKEN');
$cookies.remove('XSRF-TOKEN', { path: '/SOGo/' });
$http({
method: 'POST',
url: '/SOGo/so/passwordRecoveryCheck',
headers: {
'X-XSRF-TOKEN': xsrfCookie
},
data: { userName: userName, domain: domain, mode: mode, question: question, answer: answer, mailDomain: mailDomain }
}).then(function (response) {
d.resolve(response.data.jwt);
}, function (response) {
// Restore the cookie
$cookies.put('XSRF-TOKEN', xsrfCookie, { path: '/SOGo/' });
d.reject(l(response.data));
});
return d.promise;
},
passwordRecoveryEnabled: function (userName, domain) {
const self = this;
var d = $q.defer(),
xsrfCookie = $cookies.get('XSRF-TOKEN');
$cookies.remove('XSRF-TOKEN', { path: '/SOGo/' });
$http({
method: 'POST',
url: '/SOGo/so/passwordRecoveryEnabled',
headers: {
'X-XSRF-TOKEN': xsrfCookie
},
data: { userName: userName, domain: domain }
}).then(function (response) {
d.resolve(response.data.domain);
}, function () {
// Restore the cookie
$cookies.put('XSRF-TOKEN', xsrfCookie, { path: '/SOGo/' });
d.reject();
});
return d.promise;
}
};
return service;
@@ -20,14 +20,43 @@
</md-dialog>
*/
sgRippleClick.$inject = ['$log', '$timeout'];
function sgRippleClick($log, $timeout) {
sgRippleClick.$inject = ['$log', '$timeout', '$rootScope'];
function sgRippleClick($log, $timeout, scope) {
function rippleEffect(element, coordinates, container, content) {
// Show ripple
angular.element(container).css({ 'overflow': 'hidden', 'position': 'relative' });
angular.element(content).css({ top: container.scrollTop + 'px' });
element.css({
'top': (coordinates.top - container.offsetTop + container.scrollTop) + 'px',
'left': (coordinates.left - container.offsetLeft) + 'px',
'height': '400vmin',
'width': '400vmin'
});
// Show ripple content
content.classList.remove('ng-hide');
}
scope.$on('sgRippleDo', function (e, containerName) {
const container = document.getElementById(containerName);
container.classList.remove('ng-hide');
rippleEffect(
angular.element(document.querySelector('sg-ripple'))
, { left: (window.innerWidth / 2), top: (window.innerHeight / 2) }
, container
, document.querySelector('sg-ripple-content')
);
});
return {
restrict: 'A',
compile: compile
};
function compile(tElement, tAttrs) {
return function postLink(scope, element, attr) {
@@ -90,26 +119,16 @@
}
if (content.classList.contains('ng-hide')) {
// Show ripple
angular.element(container).css({ 'overflow': 'hidden', 'position': 'relative' });
angular.element(content).css({ top: container.scrollTop + 'px' });
$timeout(function() {
// Wait until next digest for CSS animation to work
ripple.css({
'top': (coordinates.top - container.offsetTop + container.scrollTop) + 'px',
'left': (coordinates.left - container.offsetLeft) + 'px',
'height': '400vmin',
'width': '400vmin'
});
// Show ripple content
content.classList.remove('ng-hide');
rippleEffect(ripple, coordinates, container, content);
});
}
else {
// Hide ripple layer
ripple.css({
'top': (coordinates.top - container.offsetTop + container.scrollTop) + 'px',
'left': (coordinates.left - container.offsetLeft) + 'px',
'left': (coordinates.left - container.offsetLeft) + 'px',
'height': '0px',
'width': '0px'
});
@@ -0,0 +1,25 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* sgFocus - A service to set the focus on the element associated to a specific string
* @memberof SOGo.Common
* @param {string} name - the string identifier of the element
* @see {@link SOGo.Common.sgRippleClick}
* @ngInject
*/
sgRippleClick.$inject = ['$rootScope', '$timeout'];
function sgRippleClick($rootScope, $timeout) {
return function (containerName) {
$timeout(function() {
$rootScope.$broadcast('sgRippleDo', containerName);
});
};
}
angular
.module('SOGo.Common')
.factory('sgRippleClick', sgRippleClick);
})();