Пример #1
0
        /// <summary>
        /// Login the session if possible
        /// </summary>
        public void Execute()
        {
            NameValueCollection queryString = requestWrapper.QueryString;

            string amplaSession = queryString["amplaSession"];

            if (!string.IsNullOrEmpty(amplaSession))
            {
                if (amplaUserService != null)
                {
                    string    message;
                    AmplaUser amplaUser = amplaUserService.SessionLogin(amplaSession, out message);
                    if (amplaUser != null)
                    {
                        formsAuthenticationService.StoreUserTicket(amplaUser, false);
                        amplaSessionStorage.SetAmplaSession(amplaUser.Session);

                        UriBuilder builder = new UriBuilder(requestWrapper.Url);
                        var        query   = HttpUtility.ParseQueryString(builder.Query);
                        query.Remove("amplaSession");
                        builder.Query = query.ToString();
                        responseWrapper.Redirect(builder.ToString());
                    }
                }
            }
        }
Пример #2
0
        public ActionResult LoginIntegrated(string returnUrl)
        {
            IntegratedLoginModel model = new IntegratedLoginModel {
                UseIntegratedSecurity = true
            };

            if (ModelState.IsValid)
            {
                string message;
                if (!model.UseIntegratedSecurity)
                {
                    return(RedirectToAction("Login"));
                }

                AmplaUser amplaUser = amplaUserService.IntegratedLogin(out message);
                if (amplaUser != null)
                {
                    amplaSessionStorage.SetAmplaSession(amplaUser.Session);
                    formsAuthenticationService.StoreUserTicket(amplaUser, model.RememberMe);

                    if (UrlIsLocal(returnUrl))
                    {
                        Information("Login successful.");
                        return(Redirect(returnUrl));
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                Error(message);
                ModelState.AddModelError("", message);
            }

            // If we got this far, something failed, redisplay form
            return(View("Login"));
        }
Пример #3
0
        public ActionResult Login(SimpleLoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                string    message;
                AmplaUser amplaUser = amplaUserService.SimpleLogin(model.UserName, model.Password, out message);
                if (amplaUser != null)
                {
                    amplaSessionStorage.SetAmplaSession(amplaUser.Session);

                    formsAuthenticationService.StoreUserTicket(amplaUser, model.RememberMe);

                    if (UrlIsLocal(returnUrl))
                    {
                        Information("Login successful.");
                        return(Redirect(returnUrl));
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                Error(message);
                ModelState.AddModelError("", message);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #4
0
        /// <summary>
        /// Stores the user ticket.
        /// </summary>
        /// <param name="amplaUser">The ampla user.</param>
        /// <param name="createPersistentCookie">if set to <c>true</c> [create persistent cookie].</param>
        public void StoreUserTicket(AmplaUser amplaUser, bool createPersistentCookie)
        {
            string session = amplaUser.Session;

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, amplaUser.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), createPersistentCookie, session);

            response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)));
        }
Пример #5
0
        public void SessionStorageIsSetFromForms()
        {
            securityWebService.AddExistingSession("User");
            string    session = securityWebService.Sessions[0].SessionId;
            string    message;
            AmplaUser user = amplaUserService.SessionLogin(session, out message);

            Assert.That(user, Is.Not.Null);
            FormsAuthenticationService.StoreUserTicket(user, false);

            context.Response.Redirect("http://localhost/Production");

            Assert.That(AmplaSessionStorage.GetAmplaSession(), Is.Empty);
            new AlignSessionWithFormsAuthentication(context.Request, AmplaSessionStorage, FormsAuthenticationService).Execute();

            Assert.That(AmplaSessionStorage.GetAmplaSession(), Is.EqualTo(session));
        }
Пример #6
0
        public void DisabledSessionStorageDoesntThrow()
        {
            context = context.WithSessionsDisabled();
            Assert.That(context.Session.Enabled, Is.False);

            securityWebService.AddExistingSession("User");
            string    session = securityWebService.Sessions[0].SessionId;
            string    message;
            AmplaUser user = amplaUserService.SessionLogin(session, out message);

            Assert.That(user, Is.Not.Null);
            FormsAuthenticationService.StoreUserTicket(user, false);

            context.Response.Redirect("http://localhost/Production");

            new AlignSessionWithFormsAuthentication(context.Request, AmplaSessionStorage, FormsAuthenticationService).Execute();

            Assert.That(AmplaSessionStorage.GetAmplaSession(), Is.Empty);
        }
Пример #7
0
        public ActionResult CurrentUser()
        {
            string session = amplaSessionStorage.GetAmplaSession();

            AmplaUser user = amplaUserService.RenewSession(session);

            if (user == null)
            {
                return(RedirectToAction("Login"));
            }

            UserModel model = new UserModel
            {
                UserName     = user.UserName,
                Session      = user.Session,
                Started      = user.LoginTime,
                LastActivity = user.LastActivity,
                LoginType    = user.LoginType
            };

            return(View("CurrentUser", model));
        }