Ejemplo n.º 1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                model.Username = model.Username.Trim();
                var user = _userService.ValidateUser(model.Username, model.Password);
                if (user == null)
                {
                    ModelState.AddModelError("", "Username or password is wrong, try again !");
                    return(View(model));
                }
                if (model.RememberMe)
                {
                    _cookieWrapper.RememberMe = model.Username;
                }

                _sessionWrapper.StartSession(user.Id, user.Username, user.Email);

                if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                {
                    return(RedirectToAction("Index", "Home"));
                }

                return(Redirect(returnUrl));
            }
            return(View(model));
        }