Skip to content

Commit

Permalink
require updating encryption information when changing email address
Browse files Browse the repository at this point in the history
  • Loading branch information
GNUGradyn committed May 18, 2024
1 parent bfdee7a commit 4128abb
Show file tree
Hide file tree
Showing 4 changed files with 7 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.KEKSalt, request.EncryptedDEK, GetUserId());
return StatusCode(204);
}

Expand Down
2 changes: 2 additions & 0 deletions JournalyApiV2/Models/Requests/ChangeEmailRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
public class ChangeEmailRequest
{
public string Email { get; set; }
public string KEKSalt { get; set; }
public string EncryptedDEK { 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,13 +90,15 @@ 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 KEKSalt, string encryptedDEK, 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;
user.KEKSalt = KEKSalt;
user.EncryptedDEK = encryptedDEK;
await _userManager.UpdateAsync(user);
}

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 KEKSalt, string encryptedDEK, Guid userId);

Task ChangePassword(Guid userId, string oldPassword, string newPassword, string encryptedDEK, string KEKSalt,
bool signOutEverywhere = true);
Expand Down

0 comments on commit 4128abb

Please sign in to comment.