protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var isAuthorized = base.AuthorizeCore(httpContext);

            if (!isAuthorized)
            {
                return(false);
            }

            if (SF.UsePermissions())
            {
                if (!LS.CurrentUser.Roles.Contains("Admin") && SF.CheckAdminControlersPermissions(ControlerType) == false)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (!LS.CurrentUser.Roles.Contains("Admin"))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Exemplo n.º 2
0
        public static void AddToNewsletter(Newsletter item)
        {
            List <int> ListIDs = new List <int>();

            ListIDs.Add(103435);
            string ClientUser     = "******";
            string ClientPassword = "******";

            try
            {
                CustomerServiceSoapClient client = new CustomerServiceSoapClient();
                AuthHeader authHeader            = new AuthHeader();
                authHeader.Username = ClientUser;
                authHeader.Password = ClientPassword;
                authHeader.Token    = client.Login(authHeader);


                WebCustomer customer = new WebCustomer();
                customer.Email     = item.NewsletterEmail;
                customer.FirstName = item.NewsletterName;
                customer.Phone1    = item.NewsletterPhone;

                APIResponse response = client.ImportCustomer(authHeader, customer, ListIDs.ToArray(), new int[0]);
            }
            catch (Exception ex)
            {
                SF.LogError(ex);
            }
        }
        public static void SetLanguageCode(AbstractPage ap, int MaxTimes, string LanguageCode)
        {
            List <int> Pages = new List <int>();

            Pages.Add(ap.ID);
            SF.SetLanguageCodeRecurcive(ap, 100, Pages);
            string FormatedPagesIDs = string.Join(",", Pages);

            _db.Database.ExecuteSqlCommand(string.Format("Update AbstractPages Set LanguageCode = '{0}' Where DomainID = '{1}' And ID IN ({2})", LanguageCode, ap.DomainID, FormatedPagesIDs));
        }
        //public static string GetLangJS(string KendoUrl)
        //{
        //    return "<script src=\"" + VirtualPathUtility.ToAbsolute(KendoUrl + "/cultures/kendo.culture." + SF.GetLangCodeThreading() + ".min.js") + "\"></script><script> kendo.culture(\"" + SF.GetLangCodeThreading() + "\");</script>";
        //}

        public static bool AdminIsRTL()
        {
            string        LangCode = SF.GetLangCodeThreading();
            List <string> rltList  = new List <string>()
            {
                "he-IL"
            };

            if (rltList.Contains(LangCode))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static void Initialize(HttpContext context)
        {
            if (s_InitializedAlready)
            {
                return;
            }
            lock (s_lock)
            {
                if (s_InitializedAlready)
                {
                    return;
                }

                SF.CheckEnvironment();
                SF.PingHost();

                s_InitializedAlready = true;
            }
        }
Exemplo n.º 6
0
        public static bool UserCanView(User CurrentUser, AbstractPage CurrentPage)
        {
            List <string> CurrentUserPermissions = new List <string>();

            if (CurrentUser == null)
            {
                CurrentUserPermissions.Add("Anonymous");
            }
            else
            {
                CurrentUserPermissions = SF.RolesStringToList(CurrentUser.Roles);
            }

            List <string> CurrentPagePermissions = SF.RolesStringToList(CurrentPage.PermissionsView);

            if (CurrentUserPermissions.Intersect <string>(CurrentPagePermissions).Count() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static List <ImageGalleryItem> GalleryFile2List(string GalleryPath, int Width, int Height, bool ToCacheFile, bool ExactSize)
        {
            List <Uco.Models.ImageGalleryItem> allImages = new List <ImageGalleryItem>();

            //create directory if not exist
            if (!Directory.Exists(GalleryPath))
            {
                Directory.CreateDirectory(GalleryPath);
            }

            //get all files in directory
            string RootPath = LS.CurrentHttpContext.Server.MapPath("~");

            string[] AllFiles = Directory.GetFiles(LS.CurrentHttpContext.Server.UrlDecode(GalleryPath));

            //add images from directory to allImages
            for (int i = 0; i < AllFiles.Length; i++)
            {
                AllFiles[i] = AllFiles[i].Replace(RootPath, "");
                AllFiles[i] = AllFiles[i].Replace("\\", "/").ToLower();
                if (AllFiles[i].EndsWith(".jpg") || AllFiles[i].EndsWith(".png") || AllFiles[i].EndsWith(".gif") || AllFiles[i].EndsWith(".bmp"))
                {
                    Uco.Models.ImageGalleryItem newImage = new Uco.Models.ImageGalleryItem();
                    newImage.BigImageUrl   = "/" + AllFiles[i];
                    newImage.SmallImageUrl = SF.GetImageUrl("/" + AllFiles[i], Width, Height, ExactSize, ToCacheFile);
                    allImages.Add(newImage);
                }
            }

            //create info.txt in directory if not exist
            string GalleryFilePath = GalleryPath + "info.txt";

            if (!File.Exists(GalleryFilePath))
            {
                File.CreateText(GalleryFilePath).Close();
            }

            //read info.txt to allImages
            string GalleryFile = File.ReadAllText(GalleryFilePath);

            if (!string.IsNullOrEmpty(GalleryFile))
            {
                foreach (string item in GalleryFile.Split('\n'))
                {
                    if (string.IsNullOrEmpty(item))
                    {
                        continue;
                    }
                    string[] t = item.Split('^');
                    if (t.Length == 4)
                    {
                        Uco.Models.ImageGalleryItem n = allImages.FirstOrDefault(r => r.FileName == t[1]);
                        if (n != null)
                        {
                            n.Title = t[3];
                            int tempInt = 0;
                            int.TryParse(t[0], out tempInt);
                            if (tempInt == 0)
                            {
                                tempInt = 100;
                            }
                            n.Order = tempInt;
                        }
                    }
                }
            }

            return(allImages.OrderBy(r => r.Order).ToList());
        }
Exemplo n.º 8
0
 public static void CleanOutputCache()
 {
     LS.CurrentHttpContext.Application["LangCodeDomainAndCleanCacheGuid_" + System.Threading.Thread.CurrentThread.CurrentCulture.Name + "_" + SF.GetCurrentDomain()] = null;
 }
        private int Tokenize(string SystemName, string ToEmail, IList <object> models)
        {
            if (_isGetTokensOnly)
            {
                tokens = new List <string>();
                foreach (var o in models)
                {
                    if (o == null)
                    {
                        continue;
                    }

                    var t          = o.GetType();
                    var properties = t.GetProperties();
                    foreach (var p in properties)
                    {
                        tokens.Add(string.Format("%{0}.{1}%", t.Name, p.Name)); // %Order.Total% -> $345.34
                    }
                }
                return(0);
            }
            var LanguageCode = SF.GetLangCodeThreading();
            var mailTemplate = _Context.EntityContext.MessageTemplates.FirstOrDefault(x => x.SystemName == SystemName && x.LanguageCode == LanguageCode);

            if (mailTemplate != null && mailTemplate.Active && !string.IsNullOrEmpty(ToEmail))
            {
                StringBuilder Subject = new StringBuilder(mailTemplate.Subject);
                StringBuilder Body    = new StringBuilder(mailTemplate.Body);

                string log = "";
                if (mailTemplate.SystemName == "Order.UserCantPay.EmailToAdmin")
                {
                    log += @"LOG mail template data
";
                }
                foreach (var o in models)
                {
                    if (o == null)
                    {
                        continue;
                    }

                    var t          = o.GetType();
                    var properties = t.GetProperties();
                    foreach (var p in properties)
                    {
                        string repl  = "";
                        var    value = p.GetValue(o);
                        if (value != null)
                        {
                            repl = value.ToString();
                        }
                        if (mailTemplate.SystemName == "Order.UserCantPay.EmailToAdmin")
                        {
                            log += string.Format("{0}.{1}", t.Name, p.Name) + @" = " + repl + @"
";
                        }
                        Subject.Replace(string.Format("%{0}.{1}%", t.Name, p.Name), repl); // %Order.Total% -> $345.34
                        Body.Replace(string.Format("%{0}.{1}%", t.Name, p.Name), repl);    // %Order.Total% -> $345.34
                    }
                }
                if (mailTemplate.SystemName == "Order.UserCantPay.EmailToAdmin")
                {
                    log += @"
template Body:
" + mailTemplate.Body;
                    log += @"
template Subject:
" + mailTemplate.Subject;

                    log += @"
result Body:
" + Body.ToString();
                    log += @"
result Subject:
" + Subject.ToString();

                    var acitvitylog = new ActivityLog()
                    {
                        CreateOn     = DateTime.Now,
                        FullText     = log,
                        UserID       = Guid.Empty,
                        ActivityType = ActivityType.Other
                    };
                    _Context.EntityContext.ActivityLogs.Add(acitvitylog);
                    _Context.EntityContext.SaveChanges();
                }
                var email = new OutEmail()
                {
                    Body    = Body.ToString(),
                    Subject = Subject.ToString(),
                    MailTo  = ToEmail,
                };

                _Context.EntityContext.OutEmails.Add(email);
                _Context.EntityContext.SaveChanges();
                return(email.ID);
            }
            if (mailTemplate == null)
            {
                //add to log or create automatic
                var template = new MessageTemplate()
                {
                    Active       = false,
                    Body         = "Auto generated, please change",
                    LanguageCode = SF.GetLangCodeThreading(),
                    Subject      = "Auto generated",
                    SystemName   = SystemName
                };
                _Context.EntityContext.MessageTemplates.Add(template);
                _Context.EntityContext.SaveChanges();
            }
            return(0);
        }
        public static void PrepareReflection()
        {
            if (!SF.UsePlugins())
            {
                List <Type>  PageTypesRepository           = new List <Type>();
                List <Type>  AdminControlerTypesRepository = new List <Type>();
                List <ITask> TasksRepository = new List <ITask>();
                Dictionary <string, Type> PageTypesDictionaryReprository = new Dictionary <string, Type>();

                AppDomain currentDomain = AppDomain.CurrentDomain;
                Assembly  assembly      = currentDomain.GetAssemblies().Where(r => r.FullName.StartsWith("Uco,")).First();

                PageTypesRepository.AddRange(from t in assembly.GetTypes()
                                             where t.IsSubclassOf(typeof(AbstractPage))
                                             select t);

                AdminControlerTypesRepository.AddRange(from t in assembly.GetTypes()
                                                       where t.IsSubclassOf(typeof(BaseAdminController))
                                                       select t);

                var instances = from t in assembly.GetTypes()
                                where t.GetInterfaces().Contains(typeof(ITask)) && t.GetConstructor(Type.EmptyTypes) != null
                                select Activator.CreateInstance(t) as ITask;

                if (SF.UseTasks())
                {
                    TasksRepository.AddRange(instances);
                }
                foreach (Type t in PageTypesRepository)
                {
                    System.Attribute[] attrs = System.Attribute.GetCustomAttributes(t);
                    foreach (System.Attribute attr in attrs)
                    {
                        if (attr is RouteUrlAttribute)
                        {
                            RouteUrlAttribute a = (RouteUrlAttribute)attr;
                            PageTypesDictionaryReprository.Add(a.RouteUrl, t);
                        }
                    }
                }

                LS.Cache["PageTypesRepository"]           = PageTypesRepository;
                LS.Cache["AdminControlerTypesRepository"] = AdminControlerTypesRepository;
                LS.Cache["TasksRepository"] = TasksRepository;
                LS.Cache["PageTypesDictionaryReprository"] = PageTypesDictionaryReprository;
            }
            else
            {
                LS.Cache["PageTypesRepository"]           = new List <Type>();;
                LS.Cache["AdminControlerTypesRepository"] = new List <Type>();;
                LS.Cache["TasksRepository"] = new List <ITask>();
                LS.Cache["PageTypesDictionaryReprository"] = new Dictionary <string, Type>();
            }


            //Dictionary<string, Type> dictionary = new Dictionary<string, Type>();

            //using (AssemblyLocator al = new AssemblyLocator())
            //{
            //    ReadOnlyCollection<Assembly> UcoAssemblies = al.GetUcoAssemblies();
            //    foreach (Assembly item1 in UcoAssemblies)
            //    {
            //        foreach (Type item2 in item1.GetTypes().Where(r => r.IsSubclassOf(typeof(AbstractPage))).ToList())
            //        {
            //            System.Attribute[] attrs = System.Attribute.GetCustomAttributes(item2);
            //            foreach (System.Attribute attr in attrs)
            //            {
            //                if (attr is RouteUrlAttribute)
            //                {
            //                    RouteUrlAttribute a = (RouteUrlAttribute)attr;
            //                    dictionary.Add(a.RouteUrl, item2);
            //                }
            //            }
            //        }
            //    }
            //}

            //LS.Cache[Token] = dictionary;
            //return dictionary;



            //List<ITask> l = new List<ITask>();
            //foreach (var assembly in RP.GetUcoAssemblyReprository())
            //{
            //    var instances = from t in assembly.GetTypes()
            //                    where t.GetInterfaces().Contains(typeof(ITask))
            //                             && t.GetConstructor(Type.EmptyTypes) != null
            //                    select Activator.CreateInstance(t) as ITask;
            //    if (assembly.GetName().Name == "Uco" || RP.GetPluginsReprository().Contains(assembly.GetName().Name))
            //    {
            //        l.AddRange(instances);
            //    }
            //}

            //LS.Cache[Token] = l;
            //return l;
        }