Example #1
0
        /// <summary>
        /// 第三执行
        /// </summary>
        /// <param name="context"></param>
        public void OnActionExecuting(ActionExecutingContext context)
        {
            var request     = context.HttpContext.Request;
            var RequestPath = request.Path.ToString();

            if (RequestPath.Contains("Regist"))
            {
                var PhoneCode   = request.Form["Parameter[PhoneCode]"].ToString();
                var SessionCode = CacheFactory.Cache().GetCache <string>("PhoneCode").Trim();
                if (string.IsNullOrEmpty(SessionCode))
                {
                    context.Result = ObjectResultEx.Instance("请输入验证码", 1, RetrunMessge.SUCCESS, HttpCode.FAIL);
                }
                if (!SessionCode.Trim().Equals(PhoneCode))
                {
                    context.Result = ObjectResultEx.Instance("请输入正确的验证码", 1, RetrunMessge.SUCCESS, HttpCode.FAIL);
                }
                CacheFactory.Cache().RemoveCache("PhoneCode");
            }
            if (RequestPath.Contains("EnterpriseWeb/Edit") || RequestPath.Contains("EnterpriseWeb/Remove"))
            {
                //if (RequestPath.Contains("Edit"))
                //{
                //    if (string.IsNullOrEmpty(request.Form["Id"].ToString()))
                //    {
                //        return;
                //    }
                //    if (RequestPath.Contains("EditProBatchAttach"))
                //        return;
                //}
                //context.Result = new StatusCodeResult(403);
            }
            //if (RequestPath.Contains("RepastWeb/Edit") || RequestPath.Contains("RepastWeb/Remove"))
            //{
            //    if (RequestPath.Contains("Edit"))
            //    {
            //        if (string.IsNullOrEmpty(request.Form["Id"].ToString()))
            //        {
            //            return;
            //        }
            //    }
            //    if (RequestPath.Contains("RemoveScan"))
            //        return;
            //    context.Result = new StatusCodeResult(403);
            //}
            if (context.Filters.Any(t => (t as AllowAnonymousFilter) != null))
            {
                return;
            }
            if (request.Headers.ContainsKey("ApiKey") && request.Headers.ContainsKey("SysKey"))
            {
                String ApiKey = RSACryptionExtension.RSADecrypt(request.Headers["ApiKey"].FirstOrDefault());
                String SysKey = RSACryptionExtension.RSADecrypt(request.Headers["SysKey"].FirstOrDefault());
                if (ApiKey.Equals(Configer.ApiKey + DateTime.Now.ToShortDateString()) && SystemInfoKey.PrivateKey.Equals(SysKey))
                {
                    return;
                }
            }
            context.Result = new UnauthorizedResult();
        }
Example #2
0
        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns></returns>
        public static string LoginOut()
        {
            String HeadToken  = Configer.HttpContext.Request.Headers["Token"].ToString();
            String HeadSysKey = Configer.HttpContext.Request.Headers["SysKey"].ToString();
            String Token      = RSACryptionExtension.RSADecrypt(HeadToken);
            String SysKey     = RSACryptionExtension.RSADecrypt(HeadSysKey);

            CacheFactory.Cache().RemoveCache(Token);
            CacheFactory.Cache().RemoveCache(SysKey);
            return("退出成功!");
        }
Example #3
0
        /// <summary>
        /// 验证登录
        /// </summary>
        /// <returns></returns>
        public static CookieInfo Verification()
        {
            if (String.IsNullOrEmpty(Configer.HttpContext.Request.Headers["Token"].ToList().FirstOrDefault()))
            {
                return(null);
            }
            String     Token  = RSACryptionExtension.RSADecrypt(Configer.HttpContext.Request.Headers["Token"].ToString());
            CookieInfo Cookie = CacheFactory.Cache().GetCache <CookieInfo>(Token);

            SystemInfoKey.PrivateKey = Cookie == null ? null : Cookie.SysKey;
            return(Cookie);
        }
Example #4
0
 /// <summary>
 /// 写入cookie
 /// </summary>
 /// <param name="Cookie"></param>
 public static void WriteToken <T>(CookieInfo Cookie, T DTOInfo) where T : class, new()
 {
     Cookie.Token  = Guid.NewGuid().ToString();
     Cookie.SysKey = Guid.NewGuid().ToString();
     Cookie.ApiKey = RSACryptionExtension.RSAEncrypt(Configer.ApiKey + DateTime.Now.ToShortDateString());
     CacheFactory.Cache().WriteCache(Cookie, Cookie.Token, 2);
     CacheFactory.Cache().WriteCache <T>(DTOInfo, Cookie.SysKey, 2);
     //将加密后的Token和Key回传给客服端
     ResponseCookieInfo.RSAToKen  = RSACryptionExtension.RSAEncrypt(Cookie.Token);
     ResponseCookieInfo.RSAApiKey = Cookie.ApiKey;
     ResponseCookieInfo.RSASysKey = RSACryptionExtension.RSAEncrypt(Cookie.SysKey);
 }