Ejemplo n.º 1
0
        /// <summary>
        /// 刷新应用模块
        /// </summary>
        public void RefreshModules()
        {
            applications = new ReadOnlyCollection <SysApplication>(SysApplication.FindAll());
            modules      = new ReadOnlyCollection <SysModule>(SysModule.FindAll(Expression.Eq(SysModule.Prop_Status, 1)));

            auths  = new ReadOnlyCollection <SysAuth>(SysAuth.FindAll());
            roles  = new ReadOnlyCollection <SysRole>(SysRole.FindAll());
            groups = new ReadOnlyCollection <SysGroup>(SysGroup.FindAll());
        }
        /// <summary>
        /// 刷新应用模块
        /// </summary>
        private void RefreshModules()
        {
            applications = new List <SysApplication>(SysApplication.FindAll());
            modules      = new List <SysModule>(SysModule.FindAll(Expression.Eq(SysModule.Prop_Status, 1)));

            auths  = new List <SysAuth>(SysAuth.FindAll());
            roles  = new List <SysRole>(SysRole.FindAll());
            groups = new List <SysGroup>(SysGroup.FindAll());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新账户认证信息
        /// </summary>
        private async Task <ResponseResult> UpdateAuthInfo(SysUser userInfo, LoginInfoModel loginInfo)
        {
            var authInfo = new SysAuth
            {
                UserId                  = userInfo.Id,
                Platform                = loginInfo.Platform,
                LoginTime               = DateTime.Now,
                LoginIP                 = loginInfo.IP ?? "1",
                RefreshToken            = GenerateRefreshToken(),
                RefreshTokenExpiredTime = DateTime.Now.AddDays(7)//默认刷新令牌有效期7天
            };
            var platform = Convert.ToInt32(loginInfo.Platform);
            var entity   = _authRepository.GetList(a => a.UserId == userInfo.Id && a.Platform == loginInfo.Platform).FirstOrDefault();

            if (entity != null)
            {
                entity.UserId                  = userInfo.Id;
                entity.Platform                = loginInfo.Platform;
                entity.LoginTime               = DateTime.Now;
                entity.LoginIP                 = loginInfo.IP ?? "1";
                entity.RefreshToken            = GenerateRefreshToken();
                entity.RefreshTokenExpiredTime = DateTime.Now.AddDays(7);//默认刷新令牌有效期7天

                _authRepository.Update(entity);
            }
            else
            {
                _authRepository.Insert(authInfo);
            }
            var count = await _iUnitOfWork.SaveChangesAsync();


            if (count.Equals(1))
            {
                //删除验证码缓存
                if (loginInfo.VerifyCode != null)
                {
                    CacheHelper.Cache.RemoveCache($"{GlobalSettings.LyAdminOptions.DefaultAppKeys.VerifyCode}:{loginInfo.VerifyCode.Id}");
                }

                //删除认证信息缓存
                CacheHelper.Cache.RemoveCache($"{GlobalSettings.LyAdminOptions.DefaultAppKeys.AuthInfo}:{userInfo.Id}:{loginInfo.Platform}");


                var userInfoResource = _mapper.Map <UserInfoResource>(userInfo);
                var authInfoResource = _mapper.Map <AuthResource>(authInfo);

                return(new ResponseResult <LoginResultModel>(true, new LoginResultModel
                {
                    UserInfo = userInfoResource,
                    AuthResource = authInfoResource
                }));
            }
            return(null);
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            op = RequestData.Get <string>("op");
            id = RequestData.Get <string>("id");
            string AuthIds = RequestData.Get <string>("AuthIds");

            if (!string.IsNullOrEmpty(id))
            {
                ent = MyShortCut.Find(id);
            }
            switch (RequestActionString)
            {
            case "update":
                ent = GetMergedData <MyShortCut>();
                ent.DoUpdate();
                break;

            case "create":
                ent = GetPostedData <MyShortCut>();
                sql = @"delete from BJKY_IntegratedManage..MyShortCut where CreateId='{0}' and PatIndex('%'+AuthId+'%','{1}')>0";
                sql = string.Format(sql, UserInfo.UserID, ent.AuthId);
                DataHelper.ExecSql(sql);    //删除快捷中已经存在权限模块ID
                if (ent.AuthId.Length > 36)
                {
                    string[] authIdArray   = ent.AuthId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    string[] authNameArray = ent.AuthName.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < authIdArray.Length; i++)
                    {
                        MyShortCut mscEnt = new MyShortCut();
                        mscEnt.AuthId   = authIdArray[i];
                        mscEnt.AuthName = authNameArray[i];
                        SysAuth   saEnt = SysAuth.Find(ent.AuthId);
                        SysModule smEnt = SysModule.Find(saEnt.ModuleID);
                        mscEnt.ModuleUrl    = smEnt.Url;
                        mscEnt.IconFileId   = ent.IconFileId;
                        mscEnt.IconFileName = ent.IconFileName;
                        mscEnt.DoCreate();
                    }
                }
                else
                {
                    SysAuth   saEnt = SysAuth.Find(ent.AuthId);
                    SysModule smEnt = SysModule.Find(saEnt.ModuleID);
                    ent.ModuleUrl = smEnt.Url;
                    ent.DoCreate();
                }
                break;

            default:
                DoSelect();
                break;
            }
        }
