public ActionResult VerifyEmailCode(VerifyEmailCodeViewModel inModel) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return View(inModel); } RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); return View(inModel); } try { var user = _ctx.UserProfiles.Find(inModel.UserId); if (user.isVerified == true) { ModelState.AddModelError("", "This account has already been verified"); return View(inModel); } if (Membership.ValidateUser(inModel.UserName, inModel.Password) && user.isVerified == false) { user.isVerified = true; _ctx.SaveChanges(); WebSecurity.Login(inModel.UserName, inModel.Password); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "The user name and password do not match"); return View(inModel); } } catch { ModelState.AddModelError("", "The user name and password do not match the account does not exist"); return View(inModel); } }
public ActionResult VerifyEmailCode(string token) { var userId = WebSecurity.GetUserIdFromPasswordResetToken(token); var user = _ctx.UserProfiles.Find(userId); if (user.isVerified == true) { return View("Error"); } if (userId > 0) { var outModel = new VerifyEmailCodeViewModel { UserId = userId, Token = token }; return View(outModel); } else { return View("Error"); } }