public async Task <IActionResult> ConfirmEmail(EmailConfirmModel model) { var user = await _accountRepository.GetUserByEmailAsync(model.Email); if (user != null) { if (user.EmailConfirmed) { model.EmailVerify = true; return(View(model)); } await _accountRepository.GenerateEmailConfirmationTonkenAsync(user); model.EmailSent = true; ModelState.Clear(); } else { ModelState.AddModelError("", "Something went wrong."); } return(View(model)); }
public async Task <ResultModel> ConfirmEmail([FromBody] EmailConfirmModel model) { var ret = new ResultModel { IsSucceeded = true }; var user = await _userManager.GetUserAsync(User); if (user != null) { var result = await _userManager.ConfirmEmailAsync(user, model.Token); if (!result.Succeeded) { ret.IsSucceeded = false; ret.ErrorMessage = result.Errors.Any() ? result.Errors.Select(i => i.Description).Aggregate((accu, next) => accu + "\n" + next) : "注册失败"; } return(ret); } else { ret.IsSucceeded = false; ret.ErrorMessage = "找不到该用户"; } return(ret); }
public async Task <IActionResult> ConfirmEmail(EmailConfirmModel model) { if (ModelState.IsValid) { ApplicationUser user = await _accountRepository.GetUserByEmailAsync(model.Email); if (user != null) { if (user.EmailConfirmed) { model.IsConfirmed = true; return(View(model)); } await _accountRepository.GenerateEmailConfirmationTokenAsync(user); model.EmailSent = true; ModelState.Clear(); } else { ModelState.AddModelError("", "Something Went Wrong"); } } return(View(model)); }
public async Task <IActionResult> ConfirmAsync(EmailConfirmModel model) { var user = new ApplicationUser { Id = model.UserId }; var result = await _userManager.ConfirmEmailAsync(user, model.Token); _logger.LogInformation($"User email confirm request. Email: {model.UserId}. Status {result.Succeeded}"); return(result.Succeeded ? (IActionResult)Ok() : BadRequest(result.Errors.First().Description)); }
public async Task <IActionResult> ConfirmEmail(String uid, String token, String email) { EmailConfirmModel emailConfirmModel = new EmailConfirmModel { Email = email }; if (!String.IsNullOrEmpty(uid) && !String.IsNullOrEmpty(token)) { token = token.Replace(' ', '+'); var result = await _accountRepository.ConfirmEmailAsync(uid, token); if (result.Succeeded) { emailConfirmModel.EmailVerified = true; } } return(View(emailConfirmModel)); }
public async Task <IActionResult> ConfirmEmail(string uid, string token, string email) { EmailConfirmModel model = new EmailConfirmModel() { Email = email }; if (!string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(token)) { token = token.Replace(' ', '+'); var result = await _accountRepository.ConfirmEmailAsync(uid, token); if (result.Succeeded) { // ViewBag.IsSuccess = true; model.EmailVerify = true; } } return(View(model)); }
public async Task <IActionResult> ConfirmEmail(EmailConfirmModel model) { var user = await _accountRepository.GetUserByEmailId(model.Email); if (user != null) { if (user.EmailConfirmed) { model.EmailVerified = true; return(View(model)); } await _accountRepository.GenerateTokenToConfirmEmailAsync(user); model.EmailSent = true; ModelState.Clear(); } else { ModelState.AddModelError("", "User is not found with this specific ID"); } return(View(model)); }
public async Task <IActionResult> ConfirmEmail(EmailConfirmModel model) { var user = await _compteRepository.GetUserByEmailAsync(model.Email); if (user != null) { if (user.EmailConfirmed) { model.EmailVerifie = true; return(View(model)); } await _compteRepository.GenerateEmailConfirmationTokenAsync(user); model.EmailEnvoye = true; ModelState.Clear(); } else { ModelState.AddModelError("", "Quelque chose ne marche pas"); } return(View()); }
public async Task <IActionResult> ConfirmEmail(string uid, string token, string email) { EmailConfirmModel model = new EmailConfirmModel { Email = email }; if (!string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(token)) { token = token.Replace(' ', '+'); var result = await _accountRepository.ConfirmEmailAsync(uid, token); if (result.Succeeded) { model.EmailVerified = true; } } /*if(uid==null || token == null) * { * return RedirectToAction("index", "home"); * }*/ return(View(model)); }
public async Task <IActionResult> VerifyEmail(EmailConfirmModel model) { ViewData["ButtonID"] = ButtonID.VerifyEmail; if (!ModelState.IsValid) { return(View()); } // Verify that the user exists with the specified email. ApplicationUser user = await _accountRepository.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError(string.Empty, $"We could not find user: {model.Email}."); ModelState.AddModelError(string.Empty, "If you are verifying a new email then put your older one instead."); return(View()); } bool newEmail = !string.IsNullOrWhiteSpace(user.UnverifiedNewEmail); if (user.EmailConfirmed && !newEmail) { model.IsConfirmed = true; ModelState.AddModelError(string.Empty, "Account already verified."); return(View(model)); } if (!await _captcha.IsCaptchaValidAsync()) { ModelState.AddModelError(_captcha.CaptchaValidationError().Key, _captcha.CaptchaValidationError().Value); return(View()); } if (!await _timeoutsRepository.CanRequestEmailResendVerifyAsync(user.Id)) { ModelState.AddModelError(string.Empty, "Please wait some time before requesting an email resend."); return(View()); } if (newEmail) { _logger.LogInformation($"{user.Id} ({user.UserName}) - Generated a new email confirmation token."); await _accountRepository.GenerateNewEmailConfirmationTokenAsync(user, new DeviceParser(GetClientUserAgent(), GetRemoteClientIPv4())); } else { _logger.LogInformation($"{user.Id} ({user.UserName}) - Generated a email confirmation token."); // Generate a token as well as a user agent. await _accountRepository.GenerateEmailConfirmationTokenAsync(user, new DeviceParser(GetClientUserAgent(), GetRemoteClientIPv4())); } // Indicate to the View that the email was sent. model.IsEmailSent = true; // Clear all fields. ModelState.Clear(); await _captcha.CacheNewCaptchaValidateAsync(); await _timeoutsRepository.UpdateRequestAsync(user.Id, UserRequest.RequestVerificationEmail); return(View(model)); }