Example #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!Enabled)
            {
                base.OnActionExecuting(filterContext);
                return;
            }

            string    token = filterContext.HttpContext.Request["token"];
            JwtResult jwt   = JwtUtil.Decode(token);

            if (jwt.Success)
            {
                //获取当前登录用户
                IUser iUser = lessContext.GetService <IUser>();
                lessContext.CurrentUser = iUser.GetCurrentUser(lessContext);
                if (lessContext.CurrentUser == null)
                {
                    jwt.Success = false;
                    jwt.Msg     = $"获取登录帐号 {lessContext.Jwt.Result[BasicConst.JWT_USER].loginName} 信息失败,请重新登录!";
                    filterContext.HttpContext.Response.AddHeaderTimeOut();
                    filterContext.Result = new BaseJsonResult()
                    {
                        Data = jwt
                    };
                    return;
                }

                //获取当前站点
                var sysWebSiteDal = lessContext.GetService <SysWebSiteDal>();
                lessContext.WebSite = sysWebSiteDal.GetModel(filterContext.HttpContext.Request["SiteID"]);

                //获取权限
                IPermissions iPermissions = lessContext.GetService <IPermissions>();
                lessContext.Limit = iPermissions.GetPermissions(lessContext, filterContext.RequestContext.HttpContext.Request);

                base.OnActionExecuting(filterContext);
                return;
            }
            else
            {
                filterContext.HttpContext.Response.AddHeaderTimeOut();
                if (string.IsNullOrEmpty(WhenNotPassedRedirectUrl))
                {
                    filterContext.Result = new BaseJsonResult()
                    {
                        Data = jwt
                    };
                }
                else
                {
                    filterContext.Result = new RedirectResult(WhenNotPassedRedirectUrl);
                }
            }
        }
Example #2
0
        public JsonResult Login()
        {
            var dict = new Dictionary <string, object>();

            dict["limit"] = "10101010100111";
            dict["user"]  = new { Name = "张三", Age = 25 };
            string jwt = JwtUtil.Encode(dict, 10 * 60);

            JwtResult result = JwtUtil.Decode(jwt);
            dynamic   user   = (dynamic)result.Result["user"];
            string    name   = user.Name;

            return(Json(jwt));
        }