Ejemplo n.º 1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            var user = _userRepo.GetUser(model.UserName, PasswordUtility.HashPassword(model.Password));
            if (user == null)
            {
                ModelState.AddModelError("PasswordUsernameError", "Invalid Username or Password!");
                return View(model);
            }

            ApplicationSecurity.AddAuthenticationCookie(user.UserName, ((UserRole)user.Role).ToString(), model.RememberMe);
            ActionLogger.Log("Login", model.UserName);

            return RedirectToAction("Index", "Home");
        }