public async Task <MessageApiModel> ConfirmMailBaseAsync(ConfirmApiModel model) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { throw new BadRequestException(_resourceManager.GetString("UserDoesNotExist")); } if (user != null && user.IsDeleted == true) { throw new UserIsDeletedException(_resourceManager.GetString("UserIsDeleted")); } if (user.EmailConfirmed) { throw new ArgumentException(_resourceManager.GetString("EmailAlreadyConfirmed")); } var confirmResult = await _userManager.ConfirmEmailAsync(user, model.Token); if (!confirmResult.Succeeded) { throw new BadRequestException(confirmResult.Errors.First().Description); } return(new MessageApiModel { Message = _resourceManager.GetString("EmailConfirmSucceeded") }); }
public async Task <IActionResult> ConfirmEmailBase([FromBody] ConfirmApiModel model) { var validator = new EmailValidator(_recaptcha, _resourceManager); var validResult = validator.Validate(new EmailApiModel { Email = model.Email, RecaptchaToken = model.RecaptchaToken }); if (!validResult.IsValid) { return(BadRequest(new MessageApiModel() { Message = validResult.ToString() })); } var result = await _accountService.ConfirmMailBaseAsync(model); return(Ok(result)); }