feat:区分配置文件

This commit is contained in:
橙子
2023-03-29 22:39:20 +08:00
parent d55caf2278
commit 769e2cb897
12 changed files with 125 additions and 32 deletions

View File

@@ -16,6 +16,12 @@
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.Production.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

View File

@@ -36,5 +36,12 @@
},
//开启种子数据
"EnabledDataSeed": true
"EnabledDataSeed": false,
//阿里云短信
"SmsAliyunOptions": {
"AccessKeyId": "",
"AccessKeySecret": "",
"SignName": ""
}
}

View File

@@ -16,6 +16,12 @@
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.Production.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

View File

@@ -36,5 +36,12 @@
},
//开启种子数据
"EnabledDataSeed": true
"EnabledDataSeed": false,
//阿里云短信
"SmsAliyunOptions": {
"AccessKeyId": "",
"AccessKeySecret": "",
"SignName": ""
}
}

View File

@@ -8,7 +8,8 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos.Account
{
public class CaptchaImageDto
{
public string Uuid { get; set; }=string.Empty;
public string Code { get; set; } = string.Empty;
public Guid Uuid { get; set; } = Guid.Empty;
public byte[] Img { get; set; }
}
}

View File

@@ -30,6 +30,7 @@ using Yi.RBAC.Domain.Shared.Identity.Dtos;
using Yi.RBAC.Domain.Shared.Identity.Etos;
using System.Net.WebSockets;
using Yi.Framework.Uow;
using Yi.Framework.Caching;
namespace Yi.RBAC.Application.Identity
{
@@ -67,6 +68,26 @@ namespace Yi.RBAC.Application.Identity
[Autowired]
private IRepository<RoleEntity> _roleRepository { get; set; }
[Autowired]
private CacheManager _cacheManager { get; set; }
/// <summary>
/// 效验图片登录验证码
/// </summary>
private void ValidationCaptcha()
{
}
/// <summary>
/// 效验电话验证码
/// </summary>
private void ValidationPhone()
{
}
/// <summary>
/// 登录
/// </summary>
@@ -74,6 +95,14 @@ namespace Yi.RBAC.Application.Identity
/// <returns></returns>
public async Task<object> PostLoginAsync(LoginInputVo input)
{
if (string.IsNullOrEmpty(input.Password) || string.IsNullOrEmpty(input.UserName))
{
throw new UserFriendlyException("请输入合理数据!");
}
//效验验证码
ValidationCaptcha();
UserEntity user = new();
//登录成功
await _accountManager.LoginValidationAsync(input.UserName, input.Password, x => user = x);
@@ -105,13 +134,15 @@ namespace Yi.RBAC.Application.Identity
/// 注册 手机验证码
/// </summary>
/// <returns></returns>
public async Task<object> PostPhoneCaptchaImage(PhoneCaptchaImageDto input)
public object PostPhoneCaptchaImage(PhoneCaptchaImageDto input)
{
var code = _securityCode.GetRandomEnDigitalText(4);
var uuid = Guid.NewGuid();
_cacheManager.Set($"Yi:Phone:{input.Phone}", $"{code}:{uuid}", new TimeSpan(0, 10, 0));
//生成一个4位数的验证码
//发送短信同时生成uuid
//key 电话号码 value:验证码+uuid
return new { uuid = Guid.NewGuid() };
return new { Uuid = uuid };
}
/// <summary>
@@ -130,19 +161,20 @@ namespace Yi.RBAC.Application.Identity
{
throw new UserFriendlyException("账号名需大于等于2位");
}
if (input.Password.Length<6)
if (input.Password.Length < 6)
{
throw new UserFriendlyException("密码需大于等于6位");
}
//效验验证码,根据电话号码获取 value比对验证码已经uuid
ValidationPhone();
//输入的用户名与电话号码都不能在数据库中存在
UserEntity user = new();
var isExist = await _userRepository.IsAnyAsync(x =>
x.UserName == input.UserName
|| x.Phone == input.Phone
|| x.UserName == input.Phone.ToString()
|| x.Phone.ToString() == input.UserName);
|| x.Phone == input.Phone);
if (isExist)
{
throw new UserFriendlyException("用户已存在,注册失败");
@@ -178,7 +210,7 @@ namespace Yi.RBAC.Application.Identity
//通过鉴权jwt获取到用户的id
var userId = _currentUser.Id;
//此处从缓存中获取即可
//var data = _cacheDb.Get<UserRoleMenuDto>($"Yi:UserInfo:{userId}");
//var data = _cacheManager.Get<UserRoleMenuDto>($"Yi:UserInfo:{userId}");
var data = await _userRepository.GetUserAllInfoAsync(userId);
//系统用户数据被重置,老前端访问重新授权
if (data is null)
@@ -233,9 +265,9 @@ namespace Yi.RBAC.Application.Identity
var code = _securityCode.GetRandomEnDigitalText(4);
//将uuid与codeRedis缓存中心化保存起来登录根据uuid比对即可
//10分钟过期
//_cacheDb.Set($"Yi:Captcha:{uuid}", code, new TimeSpan(0, 10, 0));
_cacheManager.Set($"Yi:Captcha:{code}", uuid, new TimeSpan(0, 10, 0));
var imgbyte = _securityCode.GetEnDigitalCodeByte(code);
return new CaptchaImageDto { Img = imgbyte, Uuid = code };
return new CaptchaImageDto { Img = imgbyte, Code = code, Uuid = uuid };
}
/// <summary>
@@ -271,9 +303,9 @@ namespace Yi.RBAC.Application.Identity
}
/// <summary>
/// 更新头像
/// 更新头像
/// </summary>
/// <param name="icon"></param>
/// <param name="input"></param>
/// <returns></returns>
public async Task<bool> UpdateIconAsync(UpdateIconDto input)
{

View File

@@ -4,6 +4,16 @@
<name>Yi.RBAC.Application</name>
</assembly>
<members>
<member name="M:Yi.RBAC.Application.Identity.AccountService.ValidationCaptcha">
<summary>
效验图片登录验证码
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.ValidationPhone">
<summary>
效验电话验证码
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.PostLoginAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.LoginInputVo)">
<summary>
登录
@@ -66,9 +76,9 @@
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.UpdateIconAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.UpdateIconDto)">
<summary>
更新头像
更新头像
</summary>
<param name="icon"></param>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.DeptService">

