From 48432c58cecabc0d1c87c8b25a0a6916c78fb80d Mon Sep 17 00:00:00 2001 From: OluwatobiAwe Date: Fri, 28 Oct 2022 08:56:24 +0100 Subject: [PATCH 1/3] Model State Checked earlier in the request. --- .../Controllers/ChangePasswordController.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs b/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs index 710a1a1c16..16493d1b06 100644 --- a/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs +++ b/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs @@ -42,6 +42,12 @@ public async Task Index(ChangePasswordFormData formData, DlsSubAp var adminId = User.GetAdminId(); var delegateId = User.GetCandidateId(); + if (!ModelState.IsValid) + { + var model = new ChangePasswordViewModel(formData, dlsSubApplication); + return View(model); + } + var verifiedLinkedUsersAccounts = string.IsNullOrEmpty(formData.CurrentPassword) ? new UserAccountSet() : userService.GetVerifiedLinkedUsersAccounts(adminId, delegateId, formData.CurrentPassword!); @@ -54,11 +60,11 @@ public async Task Index(ChangePasswordFormData formData, DlsSubAp ); } - if (!ModelState.IsValid) - { - var model = new ChangePasswordViewModel(formData, dlsSubApplication); - return View(model); - } + //if (!ModelState.IsValid) + //{ + // var model = new ChangePasswordViewModel(formData, dlsSubApplication); + // return View(model); + //} var newPassword = formData.Password!; From f996c3d7b1f0ef315207eeeb562da50075a8940e Mon Sep 17 00:00:00 2001 From: OluwatobiAwe Date: Fri, 28 Oct 2022 15:25:58 +0100 Subject: [PATCH 2/3] update --- .../Controllers/ChangePasswordController.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs b/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs index 16493d1b06..3e89344315 100644 --- a/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs +++ b/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs @@ -42,30 +42,28 @@ public async Task Index(ChangePasswordFormData formData, DlsSubAp var adminId = User.GetAdminId(); var delegateId = User.GetCandidateId(); + + + var verifiedLinkedUsersAccounts = string.IsNullOrEmpty(formData.CurrentPassword) + ? new UserAccountSet() + : userService.GetVerifiedLinkedUsersAccounts(adminId, delegateId, formData.CurrentPassword!); + if (!ModelState.IsValid) { var model = new ChangePasswordViewModel(formData, dlsSubApplication); return View(model); } - var verifiedLinkedUsersAccounts = string.IsNullOrEmpty(formData.CurrentPassword) - ? new UserAccountSet() - : userService.GetVerifiedLinkedUsersAccounts(adminId, delegateId, formData.CurrentPassword!); - if (!verifiedLinkedUsersAccounts.Any()) { ModelState.AddModelError( nameof(ChangePasswordFormData.CurrentPassword), CommonValidationErrorMessages.IncorrectPassword ); + return View(new ChangePasswordViewModel(formData, dlsSubApplication)); } - //if (!ModelState.IsValid) - //{ - // var model = new ChangePasswordViewModel(formData, dlsSubApplication); - // return View(model); - //} - + var newPassword = formData.Password!; await passwordService.ChangePasswordAsync(verifiedLinkedUsersAccounts.GetUserRefs(), newPassword); From a3ebe1c906bea695798dd91943be0191c82aaf7a Mon Sep 17 00:00:00 2001 From: OluwatobiAwe Date: Fri, 28 Oct 2022 16:15:55 +0100 Subject: [PATCH 3/3] format doc --- .../Controllers/ChangePasswordController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs b/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs index 3e89344315..23f98efd64 100644 --- a/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs +++ b/DigitalLearningSolutions.Web/Controllers/ChangePasswordController.cs @@ -42,7 +42,7 @@ public async Task Index(ChangePasswordFormData formData, DlsSubAp var adminId = User.GetAdminId(); var delegateId = User.GetCandidateId(); - + var verifiedLinkedUsersAccounts = string.IsNullOrEmpty(formData.CurrentPassword) ? new UserAccountSet() @@ -63,7 +63,7 @@ public async Task Index(ChangePasswordFormData formData, DlsSubAp return View(new ChangePasswordViewModel(formData, dlsSubApplication)); } - + var newPassword = formData.Password!; await passwordService.ChangePasswordAsync(verifiedLinkedUsersAccounts.GetUserRefs(), newPassword);