public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This needs to be tested to see if it actually encodes the data for preventing XSS attacks. model.Email = Encoder.HtmlEncode(model.Email); model.Password = Encoder.HtmlEncode(model.Password); // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); if (MvcCaptcha.IsCaptchaSolved("CustomCaptcha")) { // Use this to reset the captcha after the submit button has been pressed... This may need to be moved to the SignInStatus.Success case. MvcCaptcha.ResetCaptcha("CustomCaptcha"); switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } } else { // Use this to reset the captcha after the submit button has been pressed... This may need to be moved to the SignInStatus.Success case. MvcCaptcha.ResetCaptcha("CustomCaptcha"); ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public ActionResult Registration(RegistrationFormModel form) { if (MvcCaptcha.IsCaptchaSolved("SampleCaptcha") && form.IsUserAgree && form.Password == form.ConfirmPassword && !db.Users.Any(x => x.Email == form.Email)) { var user = new Users() { Name = form.Name, Phone = form.Phones, Email = form.Email, Notifications = Convert.ToInt32(form.IsNotitifcationAssigned), Password = form.Password, CCode = Int32.Parse(form.City) }; db.Users.Add(user); db.SaveChanges(); Session["CurrentUser"] = user; return(RedirectToAction("Index", "Home")); } else { return(Registration()); } }