feat: 添加注册功能

This commit is contained in:
橙子
2023-12-20 22:06:43 +08:00
parent ca60d4eb86
commit 2df46b0bf5
3 changed files with 1146 additions and 5 deletions

View File

@@ -54,7 +54,9 @@ namespace Yi.Framework.Rbac.Application.Services
ICaptcha captcha, ICaptcha captcha,
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
IOptions<RbacOptions> options, IOptions<RbacOptions> options,
IAliyunManger aliyunManger) IAliyunManger aliyunManger,
ISqlSugarRepository<RoleEntity> roleRepository,
UserManager userManager)
{ {
_userRepository = userRepository; _userRepository = userRepository;
_currentUser = currentUser; _currentUser = currentUser;
@@ -68,6 +70,8 @@ namespace Yi.Framework.Rbac.Application.Services
_guidGenerator = guidGenerator; _guidGenerator = guidGenerator;
_rbacOptions = options.Value; _rbacOptions = options.Value;
_aliyunManger = aliyunManger; _aliyunManger = aliyunManger;
_roleRepository = roleRepository;
_userManager = userManager;
} }
@@ -234,8 +238,8 @@ namespace Yi.Framework.Rbac.Application.Services
/// </summary> /// </summary>
private async Task ValidationPhoneCaptchaAsync(RegisterDto input) private async Task ValidationPhoneCaptchaAsync(RegisterDto input)
{ {
var value = await _phoneCache.GetAsync(new CaptchaPhoneCacheKey(input.Phone.ToString())); var item = await _phoneCache.GetAsync(new CaptchaPhoneCacheKey(input.Phone.ToString()));
if (value is not null && value.Equals($"{input.Code}")) if (item is not null && item.Code.Equals($"{input.Code}"))
{ {
//成功,需要清空 //成功,需要清空
await _phoneCache.RemoveAsync(new CaptchaPhoneCacheKey(input.Phone.ToString())); await _phoneCache.RemoveAsync(new CaptchaPhoneCacheKey(input.Phone.ToString()));
@@ -289,8 +293,7 @@ namespace Yi.Framework.Rbac.Application.Services
var entity = await _userRepository.InsertReturnEntityAsync(newUser); var entity = await _userRepository.InsertReturnEntityAsync(newUser);
//赋上一个初始角色 //赋上一个初始角色
var roleRepository = _roleRepository; var role = await _roleRepository.GetFirstAsync(x => x.RoleCode == UserConst.GuestRoleCode);
var role = await roleRepository.GetFirstAsync(x => x.RoleCode == UserConst.GuestRoleCode);
if (role is not null) if (role is not null)
{ {
await _userManager.GiveUserSetRoleAsync(new List<Guid> { entity.Id }, new List<Guid> { role.Id }); await _userManager.GiveUserSetRoleAsync(new List<Guid> { entity.Id }, new List<Guid> { role.Id });

View File

@@ -7,6 +7,7 @@ using Yi.Framework.Mapster;
using Yi.Framework.Rbac.Domain.Authorization; using Yi.Framework.Rbac.Domain.Authorization;
using Yi.Framework.Rbac.Domain.Operlog; using Yi.Framework.Rbac.Domain.Operlog;
using Yi.Framework.Rbac.Domain.Shared; using Yi.Framework.Rbac.Domain.Shared;
using Yi.Framework.Rbac.Domain.Shared.Options;
namespace Yi.Framework.Rbac.Domain namespace Yi.Framework.Rbac.Domain
{ {
@@ -22,11 +23,15 @@ namespace Yi.Framework.Rbac.Domain
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
var service = context.Services; var service = context.Services;
var configuration = context.Services.GetConfiguration();
service.AddControllers(options => service.AddControllers(options =>
{ {
options.Filters.Add<PermissionGlobalAttribute>(); options.Filters.Add<PermissionGlobalAttribute>();
options.Filters.Add<OperLogGlobalAttribute>(); options.Filters.Add<OperLogGlobalAttribute>();
}); });
//配置阿里云短信
Configure<AliyunOptions>(configuration.GetSection(nameof(AliyunOptions)));
} }
} }
} }

File diff suppressed because it is too large Load Diff