Skip to content

Commit 1df0a8b

Browse files
authored
Merge pull request #1383 from TechnologyEnhancedLearning/Develop/Fixes/TD-6134-Issues-on-'My-account---Personal-details'-screen
TD-6134: My account personal details page issues
2 parents 5508390 + 1877729 commit 1df0a8b

File tree

9 files changed

+59
-52
lines changed

9 files changed

+59
-52
lines changed

LearningHub.Nhs.WebUI/Controllers/MyAccountController.cs

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,37 @@ public async Task<IActionResult> UpdatePersonalDetails(MyAccountPersonalDetailsV
210210
return this.View("ChangePersonalDetails", model);
211211
}
212212

213+
if (model.PrimaryEmailAddress.ToLower() == model.SecondaryEmailAddress?.ToLower())
214+
{
215+
this.ModelState.AddModelError(nameof(model.SecondaryEmailAddress), CommonValidationErrorMessages.SecondaryEmailShouldNotBeSame);
216+
return this.View("ChangePersonalDetails", model);
217+
}
218+
219+
bool userPrimaryEmailAddressChanged = false;
220+
var user = await this.userService.GetUserByUserIdAsync(this.CurrentUserId);
221+
if (user != null)
222+
{
223+
if (!string.IsNullOrEmpty(model.PrimaryEmailAddress) && user.EmailAddress.ToLower() != model.PrimaryEmailAddress.ToLower())
224+
{
225+
userPrimaryEmailAddressChanged = true;
226+
}
227+
}
228+
229+
if (userPrimaryEmailAddressChanged)
230+
{
231+
if (await this.userService.DoesEmailAlreadyExist(model.PrimaryEmailAddress))
232+
{
233+
this.ModelState.AddModelError(
234+
nameof(model.PrimaryEmailAddress),
235+
CommonValidationErrorMessages.DuplicateEmailAddress);
236+
return this.View("ChangePersonalDetails", model);
237+
}
238+
else
239+
{
240+
await this.MyAccountUpdatePrimaryEmail(user.EmailAddress, model.PrimaryEmailAddress);
241+
}
242+
}
243+
213244
bool isSamePrimaryEmailPendingforValidate = await this.userService.CheckSamePrimaryemailIsPendingToValidate(model.SecondaryEmailAddress);
214245
if (isSamePrimaryEmailPendingforValidate)
215246
{
@@ -218,7 +249,6 @@ public async Task<IActionResult> UpdatePersonalDetails(MyAccountPersonalDetailsV
218249
}
219250

220251
await this.userService.UpdateMyAccountPersonalDetailsAsync(this.CurrentUserId, model);
221-
await this.MyAccountUpdatePrimaryEmail(model.PrimaryEmailAddress);
222252
this.ViewBag.SuccessMessage = CommonValidationErrorMessages.PersonalDetailsSuccessMessage;
223253
this.ViewBag.MyAction = "Index";
224254
return this.View("SuccessMessageMyAccount");
@@ -1507,48 +1537,26 @@ public async Task<ActionResult> CancelEmailChangeValidationToken()
15071537
return this.View("SuccessMessage");
15081538
}
15091539

