Skip to content

Commit 315ea8d

Browse files
committed
更新1.3.1
新增 接口、服务和仓储测试 新增 Ip限流,支持内存和Redis缓存 新增 权限管理增加权限编码字段,接口表单增加权限编码保存 新增 权限指令v-permission="'权限编码'" 或 v-permission="{ permission: '权限编码', disabled:true }" 新增 权限检查方法v-if="checkPermission('权限编码')" 修复 高级查询窗口点击关闭图标按钮,无法再打开高级查询窗口
1 parent 4686a92 commit 315ea8d

32 files changed

+520
-76
lines changed

Admin.Core.Common/Admin.Core.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.4" />
3434
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.4" />
3535
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.4" />
36-
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.5.1" />
36+
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.6.0" />
3737
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
38-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.5.1" />
38+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.6.0" />
3939
<PackageReference Include="UAParser" Version="3.1.44" />
4040
</ItemGroup>
4141

Admin.Core.Common/Configs/AppConfig.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public class AppConfig
2525
/// </summary>
2626
public LogConfig Log { get; set; } = new LogConfig();
2727

28+
/// <summary>
29+
/// 限流
30+
/// </summary>
31+
public bool RateLimit { get; set; } = true;
32+
2833
/// <summary>
2934
/// 验证码配置
3035
/// </summary>
@@ -58,6 +63,11 @@ public class LogConfig
5863
/// </summary>
5964
public class VarifyCodeConfig
6065
{
66+
/// <summary>
67+
/// 启用
68+
/// </summary>
69+
public bool Enabled { get; set; } = true;
70+
6171
/// <summary>
6272
/// 操作日志
6373
/// </summary>

Admin.Core.Common/Configs/CacheConfig.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public class CacheConfig
1414
/// </summary>
1515
public CacheType Type { get; set; } = CacheType.Memory;
1616

17+
/// <summary>
18+
/// 限流缓存类型
19+
/// </summary>
20+
public CacheType TypeRateLimit { get; set; } = CacheType.Memory;
21+
1722
/// <summary>
1823
/// Redis配置
1924
/// </summary>
@@ -29,5 +34,10 @@ public class RedisConfig
2934
/// 连接字符串
3035
/// </summary>
3136
public string ConnectionString { get; set; } = "127.0.0.1:6379,password=,defaultDatabase=2";
37+
38+
/// <summary>
39+
/// 限流连接字符串
40+
/// </summary>
41+
public string ConnectionStringRateLimit { get; set; } = "127.0.0.1:6379,password=,defaultDatabase=1";
3242
}
3343
}

