Example #1
0
        public ActionResult Login(LoginModel model, string ReturnUrl)
        {
            if (ModelState.IsValid)
            {
                if (auth.Authenticate(model.Username, model.Password))
                {
                    //Session["username"] = model.Username;

                    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                        1,
                        model.Username,  //user id
                        DateTime.Now,
                        DateTime.Now.AddMinutes(60),  // expiry
                        false,  //do not remember
                        "/");
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                                                       FormsAuthentication.Encrypt(authTicket))
                                                       {
                                                           HttpOnly = true,
                                                           Expires = authTicket.Expiration
                                                       };
                    //Response.Cookies.Add(cookie);
                    Response.SetCookie(cookie);
                    //redirect ke halaman sebelumnya
                    if (ReturnUrl != null)
                        return Redirect(ReturnUrl);
                    else
                        return RedirectToAction("Index", "Dashboard");
                }
                else
                {
                    ModelState.AddModelError("", auth.Message);
                };
            }
            return View();
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            ModelState.AddModelError("", "Имя пользователя или пароль указаны неверно.");
            return View(model);
        }
        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);
        }