Ejemplo n.º 1
0
        public IHttpActionResult DeleteFile(int siteId, int formId)
        {
            try
            {
                var request     = Context.AuthenticatedRequest;
                var fieldId     = request.GetQueryInt("fieldId");
                var uploadToken = request.GetQueryString("uploadToken");

                var cacheKey  = GetUploadTokenCacheKey(formId);
                var cacheList = CacheUtils.Get <List <string> >(cacheKey) ?? new List <string>();
                if (!cacheList.Contains(uploadToken))
                {
                    return(Unauthorized());
                }

                var fieldInfo = FieldManager.GetFieldInfo(formId, fieldId);
                if (fieldInfo.FieldType != InputType.Image.Value)
                {
                    return(Unauthorized());
                }

                return(Ok(new
                {
                    Value = string.Empty,
                    FieldId = fieldId
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public static SessionalUser GetUser(this ISession sess)
        {
            string        cacheKey = GetUserCacheKey(sess);
            SessionalUser r        = CacheUtils.Get <SessionalUser>(cacheKey);

            if (null != r)
            {
                return(r);
            }
            string s = sess.GetString(_userIdKey);

            if (String.IsNullOrEmpty(s))
            {
                return(null);
            }

            var setting = new JsonSerializerSettings();

            setting.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
            setting.ReferenceLoopHandling      = ReferenceLoopHandling.Serialize;
            r = JsonConvert.DeserializeObject <SessionalUser>(s, setting);
            if (null == r || r.Id <= 0)
            {
                return(null);
            }

            CacheUtils.Set(cacheKey, r);
            return(r);
        }
Ejemplo n.º 3
0
        public static string GetTemplateHtml(string theme)
        {
            var htmlPath = Main.Instance.PluginApi.GetPluginPath($"themes/{theme}/template.html");
            var themeUrl = Main.Instance.PluginApi.GetPluginUrl($"themes/{theme}");

            var html = CacheUtils.Get <string>(htmlPath);

            if (html != null)
            {
                return(html);
            }

            html = Utils.ReadText(htmlPath);
            var startIndex = html.IndexOf("<!-- template start -->", StringComparison.Ordinal) + "<!-- template start -->".Length;
            var length     = html.IndexOf("<!-- template end -->", StringComparison.Ordinal) - startIndex;

            html = html.Substring(startIndex, length);

            html = $@"
<link rel=""stylesheet"" type=""text/css"" href=""{themeUrl}/style.css"" />
{html}";

            CacheUtils.InsertHours(htmlPath, html, 3);
            return(html);
        }
Ejemplo n.º 4
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            PageUtils.CheckRequestParameter("siteId");

            if (IsPostBack)
            {
                return;
            }
            VerifySitePermissions(ConfigManager.WebSitePermissions.Template);

            TemplateTypeUtils.AddListItems(DdlTemplateType);
            ChannelManager.AddListItems(DdlChannelId.Items, SiteInfo, false, true, AuthRequest.AdminPermissionsImpl);
            if (AuthRequest.IsQueryExists("fromCache"))
            {
                TbTemplate.Text = TranslateUtils.DecryptStringBySecretKey(CacheUtils.Get <string>("SiteServer.BackgroundPages.Cms.PageTemplatePreview"));
            }

            if (AuthRequest.IsQueryExists("returnUrl"))
            {
                BtnReturn.Visible = true;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取计算机的硬盘序列号
        /// </summary>
        /// <returns>计算机的硬盘序列号</returns>
        public static string GetColumnSerialNumber()
        {
            var columnSerialNumber = CacheUtils.Get("ComputerUtils_ColumnSerialNumber") as String;

            if (string.IsNullOrEmpty(columnSerialNumber))
            {
                columnSerialNumber = string.Empty;
                try
                {
                    var mcHD  = new ManagementClass("win32_logicaldisk");
                    var mocHD = mcHD.GetInstances();
                    foreach (ManagementObject m in mocHD)
                    {
                        if (m["DeviceID"].ToString() == "C:")
                        {
                            columnSerialNumber = m["VolumeSerialNumber"].ToString();
                            break;
                        }
                    }
                }
                catch {}
                columnSerialNumber = columnSerialNumber.Replace(":", "");
                CacheUtils.Max("ComputerUtils_ColumnSerialNumber", columnSerialNumber);
            }
            return(columnSerialNumber);
        }
Ejemplo n.º 6
0
        public static object RegisterWithCode(IRequest request)
        {
            var mobile   = request.GetPostString("mobile");
            var password = request.GetPostString("password");
            var code     = request.GetPostString("code");

            var dbCode = CacheUtils.Get <string>(GetSendSmsCacheKey(mobile));

            var    isRegister = false;
            string errorMessage;

            if (code != dbCode)
            {
                errorMessage = "短信验证码不正确";
            }
            else
            {
                var userInfo = Main.Instance.UserApi.NewInstance();
                userInfo.UserName = mobile;
                userInfo.Mobile   = mobile;
                isRegister        = Main.Instance.UserApi.Insert(userInfo, password, out errorMessage);
            }

            return(new
            {
                IsRegister = isRegister,
                ErrorMessage = errorMessage
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取计算机的网卡地址,并将网卡地址中的分隔符“:”除去
        /// </summary>
        /// <returns>计算机的网卡地址</returns>
        public static string GetMacAddress()
        {
            var macAddress = CacheUtils.Get("ComputerUtils_MacAddress") as String;

            if (string.IsNullOrEmpty(macAddress))
            {
                macAddress = string.Empty;
                try
                {
                    var mcMAC  = new ManagementClass("Win32_NetworkAdapterConfiguration");
                    var mocMAC = mcMAC.GetInstances();
                    foreach (ManagementObject m in mocMAC)
                    {
                        if ((bool)m["IPEnabled"])
                        {
                            macAddress = m["MacAddress"].ToString();
                            break;
                        }
                    }
                }
                catch {}
                macAddress = macAddress.Replace(":", "");
                CacheUtils.Max("ComputerUtils_MacAddress", macAddress);
            }
            return(macAddress);
        }
Ejemplo n.º 8
0
        private void RptContents_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            var key   = (string)e.Item.DataItem;
            var value = CacheUtils.Get(key);

            if (value == null)
            {
                return;
            }
            var valueType = value.GetType().FullName;

            var ltlKey   = (Literal)e.Item.FindControl("ltlKey");
            var ltlValue = (Literal)e.Item.FindControl("ltlValue");

            ltlKey.Text = key;

            if (valueType == "System.String")
            {
                ltlValue.Text = $"string, length:{value.ToString().Length}";
            }
            else if (valueType == "System.Int32")
            {
                ltlValue.Text = value.ToString();
            }
            else
            {
                ltlValue.Text = valueType;
            }
        }
Ejemplo n.º 9
0
        public static object IsCodeCorrect(IRequest request)
        {
            var mobile = request.GetPostString("mobile");
            var code   = request.GetPostString("code");

            var dbCode = CacheUtils.Get <string>(GetSendSmsCacheKey(mobile));

            var isCorrect = code == dbCode;
            var token     = string.Empty;

            if (isCorrect)
            {
                var userInfo = Main.Instance.UserApi.GetUserInfoByMobile(mobile);
                if (userInfo != null)
                {
                    token = request.GetUserTokenByUserName(userInfo.UserName);
                }
            }

            return(new
            {
                IsCorrect = isCorrect,
                Token = token
            });
        }
Ejemplo n.º 10
0
        public static object IsCodeCorrect(IRequest request)
        {
            var mobile = request.GetPostString("mobile");
            var code   = request.GetPostString("code");

            var dbCode = CacheUtils.Get <string>(GetSendSmsCacheKey(mobile));

            var isCorrect = code == dbCode;
            var token     = string.Empty;

            if (isCorrect)
            {
                var userInfo = Context.UserApi.GetUserInfoByMobile(mobile);
                if (userInfo != null)
                {
                    token = Context.UserApi.GetAccessToken(userInfo.Id, userInfo.UserName, DateTime.Now.AddDays(7));
                }
            }

            return(new
            {
                IsCorrect = isCorrect,
                Token = token
            });
        }
Ejemplo n.º 11
0
        public IHttpActionResult IsCodeCorrect()
        {
            try
            {
                var request = Context.GetCurrentRequest();

                var mobile = request.GetPostString("mobile");
                var code   = request.GetPostString("code");

                var dbCode = CacheUtils.Get <string>(GetSendSmsCacheKey(mobile));

                var isCorrect = code == dbCode;
                var token     = string.Empty;
                if (isCorrect)
                {
                    var userInfo = Context.UserApi.GetUserInfoByMobile(mobile);
                    if (userInfo != null)
                    {
                        token = Context.UserApi.GetAccessToken(userInfo.Id, userInfo.UserName, DateTime.Now.AddDays(7));
                    }
                }

                return(Ok(new
                {
                    Value = isCorrect,
                    Token = token
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 12
0
            public static List <KeyValuePair <int, SiteInfo> > GetSiteInfoKeyValuePairList()
            {
                var retval = CacheUtils.Get <List <KeyValuePair <int, SiteInfo> > >(CacheKey);

                if (retval != null)
                {
                    return(retval);
                }

                lock (LockObject)
                {
                    retval = CacheUtils.Get <List <KeyValuePair <int, SiteInfo> > >(CacheKey);
                    if (retval == null)
                    {
                        var list = DataProvider.SiteDao.GetSiteInfoKeyValuePairList();
                        retval = new List <KeyValuePair <int, SiteInfo> >();
                        foreach (var pair in list)
                        {
                            var siteInfo = pair.Value;
                            if (siteInfo == null)
                            {
                                continue;
                            }

                            siteInfo.SiteDir = GetSiteDir(list, siteInfo);
                            retval.Add(pair);
                        }

                        CacheUtils.Insert(CacheKey, retval);
                    }
                }

                return(retval);
            }
Ejemplo n.º 13
0
Archivo: Htmls.cs Proyecto: dKluev/Site
 public static Dictionary <int, Tuple <string, string> > AllHtmlBlocks()
 {
     return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => {
         return new SpecialistWebDataContext().HtmlBlocks
         .Select(x => new { x.Id, x.Name, x.Description }).ToList()
         .ToDictionary(x => x.Id, x => Tuple.Create(x.Name, x.Description));
     }, 24));
 }
Ejemplo n.º 14
0
 public List <Announce> GetAllForMainCached()
 {
     return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => {
         var groups = GroupVMService.GetAllForMain();
         return GetAnnounces(groups.AsQueryable()).ToList();
     }
                           ));
 }
Ejemplo n.º 15
0
 public List <int> AllTestSections()
 {
     return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => {
         var relations = TestService.GetTestSectionRelations();
         return relations.Where(x => x.Object.IsActive).Select(x => x.RelationObject_ID).Distinct().ToList()
         .Cast <int>().ToList();
     }, 24));
 }
Ejemplo n.º 16
0
 public Dictionary <string, PageMeta> GetAllPageMetas()
 {
     return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => {
         using (var context = new SpecialistWebDataContext()) {
             return context.PageMetas.ToDictionary(x => x.Url.ToLower(),
                                                   x => x);
         }
     }));
 }
Ejemplo n.º 17
0
        public ActionResult SiteMap()
        {
            HttpContext.Response.AddHeader("Last-modified",
                                           DateTime.Now.ToUniversalTime().ToString("r"));
            var siteMap = CacheUtils.Get(MethodBase.GetCurrentMethod(), () =>
                                         XmlResult.ToStringWithDeclaration(new SiteMapGenerator().Get(Url)));

            return(new XmlResult(siteMap));
        }
Ejemplo n.º 18
0
 public List <string> TrainersWithoutGroup()
 {
     return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => {
         var visibleEmployees = GetAll().Where(x => x.SiteVisible).Select(x => x.Employee_TC).ToList();
         var trainerWithGroup = GroupService.GetAll().Where(x => x.DateBeg > DateTime.Now.AddDays(-30) &&
                                                            (x.Color_TC == Colors.Pink || x.Color_TC == Colors.Yellow)).Select(x => x.Teacher_TC).Distinct()
                                .ToList().AddFluent(Employees.TrainersAlwaysVisible);
         return visibleEmployees.Except(trainerWithGroup).ToList();
     }, 24));
 }
Ejemplo n.º 19
0
 private static Dictionary <int, Dictionary <int, SpecialInfo> > GetCacheDictionary()
 {
     if (CacheUtils.Get(CacheKey) is Dictionary <int, Dictionary <int, SpecialInfo> > dictionary)
     {
         return(dictionary);
     }
     dictionary = new Dictionary <int, Dictionary <int, SpecialInfo> >();
     CacheUtils.InsertHours(CacheKey, dictionary, 24);
     return(dictionary);
 }
Ejemplo n.º 20
0
        public static bool IsIpAddressCached(string ipAddress)
        {
            if (ConfigManager.SystemConfigInfo.UserRegistrationMinMinutes == 0 || string.IsNullOrEmpty(ipAddress))
            {
                return(true);
            }
            var obj = CacheUtils.Get($"SiteServer.CMS.Provider.UserDao.Insert.IpAddress.{ipAddress}");

            return(obj == null);
        }
Ejemplo n.º 21
0
        public IHttpActionResult UploadFile(int siteId, int formId)
        {
            try
            {
                var request     = Context.AuthenticatedRequest;
                var fieldId     = request.GetQueryInt("fieldId");
                var uploadToken = request.GetQueryString("uploadToken");

                var cacheKey  = GetUploadTokenCacheKey(formId);
                var cacheList = CacheUtils.Get <List <string> >(cacheKey) ?? new List <string>();
                if (!cacheList.Contains(uploadToken))
                {
                    return(Unauthorized());
                }

                var fieldInfo = FieldManager.GetFieldInfo(formId, fieldId);
                if (fieldInfo.FieldType != InputType.Image.Value)
                {
                    return(Unauthorized());
                }

                var imageUrl = string.Empty;

                foreach (string name in HttpContext.Current.Request.Files)
                {
                    var postFile = HttpContext.Current.Request.Files[name];

                    if (postFile == null)
                    {
                        return(BadRequest("Could not read image from body"));
                    }

                    var filePath = Context.SiteApi.GetUploadFilePath(siteId, postFile.FileName);

                    if (!FormUtils.IsImage(Path.GetExtension(filePath)))
                    {
                        return(BadRequest("image file extension is not correct"));
                    }

                    postFile.SaveAs(filePath);

                    imageUrl = Context.SiteApi.GetSiteUrlByFilePath(filePath);
                }

                return(Ok(new
                {
                    Value = imageUrl,
                    FieldId = fieldId
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 22
0
        public static IList <DictsInfo> GetCacheDictsList()
        {
            IList <DictsInfo> list = (IList <DictsInfo>)CacheUtils.Get("JsonLeeCMS_CacheForGetDicts");

            if (list == null)
            {
                list = BizBase.dbo.GetList <DictsInfo>(" SELECT * FROM sys_Dicts ");
                CacheUtils.Insert("JsonLeeCMS_CacheForGetDicts", list);
            }
            return(list);
        }
Ejemplo n.º 23
0
            public static Hashtable GetHashtable()
            {
                var ht = CacheUtils.Get(CacheKey) as Hashtable;

                if (ht == null)
                {
                    ht = new Hashtable();
                    CacheUtils.Insert(CacheKey, ht, null, CacheUtils.SecondFactorCalculate(15));
                }
                return(ht);
            }
Ejemplo n.º 24
0
        public static VerInfo GetVer()
        {
            VerInfo verInfo = (VerInfo)CacheUtils.Get("JsonLeeCMS_CacheForVER");

            if (verInfo == null)
            {
                verInfo = Ver.GetData();
                CacheUtils.Insert("JsonLeeCMS_CacheForVER", verInfo, 60, 1);
            }
            return(verInfo);
        }
Ejemplo n.º 25
0
        public IActionResult Index()
        {
            /*
             * net core不自带httpcontext 需要在 Startup 注入
             * 1、在ConfigureServices 中 services.AddStaticHttpContext();
             * 2、在Configure 中 app.UseStaticHttpContext();
             */

            var builder = new StringBuilder("测试如下:\r\n");

            //Post
            builder.Append($"Post值:{WebUtils.GetFormVal<string>("a")}\r\n");

            //IP
            builder.Append($"IP:{IPUtils.GetIP()}\r\n");

            //WebUtils
            builder.Append($"pid:{WebUtils.GetQueryVal<int>("pid")}\r\n");                                  //?pid=1
            builder.Append($"date:{WebUtils.GetQueryVal<DateTime>("date", new DateTime(1900, 1, 1))}\r\n"); //?date=2020-12-31
            //全url
            builder.Append($"全URL:{WebUtils.GetAbsoluteUri()}\r\n");

            //CacheUtils 缓存
            DateTime dateTime = DateTime.Now;
            var      cache    = new CacheUtils();

            var cacheDT = DateTime.Now;

            if (cache.ContainKey("time"))
            {
                cacheDT = cache.Get <DateTime>("time");
            }
            else
            {
                cache.Insert <DateTime>("time", dateTime, 3600);
            }

            builder.Append($"当前时间:{dateTime.ToFormatString()} \r\n");
            builder.Append($"缓存时间:{cacheDT.ToFormatString()} \r\n");

            //当前网站目录
            builder.Append($"当前网站目录:{SystemUtils.GetMapPath()} \r\n");
            builder.Append($"upload目录:{SystemUtils.GetMapPath("/upload")} \r\n");

            //cookie
            CookieUtils.SetCookie("username", "jsonlee");
            builder.Append($"username cookie: {CookieUtils.GetCookie("username")} \r\n");

            //session
            SessionUtils.SetSession("username", System.Web.HttpUtility.UrlEncode("刘备"));
            builder.Append($"username session: {System.Web.HttpUtility.UrlDecode(SessionUtils.GetSession("username"))} \r\n");

            return(Content(builder.ToString()));
        }
Ejemplo n.º 26
0
        private static Dictionary <int, Dictionary <int, TemplateInfo> > GetCacheDictionary()
        {
            var dictionary = CacheUtils.Get(CacheKey) as Dictionary <int, Dictionary <int, TemplateInfo> >;

            if (dictionary == null)
            {
                dictionary = new Dictionary <int, Dictionary <int, TemplateInfo> >();
                CacheUtils.InsertHours(CacheKey, dictionary, 24);
            }
            return(dictionary);
        }
Ejemplo n.º 27
0
        public static IList <CatalogInfo> GetCacheCatalogList()
        {
            IList <CatalogInfo> list = (IList <CatalogInfo>)CacheUtils.Get("JsonLeeCMS_CacheForGetCMSCatalog");

            if (list == null)
            {
                list = BizBase.dbo.GetList <CatalogInfo>(" SELECT * FROM sys_Catalog ORDER BY Sort ASC,AutoID desc ");
                CacheUtils.Insert("JsonLeeCMS_CacheForGetCMSCatalog", list);
            }
            return(list);
        }
Ejemplo n.º 28
0
        public static IList <ContModelInfo> GetCacheModelList()
        {
            IList <ContModelInfo> list = (IList <ContModelInfo>)CacheUtils.Get("JsonLeeCMS_CacheForGetContModel");

            if (list == null)
            {
                list = BizBase.dbo.GetList <ContModelInfo>(" SELECT * FROM cms_ContModel Order by Sort asc, AutoID desc ");
                CacheUtils.Insert("JsonLeeCMS_CacheForGetContModel", list);
            }
            return(list);
        }
Ejemplo n.º 29
0
        public static IList <SettingCategoryInfo> GetCacheSettingCategoryList()
        {
            IList <SettingCategoryInfo> list = (IList <SettingCategoryInfo>)CacheUtils.Get("JsonLeeCMS_CacheForGetSettingCategory");

            if (list == null)
            {
                list = BizBase.dbo.GetList <SettingCategoryInfo>(" select * from sys_SettingCategory order by sort asc ");
                CacheUtils.Insert("JsonLeeCMS_CacheForGetSettingCategory", list);
            }
            return(list);
        }
Ejemplo n.º 30
0
        public static IList <ProductModelInfo> GetCacheModelList()
        {
            IList <ProductModelInfo> list = (IList <ProductModelInfo>)CacheUtils.Get("JsonLeeCMS_CacheForPROMODEL");

            if (list == null)
            {
                list = ProductModel.GetAllList();
                CacheUtils.Insert("JsonLeeCMS_CacheForPROMODEL", list);
            }
            return(list);
        }