Exemplo n.º 1
0
        /// <summary>
        /// 登录验证帐号和密码
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userPwd"></param>
        /// <returns></returns>
        public async Task <Tuple <OpResult <string>, SysUser> > VerifyPassword(string userId, string userPwd)
        {
            var userInfo = await _iSysUserRepository.QueryBySql($"select * from SysUser where UserId='{userId}' and UserPwd='{userPwd}' and UserStatus=1");//验证用户id和密码

            var sysUser = userInfo.FirstOrDefault();

            if (sysUser != null)
            {
                var roleList     = _iSysUserRoleRepository.QueryBySql($"SELECT * from SysUserRole where SysUserId='{sysUser.SysUserId}'").Result.Select(x => x.SysRoleId).ToList();                  //获取用户角色
                var roleNameList = _iSysRoleRepository.QueryAsNoTracking(x => roleList.Contains(x.SysRoleId) && x.IsDelete != true && x.RoleStatus == true).Result.Select(x => x.RoleName).ToList(); //获取用户角色名称
                var roleName     = string.Join(',', roleNameList);
                return(new Tuple <OpResult <string>, SysUser>(new OpResult <string>(OpResultType.Success, roleName), sysUser));
            }

            return(new Tuple <OpResult <string>, SysUser>(new OpResult <string>(OpResultType.AuthInvalid, "帐号或密码不正确!"), sysUser));
        }