Admin.Core.Common/Helpers/ConfigHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public IConfiguration Load(string fileName, string environmentName = "", bool re
3939

4040
if (environmentName.NotNull())
4141
{
42-
builder.AddJsonFile(fileName.ToLower() + "." + environmentName + ".json", true, reloadOnChange);
42+
builder.AddJsonFile(fileName.ToLower() + "." + environmentName + ".json", optional: true, reloadOnChange: reloadOnChange);
4343
}
4444

4545
return builder.Build();

Admin.Core.Common/Helpers/HtmlHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Admin.Core.Common.Helpers
1515
public class HtmlHelper
1616
{
1717
#region 私有字段
18-
private readonly string _ContentType = "application/x-www-form-urlencoded";
18+
private readonly string _ContentType = "application/json";
1919
private readonly string _Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
2020
private readonly string _UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
2121
private int _Delay = 1000;
@@ -144,15 +144,15 @@ public string GetHtml(string url, CookieContainer cookieContainer)
144144
#endregion
145145

146146
#region 获取字符流
147-
/// <summary>
148-
/// 获取字符流
149-
/// </summary>
150147
//---------------------------------------------------------------------------------------------------------------
151148
// 示例:
152149
// System.Net.CookieContainer cookie = new System.Net.CookieContainer();
153150
// Stream s = HttpHelper.GetStream("http://ptlogin2.qq.com/getimage?aid=15000102&0.43878429697395826", cookie);
154151
// picVerify.Image = Image.FromStream(s);
155152
//---------------------------------------------------------------------------------------------------------------
153+
/// <summary>
154+
/// 获取字符流
155+
/// </summary>
156156
/// <param name="url">地址</param>
157157
/// <param name="cookieContainer">cookieContainer</param>
158158
public Stream GetStream(string url, CookieContainer cookieContainer)

Admin.Core.Model/Admin/PermissionEntity.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public class PermissionEntity : EntityBase
2121
[Column(StringLength = 50)]
2222
public string Label { get; set; }
2323

24+
/// <summary>
25+
/// 权限编码
26+
/// </summary>
27+
[Column(StringLength = 550)]
28+
public string Code { get; set; }
29+
2430
/// <summary>
2531
/// 权限类型
2632
/// </summary>

Admin.Core.Services/Admin/Auth/AuthService.cs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System;
22
using System.Linq;
33
using System.Threading.Tasks;
4+
using AutoMapper;
45
using Admin.Core.Model.Admin;
56
using Admin.Core.Common.Output;
67
using Admin.Core.Repository.Admin;
7-
using Admin.Core.Common.Helpers;
88
using Admin.Core.Common.Auth;
99
using Admin.Core.Common.Cache;
10+
using Admin.Core.Common.Configs;
11+
using Admin.Core.Common.Helpers;
1012
using Admin.Core.Service.Admin.Auth.Input;
11-
using AutoMapper;
1213
using Admin.Core.Service.Admin.Auth.Output;
1314

1415
namespace Admin.Core.Service.Admin.Auth
@@ -18,6 +19,7 @@ public class AuthService : IAuthService
1819
private readonly IUser _user;
1920
private readonly ICache _cache;
2021
private readonly IMapper _mapper;
22+
private readonly AppConfig _appConfig;
2123
private readonly VerifyCodeHelper _verifyCodeHelper;
2224
private readonly IUserRepository _userRepository;
2325
private readonly IPermissionRepository _permissionRepository;
@@ -26,6 +28,7 @@ public AuthService(
2628
IUser user,
2729
ICache cache,
2830
IMapper mapper,
31+
AppConfig appConfig,
2932
VerifyCodeHelper verifyCodeHelper,
3033
IUserRepository userRepository,
3134
IPermissionRepository permissionRepository
@@ -34,6 +37,7 @@ IPermissionRepository permissionRepository
3437
_user = user;
3538
_cache = cache;
3639
_mapper = mapper;
40+
_appConfig = appConfig;
3741
_verifyCodeHelper = verifyCodeHelper;
3842
_userRepository = userRepository;
3943
_permissionRepository = permissionRepository;
@@ -42,24 +46,27 @@ IPermissionRepository permissionRepository
4246
public async Task<IResponseOutput> LoginAsync(AuthLoginInput input)
4347
{
4448
#region 验证码校验
45-
var verifyCodeKey = string.Format(CacheKey.VerifyCodeKey, input.VerifyCodeKey);
46-
var exists = await _cache.ExistsAsync(verifyCodeKey);
47-
if (exists)
49+
if (_appConfig.VarifyCode.Enabled)
4850
{
49-
var verifyCode = await _cache.GetAsync(verifyCodeKey);
50-
if (string.IsNullOrEmpty(verifyCode))
51+
var verifyCodeKey = string.Format(CacheKey.VerifyCodeKey, input.VerifyCodeKey);
52+
var exists = await _cache.ExistsAsync(verifyCodeKey);
53+
if (exists)
5154
{
52-
return ResponseOutput.NotOk("验证码已过期!", 1);
55+
var verifyCode = await _cache.GetAsync(verifyCodeKey);
56+
if (string.IsNullOrEmpty(verifyCode))
57+
{
58+
return ResponseOutput.NotOk("验证码已过期!", 1);
59+
}
60+
if (verifyCode.ToLower() != input.VerifyCode.ToLower())
61+
{
62+
return ResponseOutput.NotOk("验证码输入有误!", 2);
63+
}
64+
await _cache.DelAsync(verifyCodeKey);
5365
}
54-
if (verifyCode.ToLower() != input.VerifyCode.ToLower())
66+
else
5567
{
56-
return ResponseOutput.NotOk("验证码输入有误!", 2);
68+
return ResponseOutput.NotOk("验证码已过期!", 1);
5769
}
58-
await _cache.DelAsync(verifyCodeKey);
59-
}
60-
else
61-
{
62-
return ResponseOutput.NotOk("验证码已过期!", 1);
6370
}
6471
#endregion
6572

@@ -143,7 +150,17 @@ public async Task<IResponseOutput> GetUserInfoAsync()
143150
a.External
144151
});
145152

146-
return ResponseOutput.Ok(new { user, menus });
153+
var permissions = await _permissionRepository.Select
154+
.Where(a => a.Type == PermissionType.Api)
155+
.Where(a =>
156+
_permissionRepository.Orm.Select<RolePermissionEntity>()
157+
.InnerJoin<UserRoleEntity>((b, c) => b.RoleId == c.RoleId && c.UserId == _user.Id)
158+
.Where(b => b.PermissionId == a.Id)
159+
.Any()
160+
)
161+
.ToListAsync(a => a.Code);
162+
163+
return ResponseOutput.Ok(new { user, menus, permissions });
147164
}
148165

149166
public async Task<IResponseOutput> GetVerifyCodeAsync(string lastKey)
@@ -161,8 +178,7 @@ public async Task<IResponseOutput> GetVerifyCodeAsync(string lastKey)
161178
var key = string.Format(CacheKey.VerifyCodeKey, guid);
162179
await _cache.SetAsync(key, code, TimeSpan.FromMinutes(5));
163180

164-
var data = new { key = guid, img };
165-
181+
var data = new AuthGetVerifyCodeOutput { Key = guid, Img = img };
166182
return ResponseOutput.Ok(data);
167183
}
168184

