profile: email change now requires password

This commit is contained in:
Girish Ramakrishnan
2024-01-18 17:34:45 +01:00
parent 0dfadc5922
commit f43a601e86
9 changed files with 144 additions and 81 deletions
+23 -30
View File
@@ -354,42 +354,44 @@ angular.module('Application').controller('ProfileController', ['$scope', '$trans
}
};
$scope.emailchange = {
$scope.emailChange = {
busy: false,
error: {},
email: '',
password: '',
reset: function () {
$scope.emailchange.busy = false;
$scope.emailchange.error.email = null;
$scope.emailchange.email = '';
$scope.emailChange.busy = false;
$scope.emailChange.error = {};
$scope.emailChange.email = '';
$scope.emailChange.password = '';
$scope.emailChangeForm.$setUntouched();
$scope.emailChangeForm.$setPristine();
},
show: function () {
$scope.emailchange.reset();
$scope.emailChange.reset();
$('#emailChangeModal').modal('show');
},
submit: function () {
$scope.emailchange.error.email = null;
$scope.emailchange.busy = true;
$scope.emailChange.error.email = null;
$scope.emailChange.busy = true;
var data = {
email: $scope.emailchange.email
};
Client.updateProfile(data, function (error) {
$scope.emailchange.busy = false;
Client.setProfileEmail($scope.emailChange.email, $scope.emailChange.password, function (error) {
$scope.emailChange.busy = false;
if (error) {
if (error.statusCode === 409) $scope.emailchange.error.email = 'Email already taken';
else if (error.statusCode === 400) $scope.emailchange.error.email = error.message;
else console.error('Unable to change email.', error);
$('#inputEmailChangeEmail').focus();
if (error.statusCode === 412) {
$scope.emailChange.error.password = true;
$scope.emailChange.password = '';
$scope.emailChangeForm.password.$setPristine();
$('#inputFallbackEmailChangePassword').focus();
} else {
$scope.emailChange.error.email = error.message;
$('#inputEmailChangeEmail').focus();
}
$scope.emailChangeForm.$setUntouched();
$scope.emailChangeForm.$setPristine();
@@ -399,7 +401,7 @@ angular.module('Application').controller('ProfileController', ['$scope', '$trans
Client.refreshUserInfo();
$scope.emailchange.reset();
$scope.emailChange.reset();
$('#emailChangeModal').modal('hide');
});
}
@@ -436,12 +438,7 @@ angular.module('Application').controller('ProfileController', ['$scope', '$trans
$scope.fallbackEmailChange.error.generic = null;
$scope.fallbackEmailChange.busy = true;
var data = {
fallbackEmail: $scope.fallbackEmailChange.email,
password: $scope.fallbackEmailChange.password
};
Client.updateProfile(data, function (error) {
Client.setProfileFallbackEmail($scope.fallbackEmailChange.email, $scope.fallbackEmailChange.password, function (error) {
$scope.fallbackEmailChange.busy = false;
if (error) {
@@ -592,11 +589,7 @@ angular.module('Application').controller('ProfileController', ['$scope', '$trans
$scope.displayNameChange.error.displayName = null;
$scope.displayNameChange.busy = true;
var user = {
displayName: $scope.displayNameChange.displayName
};
Client.updateProfile(user, function (error) {
Client.setProfileDisplayName($scope.displayNameChange.displayName, function (error) {
$scope.displayNameChange.busy = false;
if (error) {