Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 46 additions & 38 deletions LearningHub.Nhs.WebUI/Controllers/MyAccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,37 @@ public async Task<IActionResult> UpdatePersonalDetails(MyAccountPersonalDetailsV
return this.View("ChangePersonalDetails", model);
}

if (model.PrimaryEmailAddress.ToLower() == model.SecondaryEmailAddress?.ToLower())
{
this.ModelState.AddModelError(nameof(model.SecondaryEmailAddress), CommonValidationErrorMessages.SecondaryEmailShouldNotBeSame);
return this.View("ChangePersonalDetails", model);
}

bool userPrimaryEmailAddressChanged = false;
var user = await this.userService.GetUserByUserIdAsync(this.CurrentUserId);
if (user != null)
{
if (!string.IsNullOrEmpty(model.PrimaryEmailAddress) && user.EmailAddress.ToLower() != model.PrimaryEmailAddress.ToLower())
{
userPrimaryEmailAddressChanged = true;
}
}

if (userPrimaryEmailAddressChanged)
{
if (await this.userService.DoesEmailAlreadyExist(model.PrimaryEmailAddress))
{
this.ModelState.AddModelError(
nameof(model.PrimaryEmailAddress),
CommonValidationErrorMessages.DuplicateEmailAddress);
return this.View("ChangePersonalDetails", model);
}
else
{
await this.MyAccountUpdatePrimaryEmail(user.EmailAddress, model.PrimaryEmailAddress);
}
}

bool isSamePrimaryEmailPendingforValidate = await this.userService.CheckSamePrimaryemailIsPendingToValidate(model.SecondaryEmailAddress);
if (isSamePrimaryEmailPendingforValidate)
{
Expand All @@ -218,7 +249,6 @@ public async Task<IActionResult> UpdatePersonalDetails(MyAccountPersonalDetailsV
}

await this.userService.UpdateMyAccountPersonalDetailsAsync(this.CurrentUserId, model);
await this.MyAccountUpdatePrimaryEmail(model.PrimaryEmailAddress);
this.ViewBag.SuccessMessage = CommonValidationErrorMessages.PersonalDetailsSuccessMessage;
this.ViewBag.MyAction = "Index";
return this.View("SuccessMessageMyAccount");
Expand Down Expand Up @@ -1507,48 +1537,26 @@ public async Task<ActionResult> CancelEmailChangeValidationToken()
return this.View("SuccessMessage");
}

