예제 #1
0
 public ManagerSiteContext(HttpContext httpContext, CustomPrincipal user)
     : base(httpContext, user)
 {
 }
예제 #2
0
 public ClientSiteContext(HttpContext httpContext, CustomPrincipal user)
     : base(httpContext, user)
 {
 }
예제 #3
0
 private ShoppingCart CreateShoppingCart(CustomPrincipal user, ClientProfile profile)
 {
     var cart = new ShoppingCart( user.UserId, user.AcctgID, profile.ClientGroup, profile.PersonalMarkup );
     cart.ContentChanged += OnCartContentChanged;
     return cart;
 }
예제 #4
0
        public static void FormsAuthentication_OnAuthenticate(
            object sender,
            FormsAuthenticationEventArgs args)
        {
            if (FormsAuthentication.CookiesSupported)
            {
                HttpRequest request = HttpContext.Current.Request;
                if (request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
                       request.Cookies[FormsAuthentication.FormsCookieName].Value);

                    string[] parts = ticket.UserData.Split(';');

                    int userId = int.Parse(parts[0]);
                    string acctgId = parts[1];
                    byte bRole = byte.Parse(parts[2]);
                    string  internalFranchName = parts[3];

                    if (!Enum.IsDefined(typeof(SecurityRole), bRole))
                        throw new Exception("Incorrect Users.UserRole value");

                    //
                    if (HttpContext.Current.Request.Cookies["InternalFranchName"] == null || HttpContext.Current.Request.Cookies["InternalFranchName"].Value != internalFranchName)
                    {
                        //SiteContext._internalFranchName = internalFranchName;
                        HttpCookie coockie = new HttpCookie("InternalFranchName");
                        coockie.Domain = "rmsauto.ru";
                        coockie.Path = "/";
                        coockie.Value = HttpUtility.HtmlEncode(internalFranchName);
                        HttpContext.Current.Request.Cookies.Add(coockie);
                        HttpContext.Current.Response.Cookies.Add(coockie);

                        HttpCookie CityNamecoockie = new HttpCookie("cityName");
                        CityNamecoockie.Domain = "rmsauto.ru";
                        CityNamecoockie.Path = "/";
                        IEnumerable<City> cities;
                        using (var dcCommon = new RmsAuto.Store.Entities.dcCommonDataContext())
                        {
                                //Извлекаем наборы данных в списки, так как LINQ to SQL не дает выполнять запросы к различным контекстам
                                //TODO: сделать AcctgRefCatalog.Cities, вынести в справочник, чтобы не лезть в базу каждый раз
                                cities = dcCommon.Cities.Select(x => x).ToList();
                        }
                        //var regionId = AcctgRefCatalog.RmsFranches[(string)context.Request.QueryString[UrlKeys.Activation.FranchCode]].RegionID;
                        var regionId = AcctgRefCatalog.RmsFranches[internalFranchName].RegionID;
                        CityNamecoockie.Value = HttpUtility.UrlEncodeUnicode(cities.Where(x => x.CityID == regionId).Select(x => x.Name).FirstOrDefault());
                        HttpContext.Current.Request.Cookies.Add(CityNamecoockie);
                        HttpContext.Current.Response.Cookies.Add(CityNamecoockie);
                    }

                    SecurityRole role = (SecurityRole)bRole;
                    var user = new CustomPrincipal(
                          new FormsIdentity(ticket),
                          new string[] { role.ToString() },
                          userId,
                          acctgId,
                          role, internalFranchName);
                    args.User = user;
                }
            }
            else
            {
                //DO NOTHING
                //throw new HttpException( "Cookieless Forms Authentication is not " +
                //                        "supported for this application." );
            }
        }