Skip to content

Commit

Permalink
new user fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GNUGradyn committed Oct 30, 2023
1 parent 643d360 commit 945291f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions JournalyApiV2/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public async Task<IActionResult> CreateUser([FromBody] NewUserRequest request)
{
await _authService.CreateUser(request.Email, request.Password, request.FirstName, request.LastName);
}
catch (ArgumentException ex)
{
return StatusCode(409, ex.Message);
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
Expand Down
2 changes: 2 additions & 0 deletions JournalyApiV2/Services/BLL/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public async Task<AuthenticationResponse> SignIn(string email, string password)

public async Task CreateUser(string email, string password, string firstName, string lastName)
{
if (await _userManager.FindByEmailAsync(email) != null) throw new ArgumentException("Email already in use");
var result = await _userManager.CreateAsync(new JournalyUser
{
FirstName = firstName,
Expand Down Expand Up @@ -145,6 +146,7 @@ public async Task<AuthenticationResponse> ChangeEmail(string email, Guid userId,
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);

// Generate new JWT and associated refresh token with the name updated
Expand Down

0 comments on commit 945291f

Please sign in to comment.