Ejemplo n.º 1
0
        string type = String.Empty; // 查询类型

        protected void Page_Load(object sender, EventArgs e)
        {
            id   = (RequestData.ContainsKey("id") ? RequestData["id"].ToString() : String.Empty);
            type = (RequestData.ContainsKey("type") ? RequestData["type"].ToString() : String.Empty).ToLower();

            if (this.IsAsyncRequest)
            {
                switch (this.RequestAction)
                {
                case RequestActionEnum.Custom:
                    if (RequestActionString == "querychildren" || RequestActionString == "querydescendant")
                    {
                        SysAuth[] ents = null;

                        if (RequestActionString == "querychildren")
                        {
                            string atype = String.Empty;

                            if (type == "atype")
                            {
                                ents = SysAuth.FindAll("FROM SysAuth as ent WHERE ent.Type = ? AND ent.ParentID IS NULL", id);
                            }
                            else
                            {
                                ents = SysAuth.FindAll("FROM SysAuth as ent WHERE ent.ParentID = ?", id);
                            }
                        }
                        else if (RequestActionString == "querydescendant")
                        {
                            string atype = String.Empty;

                            if (type == "atype")
                            {
                                ents = SysAuth.FindAll("FROM SysAuth as ent WHERE ent.Type = ?", id);
                            }
                            else
                            {
                                ents = SysAuth.FindAll("FROM SysAuth as ent WHERE ent.Path LIKE %?%", id);
                            }
                        }

                        string jsonString = JsonHelper.GetJsonString(this.ToExtTreeCollection(ents.OrderBy(v => v.SortIndex).ThenBy(v => v.CreateDate), null));

                        Response.Write(jsonString);

                        Response.End();
                    }
                    else if (RequestActionString == "savechanges")
                    {
                        ICollection authAdded   = RequestData["added"] as ICollection;
                        ICollection authRemoved = RequestData["removed"] as ICollection;

                        if (type == "user" && !String.IsNullOrEmpty(id))
                        {
                            SysAuthRule.GrantAuthToUser(authAdded, id);
                            SysAuthRule.RevokeAuthFromUser(authRemoved, id);
                        }
                        else if (type == "group" && !String.IsNullOrEmpty(id))
                        {
                            SysAuthRule.GrantAuthToGroup(authAdded, id);
                            SysAuthRule.RevokeAuthFromGroup(authRemoved, id);
                        }
                        else if (type == "role" && !String.IsNullOrEmpty(id))
                        {
                            SysAuthRule.GrantAuthToRole(authAdded, id);
                            SysAuthRule.RevokeAuthFromRole(authRemoved, id);
                        }
                    }
                    break;
                }
            }
            else
            {
                SysAuthType[] authTypeList = SysAuthTypeRule.FindAll();

                this.PageState.Add("DtList", authTypeList);
            }

            // 获取权限列表
            if (RequestAction != RequestActionEnum.Custom)
            {
                this.PageState.Add("EntityID", id);

                IEnumerable <string> authIDs = null;
                using (new Castle.ActiveRecord.SessionScope())
                {
                    if (type == "user" && !String.IsNullOrEmpty(id))
                    {
                        SysUser user = SysUser.Find(id);
                        authIDs = (user.Auth).Select((ent) => { return(ent.AuthID); });
                    }
                    else if (type == "group" && !String.IsNullOrEmpty(id))
                    {
                        SysGroup group = SysGroup.Find(id);
                        authIDs = (group.Auth).Select((ent) => { return(ent.AuthID); });
                    }
                    else if (type == "role" && !String.IsNullOrEmpty(id))
                    {
                        SysRole role = SysRole.Find(id);
                        authIDs = (role.Auth).Select((ent) => { return(ent.AuthID); });
                    }

                    this.PageState.Add("AtList", new List <string>(authIDs));
                }
            }
        }
