Beispiel #1
0
        private void AfterLogin(UserIdentity user)
        {
            CurrentUserContext.Initilize(user);

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(user.Email, this.cbxRemember.Checked, 24 * 60);

            // Encrypt the ticket.
            string encTicket = FormsAuthentication.Encrypt(ticket);

            // Create the cookie.
            HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

            RedirectAferValidate();
        }
        public ActionResult SignIn(SignInViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                UserIdentity user = Service.Authenticate(model.Email, EncryptionHelper.Encrypt(model.Password));

                if (user != null)
                {
                    CurrentUserContext.Initilize(user);

                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(user.Email, model.RememberMe, 24 * 60);

                    // Encrypt the ticket.
                    string encTicket = FormsAuthentication.Encrypt(ticket);

                    // Create the cookie.
                    System.Web.HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction(FolderController.IndexAction, FolderController.ControllerName));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            model.CurrentLanguage = CurrentLanguage;
            return(View(model));
        }