Пример #1
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            //get cookie

            var token = _cookie.GetCookie(ClaimTypes.Sid)?.ToString();

            if (token == null)
            {
                context.Result = new ContentResult()
                {
                    Content = "Unorthorized",
                };
                return;
            }
            //get cache
            var user = _memoryCache.GetCache(token);

            if (user == null)
            {
                var _adminToken = new adminSystemContext().AdminTokens;
                var _adminUser  = new adminSystemContext().AdminUsers;
                var id          = _adminToken.Where(o => o.Token == token).FirstOrDefault().UserId;
                var sysUser     = _adminUser.Where(o => o.Id == id);
                _memoryCache.SetCache(token, sysUser);
                if (sysUser == null)
                {
                    context.Result = new ContentResult()
                    {
                        Content = "Unorthorized",
                    };
                    return;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 获取实体信息
        /// </summary>
        /// <returns></returns>
        public static EntityInfo GetEntityInfo <T>() where T : BaseEntity
        {
            var t = typeof(T);

            if (!MemoryCacheHelper.Exists(t.FullName))
            {
                var entityInfo = new EntityInfo();
                var tableName  = t.Name;
                var obs        = t.GetTypeInfo().GetCustomAttribute <TableAttribute>();
                if (obs != null)
                {
                    tableName = obs.Name;
                }
                var fields     = new List <string>();
                var properties = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                var dbProps    = new List <PropertyInfo>();
                foreach (var p in properties)
                {
                    if (p.CanWrite && p.CanRead && p.GetCustomAttribute <NotMappedAttribute>() == null)
                    {
                        fields.Add(p.Name);
                        dbProps.Add(p);
                    }
                }

                entityInfo.TableName  = tableName;
                entityInfo.Properties = dbProps.ToArray();
                entityInfo.Columns    = fields;

                MemoryCacheHelper.SetCache(t.FullName, entityInfo, TimeSpan.FromDays(1));
            }

            return(MemoryCacheHelper.GetCache <EntityInfo>(t.FullName));
        }
Пример #3
0
        public IActionResult GetValidateCode()
        {
            string validateString = ValidateCodeHelper.CreateVaildateString(4);

            byte[] buffer = ValidateCodeHelper.CreateValidateCode(validateString);
            string ip     = HttpContext.Connection.RemoteIpAddress.ToString();

            MemoryCacheHelper.SetCache(ip, validateString);
            return(File(buffer, @"image/png"));
        }
Пример #4
0
        public IActionResult GetValidPicture()
        {
            string Code = GetvalidString(5);

            //获取图片
            byte[] Imgarr = this.CreateValidPicture(Code);
            //获取ip
            string ip = HttpContext.Connection.RemoteIpAddress.ToString();

            //将验证码的值保存在缓存中
            MemoryCacheHelper.SetCache(ip, Code);

            return(File(Imgarr, "Image/jpeg"));
        }
Пример #5
0
        /// <summary>
        /// 学校公众号入口
        /// </summary>
        /// <param name="sId"></param>
        public ActionResult SchoolPortal(int sId)
        {
            glbSchoolId = sId;

            ModelWxSetting mWxSetting = JsonFileProvider.Instance.GetSettings <ModelWxSetting>();
            var            wxPubInfo  = Service.GetWx_PublicInfo(2, sId);
            // 生成重定向URL
            String redirectUrl = mWxSetting.PubUrl_Host + mWxSetting.PubUrl_WxHome;
            String authUrl     = WXOAuthApiHelper.GetAuthorizeUrl(wxPubInfo.AppId, redirectUrl, "State", EnumOAuthScope.snsapi_userinfo);

            MemoryCacheHelper.SetCache("WxPubInfo", wxPubInfo);
            // 验证跳转
            Response.Redirect(authUrl);

            return(Content("已完成跳转"));
        }
Пример #6
0
        /// <summary>
        /// 获取模型属性列表
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static PropertyInfo[] GetModelProperties(Type t)
        {
            if (!MemoryCacheHelper.Exists(t.FullName))
            {
                var properies = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                var list      = new List <PropertyInfo>();
                foreach (var p in properies)
                {
                    if (p.CanWrite && p.GetCustomAttribute <NotMappedAttribute>() == null)
                    {
                        list.Add(p);
                    }
                }
                MemoryCacheHelper.SetCache(t.FullName, list.ToArray(), TimeSpan.FromDays(1));
            }

            return(MemoryCacheHelper.GetCache <PropertyInfo[]>(t.FullName));
        }
Пример #7
0
        /// <summary>
        /// 陪绮在线自有公众号入口
        /// </summary>
        public ActionResult Index()
        {
            ModelWxSetting mWxSetting = JsonFileProvider.Instance.GetSettings <ModelWxSetting>();

            var wxPubInfo = Service.GetWx_PublicInfo(1);

            // 生成重定向URL
#if DEBUG
            mWxSetting.PubUrl_Host = mWxSetting.PubUrl_Host.Replace("https", "http");
#endif
            String redirectUrl = mWxSetting.PubUrl_Host + mWxSetting.PubUrl_WxHome;
            String authUrl     = WXOAuthApiHelper.GetAuthorizeUrl(wxPubInfo.AppId, redirectUrl, "State", EnumOAuthScope.snsapi_userinfo);
            MemoryCacheHelper.SetCache("WxPubInfo", wxPubInfo);
            // 验证跳转

            Response.Redirect(authUrl);

            return(Content("已完成跳转"));
        }
        /// <summary>
        /// 获取用户权限
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <List <InterfaceOperationModel> > GetUserAuthoritiesAsync(AspNetUser user)
        {
            var key = $"{user.Id}_UserAuthorities";

            if (!MemoryCacheHelper.Exists(key))
            {
                var list = new List <InterfaceOperationModel>();

                var    b   = (await _context.QueryNumberBySqlAsync($"SELECT COUNT(b.Id) FROM AspNetRole a,AspNetUserRole b WHERE a.Id=b.RoleId AND b.UserId={user.Id} AND a.Name='{nameof(RoleTypes.Admin)}'")) > 0;
                string sql = GET_ALL_OPERATION_SQL;
                if (!b)
                {
                    sql = $@"SELECT t2.InterfaceName,t2.OperationName FROM ({GET_ALL_OPERATION_SQL}) t2,DDomainAuthority t3,`aspnetusers` t4 WHERE t3.`OperationId`=t2.`Id`
                            AND t4.`Id`= '{user.Id}' AND(t3.`AuthorityId`= t4.`AuthorityId` OR t3.`AuthorityId` IN(SELECT a.AuthorityId FROM `aspnetroles` a,`aspnetuserroles` b WHERE a.`Id`= b.`RoleId` AND b.`UserId`= '{user.Id}'))";
                }

                list = await _context.QueryListBySqlAsync <InterfaceOperationModel>(sql);

                MemoryCacheHelper.SetCache(key, list);
            }

            return(MemoryCacheHelper.GetCache <List <InterfaceOperationModel> >(key));
        }