public async Task<ActionResult> Login(LogOnFormModel form, string returnUrl) { if (ModelState.IsValid) { var user = this.userRepository.Get(x => x.Email.ToUpper() == form.Email.ToUpper() && Md5Encrypt.Md5EncryptPassword(form.Password) == x.PasswordHash); if (user != null) { FNHMVCUser appUser = new FNHMVCUser(user); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = true, RedirectUri = returnUrl }, await appUser.GenerateUserIdentityAsync(userManager)); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } return View(form); }
public JsonResult JsonLogin(LogOnFormModel form, string returnUrl) { if (ModelState.IsValid) { User user = userRepository.Get(u => u.Email == form.UserName && u.Activated == true); if (user != null) { if (ValidatePassword(user, form.Password)) { formAuthentication.SetAuthCookie(this.HttpContext, UserAuthenticationTicketBuilder.CreateAuthenticationTicket(user)); return Json(new { success = true, redirect = returnUrl }); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } } // If we got this far, something failed return Json(new { errors = GetErrorsFromModelState() }); }