private async Task MyAccountUpdatePrimaryEmail(string primaryEmailAddress)
private async Task MyAccountUpdatePrimaryEmail(string currentEmailAddress, string primaryEmailAddress)
{
bool userPrimaryEmailAddressChanged = false;
var user = await this.userService.GetUserByUserIdAsync(this.CurrentUserId);
if (user != null)
var isUserRoleUpgrade = await this.userService.ValidateUserRoleUpgradeAsync(currentEmailAddress, primaryEmailAddress);
UserRoleUpgrade userRoleUpgradeModel = new UserRoleUpgrade()
{
if (!string.IsNullOrEmpty(primaryEmailAddress) && user.EmailAddress.ToLower() != primaryEmailAddress.ToLower())
{
userPrimaryEmailAddressChanged = true;
}
UserId = this.CurrentUserId,
EmailAddress = primaryEmailAddress,
};
if (isUserRoleUpgrade)
{
userRoleUpgradeModel.UserHistoryTypeId = (int)UserHistoryType.UserRoleUpgarde;
}

if (userPrimaryEmailAddressChanged)
else
{
if (await this.userService.DoesEmailAlreadyExist(primaryEmailAddress))
{
this.ModelState.AddModelError(
nameof(primaryEmailAddress),
CommonValidationErrorMessages.DuplicateEmailAddress);
}
else
{
var isUserRoleUpgrade = await this.userService.ValidateUserRoleUpgradeAsync(user.EmailAddress, primaryEmailAddress);
UserRoleUpgrade userRoleUpgradeModel = new UserRoleUpgrade()
{
UserId = this.CurrentUserId,
EmailAddress = primaryEmailAddress,
};
if (isUserRoleUpgrade)
{
userRoleUpgradeModel.UserHistoryTypeId = (int)UserHistoryType.UserRoleUpgarde;
}
else
{
userRoleUpgradeModel.UserHistoryTypeId = (int)UserHistoryType.UserDetails;
}

await this.userService.GenerateEmailChangeValidationTokenAndSendEmailAsync(primaryEmailAddress, isUserRoleUpgrade);
await this.userService.UpdateUserRoleUpgradeAsync();
await this.userService.CreateUserRoleUpgradeAsync(userRoleUpgradeModel);
}
userRoleUpgradeModel.UserHistoryTypeId = (int)UserHistoryType.UserDetails;
}

await this.userService.GenerateEmailChangeValidationTokenAndSendEmailAsync(primaryEmailAddress, isUserRoleUpgrade);
await this.userService.UpdateUserRoleUpgradeAsync();
await this.userService.CreateUserRoleUpgradeAsync(userRoleUpgradeModel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class MyAccountPersonalDetailsViewModel
/// Gets or sets the SecondaryEmailAddress.
/// </summary>
[DataType(DataType.EmailAddress)]
[NotEqual("PrimaryEmailAddress", ErrorMessage = CommonValidationErrorMessages.SecondaryEmailShouldNotBeSame)]
[MaxLength(100, ErrorMessage = CommonValidationErrorMessages.TooLongEmail)]
[EmailAddress(ErrorMessage = CommonValidationErrorMessages.InvalidEmail)]
[NoWhitespace(ErrorMessage = CommonValidationErrorMessages.WhitespaceInEmail)]
Expand Down
6 changes: 3 additions & 3 deletions LearningHub.Nhs.WebUI/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1942,9 +1942,9 @@ public async Task UpdateMyAccountPersonalDetailsAsync(int userId, MyAccountPerso
PersonalDetailsViewModel personalDetailsViewModel = new PersonalDetailsViewModel
{
UserId = userId,
FirstName = model.FirstName,
LastName = model.LastName,
PreferredName = model.PreferredName,
FirstName = model.FirstName.Trim(),
LastName = model.LastName.Trim(),
PreferredName = model.PreferredName?.Trim(),
SecondaryEmailAddress = model.SecondaryEmailAddress,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<div>
<vc:text-input asp-for="PrimaryEmailAddress"
label="Primary email address"
label="Work email"
populate-with-current-value="true"
type="text"
spell-check="false"
Expand All @@ -68,7 +68,7 @@

<div>
<vc:text-input asp-for="SecondaryEmailAddress"
label="Secondary email address"
label="Secondary email"
populate-with-current-value="true"
type="text"
spell-check="false"
Expand Down
8 changes: 4 additions & 4 deletions LearningHub.Nhs.WebUI/Views/MyAccount/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@model LearningHub.Nhs.WebUI.Models.UserProfile.MyAccountPersonalDetailsViewModel

@{
ViewData["Title"] = "Personal Details";
ViewData["Title"] = "Personal details";
var isgeneralUser = User.IsInRole("BasicUser");
}
@section NavBreadcrumbs {
Expand All @@ -23,7 +23,7 @@
</div>
</section>
}
<div class="bg-white nhsuk-u-padding-bottom-9 nhsuk-u-padding-top-9">
<div class="bg-white nhsuk-u-padding-bottom-7 nhsuk-u-padding-top-7">
<div class="nhsuk-width-container app-width-container">
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-one-quarter">
Expand Down Expand Up @@ -83,7 +83,7 @@
</div>
<div class="nhsuk-summary-list__row">
<dt class="nhsuk-summary-list__key">
Primary email address
Work email
</dt>
@if (Model.NewPrimaryEmailAddress != "" && Model.NewPrimaryEmailAddress != null)
{
Expand All @@ -102,7 +102,7 @@

<div class="nhsuk-summary-list__row">
<dt class="nhsuk-summary-list__key">
Secondary email address
Secondary email
</dt>
<dd class="nhsuk-summary-list__value">
@Model.SecondaryEmailAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
</section>
}
<div class="bg-white nhsuk-u-padding-bottom-9 nhsuk-u-padding-top-9">
<div class="bg-white nhsuk-u-padding-bottom-7 nhsuk-u-padding-top-7">
<div class="nhsuk-width-container app-width-container">
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-one-quarter">
Expand Down
2 changes: 1 addition & 1 deletion LearningHub.Nhs.WebUI/Views/MyAccount/MyEmployment.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</div>
</section>
}
<div class="bg-white nhsuk-u-padding-bottom-9 nhsuk-u-padding-top-9">
<div class="bg-white nhsuk-u-padding-bottom-7 nhsuk-u-padding-top-7">
<div class="nhsuk-width-container app-width-container">
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-one-quarter">
Expand Down
2 changes: 1 addition & 1 deletion LearningHub.Nhs.WebUI/Views/Notification/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
</section>
}
<div class="bg-white nhsuk-u-padding-bottom-9 nhsuk-u-padding-top-9">
<div class="bg-white nhsuk-u-padding-bottom-7 nhsuk-u-padding-top-7">
<div class="nhsuk-width-container app-width-container">
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-one-quarter">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public EmailDetails GetEmailChangeConfirmation(SendEmailModel<EmailChangeConfirm
["Content"] = emailTemplate.Body,
});
var model = emailModel.Model;
var expiraryDate = DateTime.Now.AddMinutes(model.TimeLimit);
var expiraryDate = DateTimeOffset.Now.AddMinutes(model.TimeLimit);
var replacementDict = new Dictionary<string, string>
{
["UserFirstName"] = model.UserFirstName,
Expand Down
Loading