Пример #1
0
        public ActionResult Login(LoginUserCommand command)
        {
            var client = new ExecutorServiceClient();
            var result = client.LoginUser(command);

            if (result != null)
            {
                var role      = client.GetRoleName(result.Id);
                var ticket    = new FormsAuthenticationTicket(1, result.Email, DateTime.Now, DateTime.Now.AddSeconds(525600), true, role);
                var encrypted = FormsAuthentication.Encrypt(ticket);
                var cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                cookie.Expires  = DateTime.Now.AddMinutes(525600);
                cookie.HttpOnly = true;
                Response.Cookies.Add(cookie);

                return(RedirectToAction("Listing"));
            }

            Session["CurrentUser"] = result;

            return(RedirectToAction("Login"));
        }