Esempio n. 1
0
        /// <summary>
        /// 数据库基础表数据导出到json文件
        /// </summary>
        /// <param name="tableName">指定表名称</param>
        /// <param name="path">存放路径</param>
        /// <returns></returns>
        public async Task <string> ExportTable(string tableName, string path)
        {
            string outPaths = string.Empty;
            Dictionary <string, string> dic = new Dictionary <string, string>();

            switch (tableName.ToLower())
            {
            case "user":
                dic.Add(typeof(User).Name, JsonHelper.JSON(await _userSvc.Query()));
                break;

            case "dept":
                dic.Add(typeof(Dept).Name, JsonHelper.JSON(await _deptSvc.Query()));
                break;

            case "role":
                dic.Add(typeof(Role).Name, JsonHelper.JSON(await _roleSvc.Query()));
                break;

            case "menu":
                dic.Add(typeof(Menu).Name, JsonHelper.JSON(await _menuSvc.Query()));
                break;

            case "tasksqz":
                dic.Add(typeof(TasksQz).Name, JsonHelper.JSON(await _tasksQzSvc.Query()));
                break;

            default:
                dic.Add(typeof(User).Name, JsonHelper.JSON(await _userSvc.Query()));
                dic.Add(typeof(Dept).Name, JsonHelper.JSON(await _deptSvc.Query()));
                dic.Add(typeof(Role).Name, JsonHelper.JSON(await _roleSvc.Query()));
                dic.Add(typeof(Menu).Name, JsonHelper.JSON(await _menuSvc.Query()));
                dic.Add(typeof(TasksQz).Name, JsonHelper.JSON(await _tasksQzSvc.Query()));
                break;
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            foreach (var item in dic)
            {
                string filePath = Path.Combine(path, $@"{item.Key}.json");

                using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    fs.SetLength(0); //清空文件内容
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
                    {
                        sw.WriteLine(item.Value);
                    }
                }

                outPaths += $"表{item.Key}-数据生成:{filePath} || ";
            }
            return(outPaths[0..^ 4]);
Esempio n. 2
0
        public async Task <object> PostUser([FromBody] User model)
        {
            var data = new MessageModel <User>()
            {
                Message = "添加成功", Success = true
            };

            //model.LoginPwd = MD5Helper.MD5Encrypt32(model.LoginPwd);
            var dataList = await _userSvc.Query(a => a.LoginName == model.LoginName);

            if (dataList.Count > 0)
            {
                data.Message = "该用户名称已存在";
                data.Success = false;
            }
            else
            {
                model.Id = await _userSvc.Add(model);

                data.Response = model;
            }

            return(data);
        }
Esempio n. 3
0
        public async Task <object> GetJwtToken(string name = "", string pass = "")
        {
            string jwtStr = string.Empty;

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pass))
            {
                return(new JsonResult(new
                {
                    Status = false,
                    message = "用户名或密码不能为空"
                }));
            }

            if (RSACryption.IsBase64(pass))
            {
                pass = RSACryption.RSADecrypt(pass);
            }

            var user = (await _userSvc.Query(d => d.Enabled == false && d.LoginName == name && d.LoginPwd == pass)).FirstOrDefault();

            if (user != null)
            {
                var userRoles = await _roleSvc.GetDataByids(user.RoleIds);

                //如果是基于用户的授权策略,这里要添加用户;如果是基于角色的授权策略,这里要添加角色
                var claims = new List <Claim> {
                    new Claim(ClaimTypes.Name, name),
                    new Claim(JwtRegisteredClaimNames.Jti, user.Id.ToString()),
                    new Claim(ClaimTypes.Expiration, DateTime.Now.AddSeconds(_requirement.Expiration.TotalSeconds).ToString())
                };
                claims.AddRange(userRoles.Select(s => new Claim(ClaimTypes.Role, s.RoleName)));

                //var data = await _roleModulePermissionServices.RoleModuleMaps();
                //var list = (from item in data
                //            where item.IsDeleted == false
                //            orderby item.Id
                //            select new PermissionItem
                //            {
                //                Url = item.Module?.LinkUrl,
                //                Role = item.Role?.Name,
                //            }).ToList();

                //_requirement.Permissions = list;

                // ids4和jwt切换
                // jwt
                if (!Permissions.IsUseIds4)
                {
                    _requirement.Permissions = (from item in userRoles
                                                orderby item.Id
                                                select new PermissionItem
                    {
                        Url = "",
                        Role = item?.RoleName
                    }).ToList();
                }

                //用户标识
                // var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
                // identity.AddClaims(claims);

                var token = JwtToken.BuildJwtToken(claims.ToArray(), _requirement);
                return(new JsonResult(token));
            }
            else
            {
                return(new JsonResult(new
                {
                    success = false,
                    message = "认证失败"
                }));
            }
        }