From 666e6f650c456c72b05142b34789751aa03ed21e Mon Sep 17 00:00:00 2001 From: Gradyn Wursten Date: Sat, 18 May 2024 12:51:25 -0600 Subject: [PATCH] eeeee --- JournalyApiV2/Controllers/AuthController.cs | 2 +- JournalyApiV2/Models/Requests/ChangeEmailRequest.cs | 1 + JournalyApiV2/Services/BLL/AuthService.cs | 4 +++- JournalyApiV2/Services/BLL/IAuthService.cs | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/JournalyApiV2/Controllers/AuthController.cs b/JournalyApiV2/Controllers/AuthController.cs index 1227a45..1ceddb8 100644 --- a/JournalyApiV2/Controllers/AuthController.cs +++ b/JournalyApiV2/Controllers/AuthController.cs @@ -86,7 +86,7 @@ public async Task ChangeName([FromBody] ChangeNameRequest request [HttpPost] public async Task ChangeEmail([FromBody] ChangeEmailRequest request) { - await _authService.ChangeEmail(request.Email, GetUserId()); + await _authService.ChangeEmail(request.Email, request.PasswordHash, GetUserId()); return StatusCode(204); } diff --git a/JournalyApiV2/Models/Requests/ChangeEmailRequest.cs b/JournalyApiV2/Models/Requests/ChangeEmailRequest.cs index bc8ffa1..72c8dfc 100644 --- a/JournalyApiV2/Models/Requests/ChangeEmailRequest.cs +++ b/JournalyApiV2/Models/Requests/ChangeEmailRequest.cs @@ -3,4 +3,5 @@ public class ChangeEmailRequest { public string Email { get; set; } + public string PasswordHash { get; set; } } \ No newline at end of file diff --git a/JournalyApiV2/Services/BLL/AuthService.cs b/JournalyApiV2/Services/BLL/AuthService.cs index 4139d4d..d407076 100644 --- a/JournalyApiV2/Services/BLL/AuthService.cs +++ b/JournalyApiV2/Services/BLL/AuthService.cs @@ -90,7 +90,7 @@ public async Task ChangeName(string firstName, string lastName, Guid userId) await _userManager.UpdateAsync(user); } - public async Task ChangeEmail(string email, Guid userId) + public async Task ChangeEmail(string email, string passwordHash, Guid userId) { // change email var user = await _userManager.FindByIdAsync(userId.ToString()); @@ -98,6 +98,8 @@ public async Task ChangeEmail(string email, Guid userId) user.Email = email; user.UserName = email; await _userManager.UpdateAsync(user); + var resetToken = await _userManager.GeneratePasswordResetTokenAsync(user); + await _userManager.ResetPasswordAsync(user, resetToken, passwordHash); } public async Task ChangePassword(Guid userId, string oldPassword, string newPassword, string encryptedDEK, string KEKSalt, bool signOutEverywhere = true) diff --git a/JournalyApiV2/Services/BLL/IAuthService.cs b/JournalyApiV2/Services/BLL/IAuthService.cs index 0360272..a49b515 100644 --- a/JournalyApiV2/Services/BLL/IAuthService.cs +++ b/JournalyApiV2/Services/BLL/IAuthService.cs @@ -9,7 +9,7 @@ Task CreateUser(string email, string password, string firstName, string lastName Task SignIn(string email, string password); Task VoidToken(string token); Task ChangeName(string firstName, string lastName, Guid userId); - Task ChangeEmail(string email, Guid userId); + Task ChangeEmail(string email, string passwordHash, Guid userId); Task ChangePassword(Guid userId, string oldPassword, string newPassword, string encryptedDEK, string KEKSalt, bool signOutEverywhere = true);