Skip to content

Commit

Permalink
Log email change requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed Jun 22, 2024
1 parent 7056467 commit 3ba81e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions SS14.Auth.Shared/Data/SpaceUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public sealed record AccountLogCreated : AccountLogEntry;
public sealed record AccountLogEmailConfirmedChanged(bool NewConfirmed) : AccountLogEntry;

public sealed record AccountLogEmailChanged(string OldEmail, string NewEmail) : AccountLogEntry;
public sealed record AccountLogEmailChangeRequested(string OldEmail, string NewEmail) : AccountLogEntry;
public sealed record AccountLogUserNameChanged(string NewName, string OldName) : AccountLogEntry;
public sealed record AccountLogHubAdminChanged(bool NewAdmin) : AccountLogEntry;
public sealed record AccountLogPasswordChanged : AccountLogEntry;
Expand All @@ -148,6 +149,7 @@ public sealed record AccountLogAuthRoleRemoved(Guid Role) : AccountLogEntry;

public sealed record AccountLogCreatedReserved : AccountLogEntry;

[UsedImplicitly]
public enum AccountLogType
{
// @formatter:off
Expand Down Expand Up @@ -218,6 +220,10 @@ public enum AccountLogType
[AuditEntryType(typeof(AccountLogCreatedReserved))]
[AccountLogRetention(AccountLogRetainType.AccountManagement)]
CreatedReserved = 16,

[AuditEntryType(typeof(AccountLogEmailChangeRequested))]
[AccountLogRetention(AccountLogRetainType.AccountManagement)]
EmailChangeRequested = 17,
// @formatter:on
}

Expand Down
9 changes: 6 additions & 3 deletions SS14.Web/Areas/Identity/Pages/Account/Manage/Email.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.WebUtilities;
using SS14.Auth.Shared;
using SS14.Auth.Shared.Data;
using SS14.Auth.Shared.Emails;

Expand All @@ -17,15 +16,18 @@ public partial class EmailModel : PageModel
private readonly UserManager<SpaceUser> _userManager;
private readonly SignInManager<SpaceUser> _signInManager;
private readonly IEmailSender _emailSender;
private readonly AccountLogManager _logManager;

public EmailModel(
UserManager<SpaceUser> userManager,
SignInManager<SpaceUser> signInManager,
IEmailSender emailSender)
IEmailSender emailSender,
AccountLogManager logManager)
{
_userManager = userManager;
_signInManager = signInManager;
_emailSender = emailSender;
_logManager = logManager;
}

public string Username { get; set; }
Expand Down Expand Up @@ -102,6 +104,7 @@ await _emailSender.SendEmailAsync(
Input.NewEmail,
"Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
await _logManager.LogAndSave(user, new AccountLogEmailChangeRequested(email, Input.NewEmail));

StatusMessage = "Confirmation link to change email sent. Please check your email.";
return RedirectToPage();
Expand Down Expand Up @@ -142,4 +145,4 @@ await _emailSender.SendEmailAsync(
StatusMessage = "Verification email sent. Please check your email.";
return RedirectToPage();
}
}
}

0 comments on commit 3ba81e6

Please sign in to comment.