1510-
private async Task MyAccountUpdatePrimaryEmail(string primaryEmailAddress)
1540+
private async Task MyAccountUpdatePrimaryEmail(string currentEmailAddress, string primaryEmailAddress)
15111541
{
1512-
bool userPrimaryEmailAddressChanged = false;
1513-
var user = await this.userService.GetUserByUserIdAsync(this.CurrentUserId);
1514-
if (user != null)
1542+
var isUserRoleUpgrade = await this.userService.ValidateUserRoleUpgradeAsync(currentEmailAddress, primaryEmailAddress);
1543+
UserRoleUpgrade userRoleUpgradeModel = new UserRoleUpgrade()
15151544
{
1516-
if (!string.IsNullOrEmpty(primaryEmailAddress) && user.EmailAddress.ToLower() != primaryEmailAddress.ToLower())
1517-
{
1518-
userPrimaryEmailAddressChanged = true;
1519-
}
1545+
UserId = this.CurrentUserId,
1546+
EmailAddress = primaryEmailAddress,
1547+
};
1548+
if (isUserRoleUpgrade)
1549+
{
1550+
userRoleUpgradeModel.UserHistoryTypeId = (int)UserHistoryType.UserRoleUpgarde;
15201551
}
1521-
1522-
if (userPrimaryEmailAddressChanged)
1552+
else
15231553
{
1524-
if (await this.userService.DoesEmailAlreadyExist(primaryEmailAddress))
1525-
{
1526-
this.ModelState.AddModelError(
1527-
nameof(primaryEmailAddress),
1528-
CommonValidationErrorMessages.DuplicateEmailAddress);
1529-
}
1530-
else
1531-
{
1532-
var isUserRoleUpgrade = await this.userService.ValidateUserRoleUpgradeAsync(user.EmailAddress, primaryEmailAddress);
1533-
UserRoleUpgrade userRoleUpgradeModel = new UserRoleUpgrade()
1534-
{
1535-
UserId = this.CurrentUserId,
1536-
EmailAddress = primaryEmailAddress,
1537-
};
1538-
if (isUserRoleUpgrade)
1539-
{
1540-
userRoleUpgradeModel.UserHistoryTypeId = (int)UserHistoryType.UserRoleUpgarde;
1541-
}
1542-
else
1543-
{
1544-
userRoleUpgradeModel.UserHistoryTypeId = (int)UserHistoryType.UserDetails;
1545-
}
1546-
1547-
await this.userService.GenerateEmailChangeValidationTokenAndSendEmailAsync(primaryEmailAddress, isUserRoleUpgrade);
1548-
await this.userService.UpdateUserRoleUpgradeAsync();
1549-
await this.userService.CreateUserRoleUpgradeAsync(userRoleUpgradeModel);
1550-
}
1554+
userRoleUpgradeModel.UserHistoryTypeId = (int)UserHistoryType.UserDetails;
15511555
}
1556+
1557+
await this.userService.GenerateEmailChangeValidationTokenAndSendEmailAsync(primaryEmailAddress, isUserRoleUpgrade);
1558+
await this.userService.UpdateUserRoleUpgradeAsync();
1559+
await this.userService.CreateUserRoleUpgradeAsync(userRoleUpgradeModel);
15521560
}
15531561
}
15541562
}

LearningHub.Nhs.WebUI/Models/UserProfile/MyAccountPersonalDetailsViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public class MyAccountPersonalDetailsViewModel
6666
/// Gets or sets the SecondaryEmailAddress.
6767
/// </summary>
6868
[DataType(DataType.EmailAddress)]
69-
[NotEqual("PrimaryEmailAddress", ErrorMessage = CommonValidationErrorMessages.SecondaryEmailShouldNotBeSame)]
7069
[MaxLength(100, ErrorMessage = CommonValidationErrorMessages.TooLongEmail)]
7170
[EmailAddress(ErrorMessage = CommonValidationErrorMessages.InvalidEmail)]
7271
[NoWhitespace(ErrorMessage = CommonValidationErrorMessages.WhitespaceInEmail)]

