Exemplo n.º 1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.Login, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.Login, model.RememberMe);

                    User user = Manager.GetUserByLogin(model.Login);

                    UserData userData = new UserData
                    {
                        ID = user.UserId,
                        FullName = user.FullName,
                        Roles = user.Roles
                    };

                    //Nadpisuje cookie dla przechowywania dodatkowych informacji
                    Response.SetAuthCookie(model.Login, model.RememberMe, userData);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid login or password!");
                }
            }

            return View(model);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Logowanie usera
        /// </summary>
        /// <returns></returns>
        public ActionResult LogOn()
        {
            LogOnModel model = new LogOnModel();

            return View(model);
        }