Ejemplo n.º 1
0
        /// <summary>
        /// 进行注册
        /// </summary>
        /// <returns></returns>
        public bool DoReg()
        {
            //检查两次新密码是否输入一致,如不一致则输出错误
            if (Password != NewPasswordComfirm)
            {
                MSD.AddModelError("NewPasswordComfirm", Localizer["PasswordNotSame"]);
                return(false);
            }


            //检查itcode是否重复
            var exist = DC.Set <FrameworkUserBase>().Any(x => x.ITCode.ToLower() == ITCode.ToLower());

            if (exist == true)
            {
                MSD.AddModelError("ITCode", "账号重复");
                return(false);
            }

            FrameworkUserBase user = new FrameworkUserBase
            {
                ITCode    = ITCode,
                Name      = Name,
                Password  = Utils.GetMD5String(Password),
                IsValid   = true,
                CellPhone = CellPhone,
                Email     = Email
            };

            DC.Set <FrameworkUserBase>().Add(user);
            DC.SaveChanges();
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 进行登录
        /// </summary>
        /// <param name="OutsidePris">外部传递的页面权限</param>
        /// <returns>登录用户的信息</returns>
        public LoginUserInfo DoLogin(bool ignorePris = false)
        {
            //根据用户名和密码查询用户
            var user = DC.Set <MyUser>()
                       .Include(x => x.UserRoles).Include(x => x.UserGroups)
                       .Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid)
                       .SingleOrDefault();

            //如果没有找到则输出错误
            if (user == null)
            {
                MSD.AddModelError("", "登录失败");
                return(null);
            }
            var roleIDs  = user.UserRoles.Select(x => x.RoleId).ToList();
            var groupIDs = user.UserGroups.Select(x => x.GroupId).ToList();

            var sDictionary = new Dictionary <string, object>();

            sDictionary.Add("CompanyId", user.CompanyId);


            //查找登录用户的数据权限
            var dpris = DC.Set <DataPrivilege>()
                        .Where(x => x.UserId == user.ID || (x.GroupId != null && groupIDs.Contains(x.GroupId.Value)))
                        .ToList();
            //查找登录用户的公司信息
            var company = DC.Set <Company>().Where(x => x.ID == user.CompanyId).SingleOrDefault();

            if (company != null)
            {
                sDictionary.Add("CompanyCode", company.CompanyCode);
            }


            //生成并返回登录用户信息
            LoginUserInfo rv = new LoginUserInfo
            {
                Id             = user.ID,
                ITCode         = user.ITCode,
                Name           = user.Name,
                PhotoId        = user.PhotoId,
                Roles          = DC.Set <FrameworkRole>().Where(x => user.UserRoles.Select(y => y.RoleId).Contains(x.ID)).ToList(),
                Groups         = DC.Set <FrameworkGroup>().Where(x => user.UserGroups.Select(y => y.GroupId).Contains(x.ID)).ToList(),
                DataPrivileges = dpris,
                Attributes     = sDictionary
            };

            if (ignorePris == false)
            {
                //查找登录用户的页面权限
                var pris = DC.Set <FunctionPrivilege>()
                           .Where(x => x.UserId == user.ID || (x.RoleId != null && roleIDs.Contains(x.RoleId.Value)))
                           .ToList();
                rv.FunctionPrivileges = pris;
            }
            return(rv);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 修改密码
        /// </summary>
        public void DoChange()
        {
            var user = DC.Set <FrameworkUser>().Where(x => x.ITCode.ToLower() == ITCode.ToLower()).SingleOrDefault();

            if (user != null)
            {
                user.Password = NewPassword;
            }
            DC.SaveChanges();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 自定义验证函数,验证原密码是否正确,并验证两次新密码是否输入一致
        /// </summary>
        /// <param name="validationContext">验证环境</param>
        /// <returns>验证结果</returns>
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> rv = new List <ValidationResult>();

            //检查原密码是否正确,如不正确则输出错误
            if (DC.Set <FrameworkUser>().Where(x => x.ITCode.ToLower() == ITCode.ToLower()).Select(x => x.Password).SingleOrDefault() != OldPassword)
            {
                rv.Add(new ValidationResult(Language.CurrentPasswordWrong, new[] { "OldPassword" }));
            }
            //检查两次新密码是否输入一致,如不一致则输出错误
            if (NewPassword != NewPasswordComfirm)
            {
                rv.Add(new ValidationResult(Language.ConfirmedPasswordWrong, new[] { "NewPasswordComfirm" }));
            }
            return(rv);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 进行登录
        /// </summary>
        /// <param name="ignorePris">外部传递的页面权限</param>
        /// <returns>登录用户的信息</returns>
        public LoginUserInfo DoLogin(bool ignorePris = false)
        {
            //根据用户名和密码查询用户
            var user = DC.Set <FrameworkUserBase>()
                       .Include(x => x.UserRoles).Include(x => x.UserGroups)
                       .Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid)
                       .SingleOrDefault();

            //如果没有找到则输出错误
            if (user == null)
            {
                MSD.AddModelError("", "登录失败");
                return(null);
            }
            var roleIDs  = user.UserRoles.Select(x => x.RoleId).ToList();
            var groupIDs = user.UserGroups.Select(x => x.GroupId).ToList();
            //查找登录用户的数据权限
            var dpris = DC.Set <DataPrivilege>().AsNoTracking()
                        .Where(x => x.UserId == user.ID || (x.GroupId != null && groupIDs.Contains(x.GroupId.Value)))
                        .Distinct()
                        .ToList();

            ProcessTreeDp(dpris);
            //生成并返回登录用户信息
            LoginUserInfo rv = new LoginUserInfo
            {
                Id             = user.ID,
                ITCode         = user.ITCode,
                Name           = user.Name,
                PhotoId        = user.PhotoId,
                Roles          = DC.Set <FrameworkRole>().Where(x => roleIDs.Contains(x.ID)).ToList(),
                Groups         = DC.Set <FrameworkGroup>().Where(x => groupIDs.Contains(x.ID)).ToList(),
                DataPrivileges = dpris
            };

            if (ignorePris == false)
            {
                //查找登录用户的页面权限
                var pris = DC.Set <FunctionPrivilege>().AsNoTracking()
                           .Where(x => x.UserId == user.ID || (x.RoleId != null && roleIDs.Contains(x.RoleId.Value)))
                           .Distinct()
                           .ToList();
                rv.FunctionPrivileges = pris;
            }
            return(rv);
        }
Ejemplo n.º 6
0
        public LoginUserInfo DoLogin(bool ignorePris = false)
        {
            var user = DC.Set <FrameworkUserBase>()
                       .Include(x => x.UserRoles).Include(x => x.UserGroups)
                       .Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid)
                       .SingleOrDefault();

            if (user == null)
            {
                MSD.AddModelError("", Localizer["LoginFail"]);
                return(null);
            }
            var roleIDs  = user.UserRoles.Select(x => x.RoleId).ToList();
            var groupIDs = user.UserGroups.Select(x => x.GroupId).ToList();
            var dpris    = DC.Set <DataPrivilege>()
                           .Where(x => x.UserId == user.ID || (x.GroupId != null && groupIDs.Contains(x.GroupId.Value)))
                           .Distinct()
                           .ToList();

            ProcessTreeDp(dpris);
            LoginUserInfo rv = new LoginUserInfo
            {
                Id             = user.ID,
                ITCode         = user.ITCode,
                Name           = user.Name,
                PhotoId        = user.PhotoId,
                Roles          = DC.Set <FrameworkRole>().Where(x => user.UserRoles.Select(y => y.RoleId).Contains(x.ID)).ToList(),
                Groups         = DC.Set <FrameworkGroup>().Where(x => user.UserGroups.Select(y => y.GroupId).Contains(x.ID)).ToList(),
                DataPrivileges = dpris
            };

            if (ignorePris == false)
            {
                var pris = DC.Set <FunctionPrivilege>()
                           .Where(x => x.UserId == user.ID || (x.RoleId != null && roleIDs.Contains(x.RoleId.Value)))
                           .Distinct()
                           .ToList();
                rv.FunctionPrivileges = pris;
            }
            return(rv);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 进行登录
        /// </summary>
        /// <param name="OutsidePris">外部传递的页面权限</param>
        /// <returns>登录用户的信息</returns>
        public LoginUserInfo DoLogin(bool IgnorePris = false)
        {
            //根据用户名和密码查询用户
            var user = DC.Set <FrameworkUser>()
                       .Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password.ToLower() == Password.ToLower() && x.IsValid == true)
                       .Include(x => x.Roles)
                       .Include(x => x.Department.Company)
                       .SingleOrDefault();

            //如果没有找到则输出错误
            if (user == null)
            {
                MSD.AddModelError("", Language.LogonFail);
                return(null);
            }

            var roleIDs = user.Roles.Select(x => x.ID).ToList();
            //查找登录用户的数据权限
            var dpris = DC.Set <DataPrivilege>()
                        .Where(x => x.UserID == user.ID && x.DomainID == null)
                        .ToList();
            //生成并返回登录用户信息
            LoginUserInfo rv = new LoginUserInfo();

            rv.ID             = user.ID;
            rv.ITCode         = user.ITCode;
            rv.Name           = user.Name;
            rv.Roles          = user.Roles;
            rv.DataPrivileges = dpris;
            if (IgnorePris == false)
            {
                //查找登录用户的页面权限
                var pris = DC.Set <FunctionPrivilege>()
                           .Where(x => x.UserID == user.ID || (x.RoleID != null && roleIDs.Contains(x.RoleID.Value)))
                           .ToList();
                rv.FunctionPrivileges = pris;
            }
            return(rv);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 进行登录
        /// </summary>
        /// <param name="ignorePris">外部传递的页面权限</param>
        /// <returns>登录用户的信息</returns>
        public async System.Threading.Tasks.Task <LoginUserInfo> DoLoginAsync(bool ignorePris = false)
        {
            //根据用户名和密码查询用户
            var rv = await DC.Set <FrameworkUser>().Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid).Select(x => new { itcode = x.ITCode, id = x.GetID() }).SingleOrDefaultAsync();

            //如果没有找到则输出错误
            if (rv == null)
            {
                MSD.AddModelError("", Localizer["Sys.LoginFailed"]);
                return(null);
            }
            else
            {
                LoginUserInfo user = new LoginUserInfo
                {
                    ITCode = rv.itcode,
                    UserId = rv.id.ToString()
                };
                //读取角色,用户组,页面权限,数据权限等框架配置信息
                await user.LoadBasicInfoAsync(Wtm);

                return(user);
            }
        }