LearningHub.Nhs.WebUI/Services/UserService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,9 +1942,9 @@ public async Task UpdateMyAccountPersonalDetailsAsync(int userId, MyAccountPerso
19421942
PersonalDetailsViewModel personalDetailsViewModel = new PersonalDetailsViewModel
19431943
{
19441944
UserId = userId,
1945-
FirstName = model.FirstName,
1946-
LastName = model.LastName,
1947-
PreferredName = model.PreferredName,
1945+
FirstName = model.FirstName.Trim(),
1946+
LastName = model.LastName.Trim(),
1947+
PreferredName = model.PreferredName?.Trim(),
19481948
SecondaryEmailAddress = model.SecondaryEmailAddress,
19491949
};
19501950

LearningHub.Nhs.WebUI/Views/MyAccount/ChangePersonalDetails.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<div>
5858
<vc:text-input asp-for="PrimaryEmailAddress"
59-
label="Primary email address"
59+
label="Work email"
6060
populate-with-current-value="true"
6161
type="text"
6262
spell-check="false"
@@ -68,7 +68,7 @@
6868

6969
<div>
7070
<vc:text-input asp-for="SecondaryEmailAddress"
71-
label="Secondary email address"
71+
label="Secondary email"
7272
populate-with-current-value="true"
7373
type="text"
7474
spell-check="false"

LearningHub.Nhs.WebUI/Views/MyAccount/Index.cshtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@model LearningHub.Nhs.WebUI.Models.UserProfile.MyAccountPersonalDetailsViewModel
22

33
@{
4-
ViewData["Title"] = "Personal Details";
4+
ViewData["Title"] = "Personal details";
55
var isgeneralUser = User.IsInRole("BasicUser");
66
}
77
@section NavBreadcrumbs {
@@ -23,7 +23,7 @@
2323
</div>
2424
</section>
2525
}
26-
<div class="bg-white nhsuk-u-padding-bottom-9 nhsuk-u-padding-top-9">
26+
<div class="bg-white nhsuk-u-padding-bottom-7 nhsuk-u-padding-top-7">
2727
<div class="nhsuk-width-container app-width-container">
2828
<div class="nhsuk-grid-row">
2929
<div class="nhsuk-grid-column-one-quarter">
@@ -83,7 +83,7 @@
8383
</div>
8484
<div class="nhsuk-summary-list__row">
8585
<dt class="nhsuk-summary-list__key">
86-
Primary email address
86+
Work email
8787
</dt>
8888
@if (Model.NewPrimaryEmailAddress != "" && Model.NewPrimaryEmailAddress != null)
8989
{
@@ -102,7 +102,7 @@
102102

103103
<div class="nhsuk-summary-list__row">
104104
<dt class="nhsuk-summary-list__key">
105-
Secondary email address
105+
Secondary email
106106
</dt>
107107
<dd class="nhsuk-summary-list__value">
108108
@Model.SecondaryEmailAddress

LearningHub.Nhs.WebUI/Views/MyAccount/MyAccountSecurity.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323
</section>
2424
}
25-
<div class="bg-white nhsuk-u-padding-bottom-9 nhsuk-u-padding-top-9">
25+
<div class="bg-white nhsuk-u-padding-bottom-7 nhsuk-u-padding-top-7">
2626
<div class="nhsuk-width-container app-width-container">
2727
<div class="nhsuk-grid-row">
2828
<div class="nhsuk-grid-column-one-quarter">

LearningHub.Nhs.WebUI/Views/MyAccount/MyEmployment.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</div>
2424
</section>
2525
}
26-
<div class="bg-white nhsuk-u-padding-bottom-9 nhsuk-u-padding-top-9">
26+
<div class="bg-white nhsuk-u-padding-bottom-7 nhsuk-u-padding-top-7">
2727
<div class="nhsuk-width-container app-width-container">
2828
<div class="nhsuk-grid-row">
2929
<div class="nhsuk-grid-column-one-quarter">

LearningHub.Nhs.WebUI/Views/Notification/Index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</div>
2121
</section>
2222
}
23-
<div class="bg-white nhsuk-u-padding-bottom-9 nhsuk-u-padding-top-9">
23+
<div class="bg-white nhsuk-u-padding-bottom-7 nhsuk-u-padding-top-7">
2424
<div class="nhsuk-width-container app-width-container">
2525
<div class="nhsuk-grid-row">
2626
<div class="nhsuk-grid-column-one-quarter">

OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/Messaging/EmailTemplateService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public EmailDetails GetEmailChangeConfirmation(SendEmailModel<EmailChangeConfirm
154154
["Content"] = emailTemplate.Body,
155155
});
156156
var model = emailModel.Model;
157-
var expiraryDate = DateTime.Now.AddMinutes(model.TimeLimit);
157+
var expiraryDate = DateTimeOffset.Now.AddMinutes(model.TimeLimit);
158158
var replacementDict = new Dictionary<string, string>
159159
{
160160
["UserFirstName"] = model.UserFirstName,

0 commit comments

Comments
 (0)