public void SaveCookie(string name, DateTime?expires)
 {
     try
     {
         if (ToString() == originalCookieValue && WasEncrypted == StormContext.Configuration.EncryptCookie)
         {
             return;
         }
         var data   = Encrypt();
         var cookie = new HttpCookie(name, data);
         if (StormContext.IsSsl)
         {
             cookie.HttpOnly = true;
             cookie.Secure   = true;
         }
         if (expires.HasValue)
         {
             if (expires.Value > DateTime.Now.AddYears(1))
             {
                 expires = DateTime.Now.AddYears(1);
             }
             cookie.Expires = expires.Value;
         }
         StormContext.AddCookie(cookie);
         originalCookieValue = ToString(); // Avoid saving the same cookie twice
         Log.LogEntry.Categories(CategoryFlags.Debug).Message("Saved cookie {0}: {1}", name, data).WriteVerbose();
     }
     catch { }
 }
Пример #2
0
        public override bool ValidateUser(string loginName, string password)
        {
            if (string.IsNullOrWhiteSpace(loginName))
            {
                return(false);
            }

            try
            {
                var customer = repository.Login(loginName, password);
                if (customer != null)
                {
                    StormContext.LoginUser(loginName);
                }
                return(customer != null);
            }
            catch (FaultException <ErrorMessage> ex)
            {
                if (ex.Message == "Bad Request")
                {
                    return(false);
                }
                throw;
            }
        }
        public void LoadCookie(string name)
        {
            var cookie = StormContext.GetCookie(name);

            if (cookie != null)
            {
                WasEncrypted = IsEncrypted(cookie.Value);
                var data = Decrypt(cookie);
                Log.LogEntry.Categories(CategoryFlags.Debug).Message("Loaded cookie {0}: {1}", name, data).WriteVerbose();
            }
            StormContext.SetItem(name, this);
            originalCookieValue = ToString();
        }
 public void EndRequest(object source, EventArgs e)
 {
     if (!IsRealPage)
     {
         return;
     }
     if (StormContext.IsInitialRequest && HttpContext.Current.Response.RedirectLocation == null)
     {
         StormContext.IsInitialRequest = false;
         StormContext.Refresh();
     }
     StormContext.SaveCookie();
 }
 public void BeginRequest(object source, EventArgs e)
 {
     if (!IsRealPage)
     {
         return;
     }
     StormContext.LoadCookie();
     if (HttpContext.Current != null)
     {
         SetReferUrl();
         SetReferId();
     }
     if (StormContext.IsInitialRequest && !StormContext.RememberMe)
     {
         StormContext.LogoutUser();
     }
 }