public async Task <IActionResult> ConfirmEmail([FromQuery] string userId, [FromQuery] string code) { if (userId == null || code == null) { return(Redirect("/")); } var user = await userManager.FindByIdAsync(userId); if (user == null) { return(NotFound($"Unable to load user with ID '{userId}'.")); } var result = await userManager.ConfirmEmailAsync(user, code); if (!result.Succeeded) { throw new InvalidOperationException($"Error confirming email for user with ID '{userId}':"); } var token = await identityTokenService.CreateTokenAsync(user); return(Redirect($"/emailConfirmed?t={token}")); }
public async Task <IActionResult> Login([FromBody] CredentialViewModel model) { var user = await userManager.FindByEmailAsync(model.Email); if (user == null || !user.EmailConfirmed) { return(BadRequest()); } var passwordVerificationResult = passwordHasher.VerifyHashedPassword(user, user.PasswordHash, model.Password); if (passwordVerificationResult != PasswordVerificationResult.Success) { return(BadRequest()); } var token = await identityTokenService.CreateTokenAsync(user); return(Ok(new { token })); }