public async Task <IActionResult> EmailConfirmEmail([FromBody] EmailConfirmEmailRequest request) { if (request == null) { return(BadRequest( new AuthFailedResponse { Errors = new List <string>() { "Empty Request." } } )); } DragonflyUser user; if (HttpContext.User.Identity.IsAuthenticated) { var userId = HttpContext.GetUserId(); user = await _userService.GetUserByIdAsync(userId).ConfigureAwait(false); if (user != null && ((!string.IsNullOrEmpty(request.Email) && user.Email != request.Email) || (!string.IsNullOrEmpty(request.UserName) && user.UserName != request.UserName))) { return(BadRequest( new AuthFailedResponse { Errors = new List <string>() { "Mismatched user data." } } )); } } else if (!string.IsNullOrEmpty(request.UserName)) { user = await _userService.GetUserByUserNameAsync(request.UserName).ConfigureAwait(false); } else if (!string.IsNullOrEmpty(request.Email)) { user = await _userService.GetUserByEmailAsync(request.Email).ConfigureAwait(false); } else { return(BadRequest( new AuthFailedResponse { Errors = new List <string>() { "No user data included." } } )); } if (user == null) { return(BadRequest( new AuthFailedResponse { Errors = new List <string>() { "Could not find user." } } )); } var sentResult = await _identityService.SendConfirmationEmailAsync(user).ConfigureAwait(false); if (!sentResult.Success) { return(BadRequest( new AuthFailedResponse { Errors = sentResult.Errors })); } return(Ok( new AuthenticationResult { Success = true })); }
public async Task <IActionResult> EmailConfirmEmail([FromBody] EmailConfirmEmailRequest request) { if (request == null) { return(BadRequest(new BaseResponse <string> { Errors = new List <string>() { "Empty Request." }, Success = false, })); } AppUser user; if (HttpContext.User.Identity.IsAuthenticated) { var username = _userManager.GetUserId(HttpContext.User); user = await _userManager.FindByNameAsync(username); if (user != null && ((!string.IsNullOrEmpty(request.Email) && user.Email != request.Email) || (!string.IsNullOrEmpty(request.UserName) && user.UserName != request.UserName))) { return(BadRequest(new BaseResponse <string> { Errors = new List <string>() { "Mismatched user data." }, Success = false, })); } } else if (!string.IsNullOrEmpty(request.UserName)) { user = await _userManager.FindByNameAsync(request.UserName); } else if (!string.IsNullOrEmpty(request.Email)) { user = await _userManager.FindByEmailAsync(request.Email); } else { return(BadRequest(new BaseResponse <string> { Errors = new List <string>() { "No user data included." }, Success = false, })); } if (user == null) { return(BadRequest(new BaseResponse <string> { Errors = new List <string>() { "Could not find user." }, Success = false, })); } var sentResult = await _accountService.SendConfirmationEmailAsync(user); if (!sentResult.Success) { return(BadRequest(new BaseResponse <string> { Errors = sentResult.Errors, Success = false, })); } return(Ok(new BaseResponse <string> { Success = true, })); }