Ejemplo n.º 2
0
        private byte[] ExecuteServiceByMsgObj(OpMessage opMsg)
        {
            try
            {
                byte[] data    = null;
                Object dataObj = null;

                if (String.IsNullOrEmpty(opMsg.Operation))
                {
                    return(null);
                }

                string label = (opMsg.Lable == null ? String.Empty : opMsg.Lable).ToLower();
                string op    = (opMsg.Operation == null ? String.Empty : opMsg.Operation).ToLower();

                if (label == "getuserdata")
                {
                    using (new SessionScope())
                    {
                        UserLogonInfo  logonInfo = Server.GetLogonInfo(opMsg.SessionID);
                        IList <string> ids       = new List <string>();

                        if (logonInfo != null)
                        {
                            if (op == "getlogoninfo")
                            {
                                dataObj = logonInfo;
                            }
                            else if (op == "getalluserauth")
                            {
                                dataObj = logonInfo.User.RetrieveAllAuth();
                            }
                            else if (op == "getallusergroup")
                            {
                                dataObj = logonInfo.User.RetrieveAllGroup();
                            }
                            else if (op == "getalluserrole")
                            {
                                dataObj = logonInfo.User.RetrieveAllRole();
                            }
                            else if (op == "getalluserauthids")
                            {
                                IList <SysAuth>      auths   = logonInfo.User.RetrieveAllAuth();
                                IEnumerable <string> authIDs = auths.Select(ent => { return(ent.AuthID); });

                                dataObj = new List <string>(authIDs);
                            }
                            else if (op == "getallusergroupids")
                            {
                                IList <SysGroup>     grps   = logonInfo.User.RetrieveAllGroup();
                                IEnumerable <string> grpIDs = grps.Select(ent => { return(ent.GroupID); });

                                dataObj = new List <string>(grpIDs);
                            }
                            else if (op == "getalluserroleids")
                            {
                                IList <SysRole>      roles   = logonInfo.User.RetrieveAllRole();
                                IEnumerable <string> roleIDs = roles.Select(ent => { return(ent.RoleID); });

                                dataObj = new List <string>(roleIDs);
                            }
                            else if (op == "getuserinfo")
                            {
                                dataObj = new SimpleUserInfo(logonInfo);
                            }
                            else if (op == "getsysuser")
                            {
                                dataObj = logonInfo.User;
                            }
                        }
                    }
                }
                else if (label == "getsystemdata")
                {
                    using (new SessionScope())
                    {
                        if (opMsg.Operation == "getallapplications")
                        {
                            dataObj = new List <SysApplication>(SysApplicationRule.FindAll());
                        }
                        else if (opMsg.Operation == "getallmodules")
                        {
                            dataObj = new List <SysModule>(SysModuleRule.FindAll());
                        }
                        else if (opMsg.Operation == "getallgroups")
                        {
                            dataObj = new List <SysGroup>(SysGroupRule.FindAll());
                        }
                        else if (opMsg.Operation == "getallusers")
                        {
                            dataObj = new List <SysUser>(SysUserRule.FindAll());
                        }
                        else if (opMsg.Operation == "getallroles")
                        {
                            dataObj = new List <SysRole>(SysRoleRule.FindAll());
                        }
                        else if (opMsg.Operation == "getallauths")
                        {
                            dataObj = new List <SysAuth>(SysAuthRule.FindAll());
                        }
                    }
                }
                else
                {
                    try
                    {
                        if (op == "checkusersession")
                        {
                            dataObj = Server.CheckUserSession(opMsg.SessionID);
                        }
                        else if (op == "releasesession")
                        {
                            dataObj = Server.ReleaseSession(opMsg.SessionID);
                        }
                        else if (op == "setpreprelease")
                        {
                            if (opMsg["logmode"].Type != TypeCode.Empty)
                            {
                                Server.SetPrepRelease(opMsg.SessionID, (LoginTypeEnum)opMsg["logmode"].Value);
                            }
                            else
                            {
                                Server.SetPrepRelease(opMsg.SessionID);
                            }

                            Server.SetPrepRelease(opMsg.SessionID);
                        }
                        else if (op == "refreshsession")
                        {
                            Server.RefreshSession(opMsg.SessionID);
                        }
                    }
                    catch (Exception ex)
                    {
                        dataObj = false;
                    }
                }

                if (dataObj != null)
                {
                    data = ServiceHelper.SerializeToBytes(dataObj);
                }

                return(data);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        string type = String.Empty; // 查询类型

        protected void Page_Load(object sender, EventArgs e)
        {
            id   = (RequestData.ContainsKey("id") ? RequestData["id"].ToString() : UserInfo.UserID);
            type = (RequestData.ContainsKey("type") ? RequestData["type"].ToString() : String.Empty).ToLower();
            if (this.IsAsyncRequest)
            {
                switch (this.RequestAction)
                {
                case RequestActionEnum.Custom:
                    if (RequestActionString == "querydescendant")
                    {
                        SysAuth[] ents  = null;
                        string    atype = String.Empty;
                        //ents = SysAuth.FindAll("FROM SysAuth as ent WHERE ent.Type = ?", id);
                        SysUser user = SysUser.Find(this.UserInfo.UserID);
                        ents = this.UserContext.Auths.OrderBy(ens => ens.SortIndex).ToArray();
                        //SysAuth.FindAll(Expression.Sql("AuthID in (select AuthID from SysUserPermission where UserID ='" + this.UserInfo.UserID + "')"));
                        //user.Auth.ToArray();
                        string jsonString = JsonHelper.GetJsonString(this.ToExtTreeCollection(ents.OrderBy(v => v.SortIndex).ThenBy(v => v.CreateDate), null));
                        Response.Write(jsonString);
                        Response.End();
                    }
                    else if (RequestActionString == "savechanges")
                    {
                        ICollection authAdded   = RequestData["added"] as ICollection;
                        ICollection authRemoved = RequestData["removed"] as ICollection;

                        if (type == "user" && !String.IsNullOrEmpty(id))
                        {
                            SysAuth[] tAuths = SysAuthRule.GetAuthByIDs(authAdded).ToArray();
                            foreach (SysAuth auth in tAuths)
                            {
                                MyShortCut cut = new MyShortCut();
                                cut.CreateId     = this.UserInfo.UserID;
                                cut.CreateName   = this.UserInfo.Name;
                                cut.CreateTime   = DateTime.Now;
                                cut.ModuleUrl    = SysModule.Find(auth.ModuleID).Url;
                                cut.AuthId       = auth.AuthID;
                                cut.AuthName     = auth.Name;
                                cut.IconFileName = "/images/shared/read.gif";
                                cut.Save();
                            }
                            if (authRemoved.Count > 0)
                            {
                                ICollection myAuthIDs = null;
                                if (authRemoved is JArray)
                                {
                                    JArray arrAuths = authRemoved as JArray;
                                    myAuthIDs = new List <string>(arrAuths.Values <string>());
                                }
                                else
                                {
                                    myAuthIDs = authRemoved;
                                }
                                foreach (string s in myAuthIDs)
                                {
                                    DataHelper.ExecSql("delete from MyShortCut where AuthId like '%" + s + "%' and CreateId='" + this.UserInfo.UserID + "'", DataHelper.GetCurrentDbConnection(typeof(MyShortCut)));
                                }
                            }
                            //SysAuthRule.GrantAuthToUser(authAdded, id);
                            //SysAuthRule.RevokeAuthFromUser(authRemoved, id);
                        }

                        /*else if (type == "group" && !String.IsNullOrEmpty(id))
                         * {
                         *  SysAuthRule.GrantAuthToGroup(authAdded, id);
                         *  SysAuthRule.RevokeAuthFromGroup(authRemoved, id);
                         * }
                         * else if (type == "role" && !String.IsNullOrEmpty(id))
                         * {
                         *  SysAuthRule.GrantAuthToRole(authAdded, id);
                         *  SysAuthRule.RevokeAuthFromRole(authRemoved, id);
                         * }*/
                    }
                    break;
                }
            }
            else
            {
                SysAuthType[] authTypeList = SysAuthTypeRule.FindAll();
                if (this.Request.QueryString["Role"] != null && this.Request.QueryString["Role"] == "User")
                {
                    authTypeList = SysAuthType.FindAllByProperties(SysAuthType.Prop_AuthTypeID, 1);
                }
                this.PageState.Add("DtList", authTypeList);
            }

            // 获取权限列表
            if (RequestAction != RequestActionEnum.Custom)
            {
                this.PageState.Add("EntityID", id);
                IEnumerable <string> authIDs = null;
                IList <MyShortCut>   mscEnts = MyShortCut.FindAllByProperty(MyShortCut.Prop_CreateId, UserInfo.UserID);

                authIDs = mscEnts.Select(s => s.AuthId);
                this.PageState.Add("AtList", new List <string>(authIDs));
                //using (new Castle.ActiveRecord.SessionScope())
                //{
                //    if (type == "user" && !String.IsNullOrEmpty(id))
                //    {
                //        SysUser user = SysUser.Find(id);
                //        if (this.RequestData.Get<string>("Deny") != null && this.RequestData.Get<string>("Deny").Trim() == "Y")
                //        {
                //            authIDs = (user.AuthNo).Select((ent) => { return ent.AuthID; });
                //        }
                //        else
                //            authIDs = (user.Auth).Select((ent) => { return ent.AuthID; });
                //    }
                //    else if (type == "group" && !String.IsNullOrEmpty(id))
                //    {
                //        SysGroup group = SysGroup.Find(id);
                //        authIDs = (group.Auth).Select((ent) => { return ent.AuthID; });
                //    }
                //    else if (type == "role" && !String.IsNullOrEmpty(id))
                //    {
                //        SysRole role = SysRole.Find(id);
                //        authIDs = (role.Auth).Select((ent) => { return ent.AuthID; });
                //    }
                //    this.PageState.Add("AtList", new List<string>(authIDs));
                //}
            }
        }