Ejemplo n.º 9
0
        }                                     ///用户绑定的Mac地址和硬盘序列号


        //[Display(Name = "验证码")]
        //public string VerifyCode { get; set; }

        /// <summary>
        /// 进行登录
        /// </summary>
        /// <param name="ignorePris">外部传递的页面权限</param>
        /// <returns>登录用户的信息</returns>
        public LoginUserInfo DoLogin(bool ignorePris = false)
        {
            //根据用户名和密码查询用户
            var user = DC.Set <Admin>()
                       .Include(x => x.UserRoles).Include(x => x.UserGroups)
                       .Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid)
                       .SingleOrDefault();

            //如果没有找到则输出错误
            if (user == null)
            {
                MSD.AddModelError("", "登录失败");
                return(null);
            }

            var organ     = DC.Set <Organ>().SingleOrDefault(x => x.ID == user.OrganId);
            var checkbind = false;

            if (user.MAC == null || user.MAC == "")
            {
                checkbind = true;
            }
            else
            {
                if (user.MAC.Contains(MacDid))
                {
                    checkbind = true;
                }
                else
                {
                    checkbind = false;
                }
            }
            if (checkbind)
            {
                var roleIDs  = user.UserRoles.Select(x => x.RoleId).ToList();
                var groupIDs = user.UserGroups.Select(x => x.GroupId).ToList();
                //查找登录用户的数据权限
                var dpris = DC.Set <DataPrivilege>()
                            .Where(x => x.UserId == user.ID || (x.GroupId != null && groupIDs.Contains(x.GroupId.Value)))
                            .Distinct()
                            .ToList();

                //生成并返回登录用户信息
                LoginUserInfo rv = new LoginUserInfo
                {
                    Id             = user.ID,
                    ITCode         = user.ITCode,
                    Name           = user.Name,
                    Memo           = organ.OrganCode,
                    PhotoId        = user.PhotoId,
                    Roles          = DC.Set <FrameworkRole>().Where(x => user.UserRoles.Select(y => y.RoleId).Contains(x.ID)).ToList(),
                    Groups         = DC.Set <FrameworkGroup>().Where(x => user.UserGroups.Select(y => y.GroupId).Contains(x.ID)).ToList(),
                    DataPrivileges = dpris
                };
                if (ignorePris == false)
                {
                    //查找登录用户的页面权限
                    var pris = DC.Set <FunctionPrivilege>()
                               .Where(x => x.UserId == user.ID || (x.RoleId != null && roleIDs.Contains(x.RoleId.Value)))
                               .Distinct()
                               .ToList();
                    rv.FunctionPrivileges = pris;
                }
                return(rv);
            }
            else
            {
                MSD.AddModelError("", "您的电脑无登录权限");
                return(null);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 进行登录
        /// </summary>
        /// <param name="ignorePris">外部传递的页面权限</param>
        /// <returns>登录用户的信息</returns>
        public async System.Threading.Tasks.Task <LoginUserInfo> DoLoginAsync(bool ignorePris = false)
        {
            //根据用户名和密码查询用户
            string code = await DC.Set <FrameworkUser>().Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password)).Select(x => x.ITCode).SingleOrDefaultAsync();

            //如果没有找到则输出错误
            if (string.IsNullOrEmpty(code))
            {
                MSD.AddModelError("", Localizer["Sys.LoginFailed"]);
                return(null);
            }
            else
            {
                LoginUserInfo user = new LoginUserInfo
                {
                    ITCode = code
                };
                //读取角色,用户组,页面权限,数据权限等框架配置信息
                await user.LoadBasicInfoAsync(Wtm);

                return(user);
            }
        }