feat:区分配置文件
This commit is contained in:
@@ -4,12 +4,24 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AlibabaCloud.SDK.Dysmsapi20170525;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Tea;
|
||||
|
||||
namespace Yi.Framework.Sms.Aliyun
|
||||
{
|
||||
public class SmsAliyunManager
|
||||
{
|
||||
public Client AliyunClient { get; set; }
|
||||
private ILogger<SmsAliyunManager> _logger;
|
||||
private SmsAliyunOptions Options { get; set; }
|
||||
public SmsAliyunManager(ILogger<SmsAliyunManager> logger,IOptions<SmsAliyunOptions> options)
|
||||
{
|
||||
_logger = logger;
|
||||
AliyunClient = CreateClient(Options.AccessKeyId, Options.AccessKeySecret);
|
||||
Options = options.Value;
|
||||
}
|
||||
|
||||
private static Client CreateClient(string accessKeyId, string accessKeySecret)
|
||||
{
|
||||
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
|
||||
@@ -24,12 +36,13 @@ namespace Yi.Framework.Sms.Aliyun
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
public Client AliyunClient { get; set; }
|
||||
public SmsAliyunManager() {
|
||||
|
||||
AliyunClient = CreateClient("accessKeyId", "accessKeySecret");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送短信
|
||||
/// </summary>
|
||||
/// <param name="phoneNumbers"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Send(string phoneNumbers, string code)
|
||||
{
|
||||
try
|
||||
@@ -37,21 +50,17 @@ namespace Yi.Framework.Sms.Aliyun
|
||||
AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsRequest sendSmsRequest = new AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsRequest
|
||||
{
|
||||
PhoneNumbers = phoneNumbers,
|
||||
SignName = "",
|
||||
SignName = Options.SignName,
|
||||
TemplateCode = code,
|
||||
};
|
||||
|
||||
var response= await AliyunClient.SendSmsAsync(sendSmsRequest);
|
||||
var response = await AliyunClient.SendSmsAsync(sendSmsRequest);
|
||||
}
|
||||
catch (TeaException error)
|
||||
{
|
||||
|
||||
Console.WriteLine(error.Message);
|
||||
}
|
||||
catch (Exception _error)
|
||||
{
|
||||
Console.WriteLine(_error.Message);
|
||||
_logger.LogError(_error, _error.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,9 @@ namespace Yi.Framework.Sms.Aliyun
|
||||
{
|
||||
public class SmsAliyunOptions
|
||||
{
|
||||
public string AccessKeyId { get; set; }
|
||||
public string AccessKeySecret { get; set; }
|
||||
|
||||
public string SignName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StartupModules;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Core.Attributes;
|
||||
using Yi.Framework.Core.Configuration;
|
||||
|
||||
namespace Yi.Framework.Sms.Aliyun
|
||||
{
|
||||
[DependsOn(typeof(YiFrameworkCoreModule))]
|
||||
public class YiFrameworkSmsAliyunModule : IStartupModule
|
||||
{
|
||||
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
|
||||
@@ -13,7 +17,8 @@ namespace Yi.Framework.Sms.Aliyun
|
||||
|
||||
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
|
||||
{
|
||||
|
||||
services.Configure<SmsAliyunOptions>(Appsettings.appConfiguration("SmsAliyunOptions"));
|
||||
services.AddSingleton<SmsAliyunManager>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -36,5 +36,12 @@
|
||||
},
|
||||
|
||||
//开启种子数据
|
||||
"EnabledDataSeed": true
|
||||
"EnabledDataSeed": false,
|
||||
|
||||
//阿里云短信
|
||||
"SmsAliyunOptions": {
|
||||
"AccessKeyId": "",
|
||||
"AccessKeySecret": "",
|
||||
"SignName": ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -36,5 +36,12 @@
|
||||
},
|
||||
|
||||
//开启种子数据
|
||||
"EnabledDataSeed": true
|
||||
"EnabledDataSeed": false,
|
||||
|
||||
//阿里云短信
|
||||
"SmsAliyunOptions": {
|
||||
"AccessKeyId": "",
|
||||
"AccessKeySecret": "",
|
||||
"SignName": ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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与code,Redis缓存中心化保存起来,登录根据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)
|
||||
{
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user