Admin.Core.Services/Admin/Auth/Input/AuthLoginInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class AuthLoginInput
2727
/// <summary>
2828
/// 验证码
2929
/// </summary>
30-
[Required(ErrorMessage = "验证码不能为空!")]
30+
//[Required(ErrorMessage = "验证码不能为空!")]
3131
public string VerifyCode { get; set; }
3232

3333
/// <summary>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace Admin.Core.Service.Admin.Auth.Output
4+
{
5+
public class AuthGetVerifyCodeOutput
6+
{
7+
/// <summary>
8+
/// 缓存键
9+
/// </summary>
10+
public string Key { get; set; }
11+
12+
/// <summary>
13+
/// 图片
14+
/// </summary>
15+
public string Img { get; set; }
16+
}
17+
}

Admin.Core.Services/Admin/LoginLog/LoginLogService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ public async Task<IResponseOutput<long>> AddAsync(LoginLogAddInput input)
5454
input.IP = IPHelper.GetIP(_context?.HttpContext?.Request);
5555

5656
string ua = _context.HttpContext.Request.Headers["User-Agent"];
57-
var client = UAParser.Parser.GetDefault().Parse(ua);
58-
var device = client.Device.Family;
59-
device = device.ToLower() == "other" ? "" : device;
60-
input.Browser = client.UA.Family;
61-
input.Os = client.OS.Family;
62-
input.Device = device;
63-
input.BrowserInfo = ua;
64-
57+
if (ua.NotNull())
58+
{
59+
var client = UAParser.Parser.GetDefault().Parse(ua);
60+
var device = client.Device.Family;
61+
device = device.ToLower() == "other" ? "" : device;
62+
input.Browser = client.UA.Family;
63+
input.Os = client.OS.Family;
64+
input.Device = device;
65+
input.BrowserInfo = ua;
66+
}
6567
var entity = _mapper.Map<LoginLogEntity>(input);
6668
var id = (await _loginLogRepository.InsertAsync(entity)).Id;
6769

0 commit comments

Comments
 (0)