Skip to content

Commit

Permalink
eeeee
Browse files Browse the repository at this point in the history
  • Loading branch information
GNUGradyn committed May 18, 2024
1 parent 35bd0f6 commit 666e6f6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion JournalyApiV2/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<IActionResult> ChangeName([FromBody] ChangeNameRequest request
[HttpPost]
public async Task<IActionResult> ChangeEmail([FromBody] ChangeEmailRequest request)
{
await _authService.ChangeEmail(request.Email, GetUserId());
await _authService.ChangeEmail(request.Email, request.PasswordHash, GetUserId());
return StatusCode(204);
}

Expand Down
1 change: 1 addition & 0 deletions JournalyApiV2/Models/Requests/ChangeEmailRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public class ChangeEmailRequest
{
public string Email { get; set; }
public string PasswordHash { get; set; }
}
4 changes: 3 additions & 1 deletion JournalyApiV2/Services/BLL/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ 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());
if (user == null) throw new ArgumentException("User not found");
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)
Expand Down
2 changes: 1 addition & 1 deletion JournalyApiV2/Services/BLL/IAuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Task CreateUser(string email, string password, string firstName, string lastName
Task<AuthenticationResponse> 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);
Expand Down

0 comments on commit 666e6f6

Please sign in to comment.