|
@@ -15,6 +15,7 @@ using XF.Domain.Constants;
|
|
|
using XF.Domain.Exceptions;
|
|
|
using Hotline.Share.Dtos.Snapshot;
|
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
|
+using NETCore.Encrypt;
|
|
|
|
|
|
namespace Hotline.Api.Controllers;
|
|
|
|
|
@@ -25,7 +26,7 @@ public class IdentityController : BaseController
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
private readonly ISystemLogApplication _iSystemLogApplication;
|
|
|
|
|
|
- private const string PublicKey = @"-----BEGIN PUBLIC KEY-----
|
|
|
+ private const string PublicKey = @"-----BEGIN PUBLIC KEY-----
|
|
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgw+/x6IQPkH0A4eoF63j
|
|
|
kLThsOXWyNBdcL9LATGy/G1yTHOr1RyKJB//iNug+V8DIoIHuFTlhgLHDbSqxvRW
|
|
|
MONxIIF289riS6bDI4Ox/pFmOfmElFRk0lKGihaTE2Aefd6g/N+RfLLaHWztY+/v
|
|
@@ -62,17 +63,20 @@ Q9PP8NTEmKqdI3WVFYqW/OlOFC6sjiscTOOn9Tc5Mrcn8ocCjAPjkhkCCVRMiJnv
|
|
|
jxrWXHbT1FB6DqkdOnBbQqS1Azqz5HxLlSyEK3F60e3SgB5iZsDZ
|
|
|
-----END RSA PRIVATE KEY-----";
|
|
|
|
|
|
+ private const string AesKey = "qlzeJrbj0CPkHdFBvEAxX47Y4nCbBPZW";
|
|
|
+ private const string AesIv = "JxeDP0sgnPJdH9fE";
|
|
|
+
|
|
|
public IdentityController(
|
|
|
IOptionsSnapshot<AppConfiguration> appOptions,
|
|
|
- IIdentityAppService identityAppService,
|
|
|
- ISystemSettingCacheManager systemSettingCacheManager,
|
|
|
+ IIdentityAppService identityAppService,
|
|
|
+ ISystemSettingCacheManager systemSettingCacheManager,
|
|
|
ISystemLogApplication iSystemLogApplication)
|
|
|
{
|
|
|
_appOptions = appOptions;
|
|
|
_identityAppService = identityAppService;
|
|
|
_systemSettingCacheManager = systemSettingCacheManager;
|
|
|
_iSystemLogApplication = iSystemLogApplication;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 登录
|
|
@@ -81,14 +85,30 @@ jxrWXHbT1FB6DqkdOnBbQqS1Azqz5HxLlSyEK3F60e3SgB5iZsDZ
|
|
|
/// <returns></returns>
|
|
|
[AllowAnonymous]
|
|
|
[HttpPost("login")]
|
|
|
- [LogFilter("",false)]
|
|
|
- public async Task<string> Login([FromBody] LoginDto dto)
|
|
|
+ [LogFilter("", false)]
|
|
|
+ public async Task<string> Login([FromBody] LoginDto dto)
|
|
|
{
|
|
|
dto = Decrypt(dto);
|
|
|
var res = await _identityAppService.LoginAsync(dto, HttpContext.RequestAborted);
|
|
|
dto.Password = string.Empty;
|
|
|
- await _iSystemLogApplication.AddLog("账号登录", res, dto, HttpContext,dto.Username);
|
|
|
- return res ;
|
|
|
+ await _iSystemLogApplication.AddLog("账号登录", res, dto, HttpContext, dto.Username);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 登录
|
|
|
+ /// </summary>
|
|
|
+ [AllowAnonymous]
|
|
|
+ [HttpPost("login-sign")]
|
|
|
+ public async Task<string> Login([FromBody] LoginSignatureDto dto)
|
|
|
+ {
|
|
|
+ var request = Decrypt(dto.Signature);
|
|
|
+ if (request is null)
|
|
|
+ throw UserFriendlyException.SameMessage("用户名或密码错误!");
|
|
|
+ var res = await _identityAppService.LoginWithSignatureAsync(request, HttpContext.RequestAborted);
|
|
|
+ request.Password = string.Empty;
|
|
|
+ await _iSystemLogApplication.AddLog("账号登录", res, request, HttpContext, request.Username);
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -133,7 +153,7 @@ jxrWXHbT1FB6DqkdOnBbQqS1Azqz5HxLlSyEK3F60e3SgB5iZsDZ
|
|
|
var faviconImage = _systemSettingCacheManager.GetSetting(SettingConstants.FaviconImage).SettingValue?.FirstOrDefault();
|
|
|
var menuLogoImage = _systemSettingCacheManager.GetSetting(SettingConstants.MenuLogoImage).SettingValue?.FirstOrDefault();
|
|
|
var menuLogoImageMini = _systemSettingCacheManager.GetSetting(SettingConstants.MenuLogoImageMini).SettingValue?.FirstOrDefault();
|
|
|
- var IsLoginMessageCode = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsLoginMessageCode).SettingValue[0]);
|
|
|
+ var IsLoginMessageCode = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsLoginMessageCode).SettingValue[0]);
|
|
|
var recordNumber = _systemSettingCacheManager.GetSetting(SettingConstants.RecordNumber).SettingValue?.FirstOrDefault();
|
|
|
var cityAbbr = _systemSettingCacheManager.GetSetting(SettingConstants.CityAbbr).SettingValue?.FirstOrDefault();
|
|
|
var operate = _systemSettingCacheManager.GetSetting(SettingConstants.Operate).SettingValue?.FirstOrDefault();
|
|
@@ -172,11 +192,20 @@ jxrWXHbT1FB6DqkdOnBbQqS1Azqz5HxLlSyEK3F60e3SgB5iZsDZ
|
|
|
var uname = pkcs1.Decrypt(dto.Username, RSAEncryptionPadding.Pkcs1);
|
|
|
var pwd = pkcs1.Decrypt(dto.Password, RSAEncryptionPadding.Pkcs1);
|
|
|
var msgCode = pkcs1.Decrypt(dto.MsgCode, RSAEncryptionPadding.Pkcs1);
|
|
|
- return new LoginDto { Username = uname, Password = pwd,MsgCode=msgCode };
|
|
|
+ return new LoginDto { Username = uname, Password = pwd, MsgCode = msgCode };
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
throw new UserFriendlyException($"解密失败:{e.Message}", "无效参数");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private LoginWithSignatureRequest? Decrypt(string signature)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(signature)) return null;
|
|
|
+ var decrypted = EncryptProvider.AESDecrypt(signature, AesKey, AesIv);
|
|
|
+ if(string.IsNullOrEmpty(decrypted)) return null;
|
|
|
+ return System.Text.Json.JsonSerializer.Deserialize<LoginWithSignatureRequest>(decrypted,
|
|
|
+ JsonDefaults.DefaultJsonSerializerOptionsWithCamelCase);
|
|
|
+ }
|
|
|
}
|