public async Task <IActionResult> GenerateToken([FromBody] LoginModel model) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { throw new ApiException(400, "Invalid email", ErrorCode.InvalidCredentials); } var isPasswordCorrect = await _userManager.CheckPasswordAsync(user, model.Password); if (!isPasswordCorrect) { throw new ApiException(400, "Invalid password", ErrorCode.InvalidCredentials); } var token = await _tokenService.GenerateToken(user); var response = new { access_token = token, user = _mapper.Map <CurrentUserViewModel>(user) }; return(Json(response)); }
public async Task <IActionResult> ConfirmResettingPassword([FromBody] ConfirmResetPasswordModel model) { var user = await _accountService.ConfirmResetPassword(model); var token = await _tokenService.GenerateToken(user); var response = new { access_token = token, user = _mapper.Map <CurrentUserViewModel>(user) }; return(Json(response)); }