完善邮箱登录,日志完善,操作日志中增加详细报错堆栈信息
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using NETCore.Encrypt;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Infrastructure.Cache;
|
||||
using ZR.Service.System;
|
||||
using ZR.Service.System.IService;
|
||||
using ZR.ServiceCore.Model;
|
||||
@@ -191,6 +192,64 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
return ToResponse(ResultCode.CUSTOM_ERROR, "注册失败,请联系管理员");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送邮箱验证码
|
||||
/// </summary>
|
||||
/// <param name="sendEmailVo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("getMailCode")]
|
||||
public async Task<IActionResult> GetMailCode([FromBody] SendEmailDto sendEmailVo)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sendEmailVo.ToUser))
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"邮箱不能为空"));
|
||||
}
|
||||
if (string.IsNullOrEmpty(optionSettings.MailOptions.FromEmail) || string.IsNullOrEmpty(optionSettings.MailOptions.Password))
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
|
||||
}
|
||||
|
||||
if (sendEmailVo.ToUser.Length > 32)
|
||||
{
|
||||
// 解密邮箱
|
||||
sendEmailVo.ToUser = EncryptProvider.RSADecryptWithPem(PrivatePem, sendEmailVo.ToUser);
|
||||
|
||||
// 验证邮箱是否存在于系统用户中
|
||||
var user = await sysUserService.IsAnyAsync(it => it.Email == sendEmailVo.ToUser);
|
||||
// if (user == null || user.UserId <= 0)
|
||||
// 不存在则提示错误
|
||||
if (!user)
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"邮箱错误,请联系管理员"));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] saltKey = await RedisServer.Session.LRangeAsync("saltMail:" + sendEmailVo.ToUser, 0, 1);
|
||||
if (saltKey.Length > 0)
|
||||
{
|
||||
sendEmailVo.ToUser = saltKey[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"邮箱错误,请联系管理员"));
|
||||
}
|
||||
}
|
||||
// 实例化MailHelper以准备发送邮件
|
||||
MailHelper mailHelper = new();
|
||||
// 生成6位邮箱验证码
|
||||
var verifyCode = mailHelper.VerifyCode(6);
|
||||
// 设置存入Redis的key为 verifyCode: 前缀 + (盐 + 邮箱)的MD5值
|
||||
var key = "verifyCode:" + sendEmailVo.ToUser;
|
||||
// 存入Redis中设置过期时间为15分钟
|
||||
var res = await RedisServer.Session.SetAsync(key, verifyCode, 900);
|
||||
// 发送邮件,主题为 ZRAdmin.NET邮箱验证码,内容为验证码
|
||||
mailHelper.SendMail(sendEmailVo.ToUser, "ZRAdmin.NET邮箱验证码", verifyCode);
|
||||
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
#region 二维码登录
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user