View File

@@ -16,10 +16,12 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\framework\Yi.Framework.Data\Yi.Framework.Data.csproj" />
<ProjectReference Include="..\..\..\module\Yi.Framework.Caching.MemoryCache\Yi.Framework.Caching.MemoryCache.csproj" />
<ProjectReference Include="..\..\..\module\Yi.Framework.DictionaryManager\Yi.Framework.DictionaryManager.csproj" />
<ProjectReference Include="..\..\..\module\Yi.Framework.EventBus\Yi.Framework.EventBus.csproj" />
<ProjectReference Include="..\..\..\module\Yi.Framework.FileManager\Yi.Framework.FileManager.csproj" />
<ProjectReference Include="..\..\..\module\Yi.Framework.OperLogManager\Yi.Framework.OperLogManager.csproj" />
<ProjectReference Include="..\..\..\module\Yi.Framework.Sms.Aliyun\Yi.Framework.Sms.Aliyun.csproj" />
<ProjectReference Include="..\..\..\module\Yi.Framework.ThumbnailSharp\Yi.Framework.ThumbnailSharp.csproj" />
<ProjectReference Include="..\Yi.RBAC.Domain.Shared\Yi.RBAC.Domain.Shared.csproj" />
</ItemGroup>

View File

@@ -9,10 +9,12 @@ using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Attributes;
using Yi.Framework.Data;
using Yi.Framework.Ddd;
using Yi.Framework.DictionaryManager;
using Yi.Framework.EventBus;
using Yi.Framework.FileManager;
using Yi.Framework.OperLogManager;
using Yi.Framework.Sms.Aliyun;
using Yi.Framework.ThumbnailSharp;
using Yi.RBAC.Domain.Logs;
using Yi.RBAC.Domain.Shared;
@@ -26,7 +28,9 @@ namespace Yi.RBAC.Domain
typeof(YiFrameworkEventBusModule),
typeof(YiFrameworkOperLogManagerModule),
typeof(YiFrameworkFileManagerModule),
typeof(YiFrameworkDictionaryManagerModule)
typeof(YiFrameworkDictionaryManagerModule),
typeof(YiFrameworkCachingMemoryCacheModule),
typeof(YiFrameworkSmsAliyunModule)
)]
public class YiRBACDomainModule : IStartupModule
{