Example #1
0
        /// <summary>
        /// 编辑用户
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit()
        {
            DataResult result = new DataResult();

            AdminEntity entity    = WebUtil.GetFormObject <AdminEntity>("Entity");
            string      CompanyID = WebUtil.GetFormValue <string>("CompanyID", string.Empty);

            entity.CompanyID = CompanyID;

            if (entity.IsNull())
            {
                result.Code    = (int)EResponseCode.Exception;
                result.Message = "新增用户信息为空";
                return(Content(JsonHelper.SerializeObject(result)));
            }

            AdminProvider provider = new AdminProvider(CompanyID);
            int           line     = provider.Update(entity);

            if (line > 0)
            {
                result.Code    = (int)EResponseCode.Success;
                result.Message = "用户编辑成功";
            }
            else
            {
                result.Code    = (int)EResponseCode.Exception;
                result.Message = "用户编辑失败";
            }
            return(Content(JsonHelper.SerializeObject(result)));
        }
Example #2
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            AdminEntity LoginUser = filterContext.HttpContext.Session[SessionKey.SESSION_LOGIN_ADMIN] as AdminEntity;

            //如果是未登陆则跳转到登陆页面
            //if (LoginUser == null)
            //{
            //    string path = GetPath(filterContext);
            //    string url = "/Home/Index";
            //    if (!path.IsEmpty())
            //    {
            //        path = filterContext.HttpContext.Server.UrlEncode(path);
            //        url = "/Home/Index?returnurl=" + path;
            //    }
            //    filterContext.Result = new RedirectResult(url);
            //}

            if (this.ValidateLogin)
            {
                string RawUrl = filterContext.HttpContext.Request.RawUrl;
                string path   = filterContext.HttpContext.Request.Path;
                if (LoginUser.IsNull())
                {
                    string url = "/Home/Index";
                    if (!RawUrl.IsEmpty())
                    {
                        RawUrl = filterContext.HttpContext.Server.UrlEncode(RawUrl);
                        url    = "/Home/Index?returnurl=" + RawUrl;
                    }
                    filterContext.Result = new RedirectResult(url);
                }
                else
                {
                    if (ValidateRequest && path != "/")
                    {
                        ITopClient client = new TopClientDefault();
                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        string CompanyID = LoginUser.CompanyID;
                        dic.Add("CompanyID", CompanyID);
                        dic.Add("RoleNum", LoginUser.RoleNum);
                        dic.Add("ResNum", path);
                        string     result     = client.Execute(UserApiName.UserApiName_HasPower, dic);
                        DataResult dataResult = JsonConvert.DeserializeObject <DataResult>(result);

                        if (dataResult.Code != (int)EResponseCode.Success)
                        {
                            string url = "/Home/Error";
                            filterContext.Result = new RedirectResult(url);
                        }
                    }
                }
            }
        }
Example #3
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            //AdminEntity LoginUser = filterContext.HttpContext.Session[CacheKey.SESSION_LOGIN_ADMIN] as AdminEntity;
            ////如果是未登陆则跳转到登陆页面
            //if (LoginUser == null)
            //{
            //    string path = GetPath(filterContext);
            //    string url = "/Home/Index";
            //    if (!path.IsEmpty())
            //    {
            //        path = filterContext.HttpContext.Server.UrlEncode(path);
            //        url = "/Home/Index?returnurl=" + path;
            //    }
            //    filterContext.Result = new RedirectResult(url);
            //}

            if (this.ValidateLogin)
            {
                AdminEntity LoginUser = filterContext.HttpContext.Session[CacheKey.SESSION_LOGIN_ADMIN] as AdminEntity;
                string      path      = filterContext.HttpContext.Request.Path;
                if (LoginUser.IsNull())
                {
                    string url = "/Home/Index";
                    if (!path.IsEmpty())
                    {
                        path = filterContext.HttpContext.Server.UrlEncode(path);
                        url  = "/Home/Index?returnurl=" + path;
                    }
                    filterContext.Result = new RedirectResult(url);
                }
                else
                {
                    if (ValidateRequest && path != "/")
                    {
                        PowerProvider provider = new PowerProvider();
                        bool          hasPower = provider.HasPower(path, LoginUser.RoleNum);
                        if (!hasPower)
                        {
                            string url = "/Home/Error";
                            filterContext.Result = new RedirectResult(url);
                        }
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// 1001:用户未登录
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (this.ValidateLogin)
            {
                AdminEntity LoginUser = filterContext.HttpContext.Session[SessionKey.SESSION_LOGIN_ADMIN] as AdminEntity;
                string      path      = filterContext.HttpContext.Request.Path;
                if (LoginUser.IsNull())
                {
                    filterContext.Result = new JsonResult()
                    {
                        Data = new DataResult()
                        {
                            Code = (int)EResponseCode.NotLogin, Message = "未登录"
                        }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                }
                else
                {
                    if (ValidateRequest && path != "/")
                    {
                        ITopClient client = new TopClientDefault();
                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        string CompanyID = LoginUser.CompanyID;
                        dic.Add("CompanyID", CompanyID);
                        dic.Add("RoleNum", LoginUser.RoleNum);
                        dic.Add("ResNum", path);
                        string     result     = client.Execute(UserApiName.UserApiName_HasPower, dic);
                        DataResult dataResult = JsonConvert.DeserializeObject <DataResult>(result);

                        if (dataResult.Code != (int)EResponseCode.Success)
                        {
                            filterContext.Result = new JsonResult()
                            {
                                Data = new DataResult()
                                {
                                    Code = (int)EResponseCode.NoPermission, Message = "未登录"
                                }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                            };
                        }
                    }
                }
            }
        }