Ejemplo n.º 5
0
        string id = String.Empty;   // 对象id

        protected void Page_Load(object sender, EventArgs e)
        {
            op = RequestData.Get <string>("op"); // 用户编辑操作
            id = RequestData.Get <string>("id");

            SysAuth ent = null;

            if (IsAsyncRequest)
            {
                switch (RequestAction)
                {
                case RequestActionEnum.Query:
                case RequestActionEnum.Default:
                    break;

                case RequestActionEnum.Create:
                    ent = this.GetPostedData <SysAuth>();
                    ent.CreateAndFlush();
                    break;

                case RequestActionEnum.Delete:
                    ent = this.GetTargetData <SysAuth>();
                    ent.DeleteAndFlush();
                    break;

                default:
                    if (RequestActionString == "createsub")
                    {
                        ent = this.GetPostedData <SysAuth>();
                        ent.CreateAsSub(id);
                    }
                    break;
                }
            }
            else
            {
                if (op != "c" && op != "cs")
                {
                    if (!String.IsNullOrEmpty(id))
                    {
                        ent = SysAuth.Find(id);
                    }
                }
            }

            DataEnum de = SysAuthTypeRule.GetAuthTypeEnum();

            this.PageState.Add("AuthTypeEnum", de);

            this.SetFormData(ent);
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SearchCriterion.AutoOrder = false;
            SearchCriterion.SetOrder(SysUser.Prop_WorkNo);
            string dName = SearchCriterion.GetSearchValue <string>("Name");

            if (dName != null && dName.Trim() != "")
            {
                string where = "select * from SysUser where " + GetPinyinWhereString("Name", dName);
                this.PageState.Add("UsrList", DataHelper.QueryDictList(where));
            }
            else
            {
                ents = SysUserRule.FindAll(SearchCriterion);
                this.PageState.Add("UsrList", ents);
            }
            if (this.IsAsyncRequest)
            {
                switch (this.RequestAction)
                {
                case RequestActionEnum.Custom:
                    if (RequestActionString == "querychildren")
                    {
                        string id    = (RequestData.ContainsKey("ID") ? RequestData["ID"].ToString() : String.Empty);
                        string ttype = RequestData["Type"].ToString().ToLower();

                        if (RequestData.ContainsKey("Type"))
                        {
                            if (ttype == "atype")      // 1为入口权限
                            {
                                SysAuth[] auths = SysAuth.FindAll("FROM SysAuth as ent WHERE ent.Type = ?", id);

                                this.PageState.Add("DtList", auths);
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            else
            {
                SysAuthType[] authTypeList = SysAuthTypeRule.FindAll();
                this.PageState.Add("DtList", authTypeList);
            }
        }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            switch (this.RequestAction)
            {
            case RequestActionEnum.Custom:
                if (RequestActionString == "querychildren")
                {
                    string id    = (RequestData.ContainsKey("ID") ? RequestData["ID"].ToString() : String.Empty);
                    string ttype = RequestData["Type"].ToString().ToLower();

                    if (RequestData.ContainsKey("Type"))
                    {
                        SysAuth[] ents = null;
                        if (ttype == "atype")      // 1为入口权限
                        {
                            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);
                        }

                        this.PageState.Add("DtList", ents.OrderBy(v => v.SortIndex).ThenBy(v => v.CreateDate));
                    }
                }
                else if (RequestActionString == "refreshsys")
                {
                    PortalService.RefreshSysModules();

                    SetMessage("操作成功!");
                }
                break;
            }

            if (!IsAsyncRequest)
            {
                SysAuthType[] authTypeList = SysAuthTypeRule.FindAll();

                this.PageState.Add("DtList", authTypeList);
            }
        }
Ejemplo n.º 8
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));
                }
            }
        }