Пример #1
0
        public ActionResult Login(RegisterVM user)
        {
            var mediator = new AccountMediator();

            var isAuthenticated = mediator.Authenticate(user);

            if (isAuthenticated)
            {
                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, user.Email, DateTime.Now, DateTime.Now.AddMinutes(30), false, "");
                string CookieContents = FormsAuthentication.Encrypt(authTicket);
                var    cookie         = new HttpCookie(FormsAuthentication.FormsCookieName, CookieContents)
                {
                    Path = FormsAuthentication.FormsCookiePath
                };
                if (HttpContext.Response != null)
                {
                    HttpContext.Response.Cookies.Add(cookie);
                }

                return(Redirect("/admin/eventList"));
            }
            else
            {
                ModelState.AddModelError("ErrorMessage", "Invalid credentials");
            }
            return(PartialView(user));
        }
Пример #2
0
        public ActionResult Register(RegisterVM user)
        {
            var mediator = new AccountMediator();

            if (user.Password != user.VerifyPassword)
            {
                ModelState.AddModelError("ErrorMessage", "Passwords don't match");
            }
            else if (ModelState.IsValid)
            {
                bool success = mediator.RegisterUser(user);

                if (success)
                {
                    return(Redirect("/account/login"));
                }
                else
                {
                    ModelState.AddModelError("ErrorMessage", "Unable to create account");
                }
            }
            return(PartialView(user));
        }