diff --git a/src/LinCms.Application.Contracts/Cms/Account/RegisterDto.cs b/src/LinCms.Application.Contracts/Cms/Account/RegisterDto.cs index efaaca55..15368d2a 100644 --- a/src/LinCms.Application.Contracts/Cms/Account/RegisterDto.cs +++ b/src/LinCms.Application.Contracts/Cms/Account/RegisterDto.cs @@ -6,13 +6,6 @@ namespace LinCms.Cms.Account; public class RegisterEmailCodeInput : IValidatableObject { - /// - /// 昵称 - /// - [StringLength(10, MinimumLength = 2, ErrorMessage = "昵称长度必须在2~10之间")] - [Required(ErrorMessage = "昵称不可为空")] - public string Nickname { get; set; } - /// /// 邮件 /// @@ -46,6 +39,13 @@ public IEnumerable Validate(ValidationContext validationContex } public class RegisterDto : RegisterEmailCodeInput { + /// + /// 昵称 + /// + [StringLength(10, MinimumLength = 2, ErrorMessage = "昵称长度必须在2~10之间")] + [Required(ErrorMessage = "昵称不可为空")] + public string Nickname { get; set; } + /// /// 密码 /// @@ -56,12 +56,12 @@ public class RegisterDto : RegisterEmailCodeInput /// /// 发送邮件时返回的唯一码,以保证用户请求与验证码是一个请求 /// - //[Required(ErrorMessage = "非法请求")] - //public string EmailCode { get; set; } + [Required(ErrorMessage = "请获取邮件验证码")] + public string EmailCode { get; set; } /// /// 邮件发送的验证码 /// - //[Required(ErrorMessage = "邮件发送的验证码不能为空")] - //public string VerificationCode { get; set; } + [Required(ErrorMessage = "邮件发送的验证码不能为空")] + public string VerificationCode { get; set; } } \ No newline at end of file diff --git a/src/LinCms.Application.Contracts/Cms/Admins/UserSearchDto.cs b/src/LinCms.Application.Contracts/Cms/Admins/UserSearchDto.cs index 7308eb38..8cf18e98 100644 --- a/src/LinCms.Application.Contracts/Cms/Admins/UserSearchDto.cs +++ b/src/LinCms.Application.Contracts/Cms/Admins/UserSearchDto.cs @@ -1,8 +1,13 @@ -using LinCms.Data; +using JetBrains.Annotations; +using LinCms.Data; namespace LinCms.Cms.Admins; public class UserSearchDto : PageDto { public int? GroupId { get; set; } + + [CanBeNull] public string Email { get; set; } + [CanBeNull] public string Nickname { get; set; } + [CanBeNull] public string Username { get; set; } } \ No newline at end of file diff --git a/src/LinCms.Application.Contracts/LinCms.Application.Contracts.xml b/src/LinCms.Application.Contracts/LinCms.Application.Contracts.xml index 117cabbb..4e8cca0f 100644 --- a/src/LinCms.Application.Contracts/LinCms.Application.Contracts.xml +++ b/src/LinCms.Application.Contracts/LinCms.Application.Contracts.xml @@ -607,14 +607,14 @@ 验证码 - + - 昵称 + 邮件 - + - 邮件 + 昵称 @@ -622,6 +622,16 @@ 密码 + + + 发送邮件时返回的唯一码,以保证用户请求与验证码是一个请求 + + + + + 邮件发送的验证码 + + 文件服务 diff --git a/src/LinCms.Application/Cms/Account/AccountService.cs b/src/LinCms.Application/Cms/Account/AccountService.cs index 31947b28..0b7c6bfa 100644 --- a/src/LinCms.Application/Cms/Account/AccountService.cs +++ b/src/LinCms.Application/Cms/Account/AccountService.cs @@ -119,7 +119,7 @@ public async Task SendEmailCodeAsync(RegisterEmailCodeInput registerDto) var message = new MimeMessage(); message.From.Add(new MailboxAddress(_mailKitOptions.UserName, _mailKitOptions.UserName)); - message.To.Add(new MailboxAddress(registerDto.Nickname, registerDto.Email)); + message.To.Add(new MailboxAddress(registerDto.Email, registerDto.Email)); message.Subject = $"vvlog-你的验证码是"; string uuid = Guid.NewGuid().ToString(); @@ -129,7 +129,7 @@ public async Task SendEmailCodeAsync(RegisterEmailCodeInput registerDto) message.Body = new TextPart("html") { - Text = $@"{registerDto.Nickname},您好!
你此次验证码如下,请在 30 分钟内输入验证码进行下一步操作。
如非你本人操作,请忽略此邮件。
{verificationCode}" + Text = $@"{registerDto.Email},您好!
你此次验证码如下,请在 30 分钟内输入验证码进行下一步操作。
如非你本人操作,请忽略此邮件。
{verificationCode}" }; await _emailSender.SendAsync(message); diff --git a/src/LinCms.Application/Cms/Users/UserService.cs b/src/LinCms.Application/Cms/Users/UserService.cs index 33585e09..70d5a606 100644 --- a/src/LinCms.Application/Cms/Users/UserService.cs +++ b/src/LinCms.Application/Cms/Users/UserService.cs @@ -69,6 +69,9 @@ public PagedResultDto GetUserListByGroupId(UserSearchDto searchDto) List linUsers = userRepository.Select .IncludeMany(r => r.LinGroups) .WhereIf(searchDto.GroupId != null, r => r.LinUserGroups.AsSelect().Any(u => u.GroupId == searchDto.GroupId)) + .WhereIf(searchDto.Email.IsNotNullOrWhiteSpace(), r => r.Email.Contains(searchDto.Email)) + .WhereIf(searchDto.Nickname.IsNotNullOrWhiteSpace(), r => r.Nickname.Contains(searchDto.Nickname)) + .WhereIf(searchDto.Username.IsNotNullOrWhiteSpace(), r => r.Username.Contains(searchDto.Username)) .OrderByDescending(r => r.Id) .ToPagerList(searchDto, out long totalCount) .Select(r => diff --git a/src/LinCms.Web/Controllers/Cms/AccountController.cs b/src/LinCms.Web/Controllers/Cms/AccountController.cs index f0119c99..ccfb0b3f 100644 --- a/src/LinCms.Web/Controllers/Cms/AccountController.cs +++ b/src/LinCms.Web/Controllers/Cms/AccountController.cs @@ -17,6 +17,7 @@ using Microsoft.Extensions.Options; using System.Collections.Generic; using System.Threading.Tasks; +using FreeRedis; using LinCms.Aop.Attributes; namespace LinCms.Controllers.Cms; @@ -35,7 +36,8 @@ public class AccountController : ApiControllerBase private readonly IAuditBaseRepository _blackRecordRepository; private readonly CaptchaOption _loginCaptchaOption; private readonly ICaptchaManager _captchaManager; - public AccountController(IComponentContext componentContext, IConfiguration configuration, IAccountService accountService, IAuditBaseRepository blackRecordRepository, IUserService userService, IOptionsMonitor loginCaptchaOption, ICaptchaManager captchaManager) + private readonly RedisClient _redisClient; + public AccountController(IComponentContext componentContext, IConfiguration configuration, IAccountService accountService, IAuditBaseRepository blackRecordRepository, IUserService userService, IOptionsMonitor loginCaptchaOption, ICaptchaManager captchaManager, RedisClient redisClient) { bool isIdentityServer4 = configuration.GetSection("Service:IdentityServer4").Value?.ToBoolean() ?? false; _tokenService = componentContext.ResolveNamed(isIdentityServer4 ? nameof(IdentityServer4Service) : nameof(JwtTokenService)); @@ -43,6 +45,7 @@ public AccountController(IComponentContext componentContext, IConfiguration conf _blackRecordRepository = blackRecordRepository; _loginCaptchaOption = loginCaptchaOption.CurrentValue; _captchaManager = captchaManager; + _redisClient = redisClient; } @@ -154,19 +157,20 @@ public async Task SendEmailCodeAsync([FromBody] RegisterEmailCodeInput r [HttpPost("account/register")] public async Task Register([FromBody] RegisterDto registerDto, [FromServices] IMapper mapper, [FromServices] IUserService userSevice) { - //string uuid = await RedisHelper.GetAsync("SendEmailCode." + registerDto.Email); - - //if (uuid != registerDto.EmailCode) - //{ - // return UnifyResponseDto.Error("非法请求"); - //} - - //string verificationCode = await RedisHelper.GetAsync("SendEmailCode.VerificationCode" + registerDto.Email); - //if (verificationCode != registerDto.VerificationCode) - //{ - // return UnifyResponseDto.Error("验证码不正确"); - //} - //暂时设置直接激活,因前台未同步改造成功 + string uuid = await _redisClient.GetAsync("SendEmailCode." + registerDto.Email); + + if (uuid != registerDto.EmailCode) + { + return UnifyResponseDto.Error("非法请求"); + } + + string verificationCode = await _redisClient.GetAsync("SendEmailCode.VerificationCode" + registerDto.Email); + if (verificationCode != registerDto.VerificationCode) + { + return UnifyResponseDto.Error("验证码不正确"); + } + //验证通过后,删除redis中的验证码 + await _redisClient.DelAsync("SendEmailCode." + registerDto.Email); LinUser user = mapper.Map(registerDto); user.IsEmailConfirmed = true; await userSevice.CreateAsync(user, new List(), registerDto.Password);