refactor: 消除二义性错误
This commit is contained in:
parent
42d56b9dbc
commit
edac104fbc
|
@ -9,12 +9,12 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BootstrapBlazor" Version="5.6.5" />
|
||||
<PackageReference Include="BootstrapBlazor" Version="5.16.0" />
|
||||
<PackageReference Include="Exceptionless.AspNetCore" Version="4.6.2" />
|
||||
<PackageReference Include="Longbow.Logging" Version="5.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
|
||||
<PackageReference Include="Sentry.AspNetCore" Version="3.8.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />
|
||||
<PackageReference Include="Sentry.AspNetCore" Version="3.10.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(code)) return RedirectLogin();
|
||||
|
||||
var auth = provider.Validate(phone, code);
|
||||
HttpContext.Log(phone, auth);
|
||||
await HttpContext.Log(phone, auth);
|
||||
if (auth)
|
||||
{
|
||||
var user = UserHelper.Retrieves().FirstOrDefault(u => u.UserName == phone);
|
||||
|
@ -161,7 +161,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password)) return RedirectLogin();
|
||||
|
||||
var auth = UserHelper.Authenticate(userName, password);
|
||||
HttpContext.Log(userName, auth);
|
||||
await HttpContext.Log(userName, auth);
|
||||
return auth ? await SignInAsync(userName, remember == "true") : LoginView("", new LoginModel() { AuthFailed = true });
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <returns></returns>
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public QueryData<LoginUser> Get([FromQuery]QueryLoginOption value) => value.RetrieveData();
|
||||
public QueryData<LoginUser> Get([FromQuery] QueryLoginOption value) => value.RetrieveData();
|
||||
|
||||
/// <summary>
|
||||
/// JWT 登陆认证接口
|
||||
|
@ -34,9 +34,9 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public string? Post([FromServices]IConfiguration config, [FromBody]User user)
|
||||
public async Task<string?> Post([FromServices] IConfiguration config, [FromBody] User user)
|
||||
{
|
||||
var token = string.Empty;
|
||||
string? token = null;
|
||||
string userName = user.UserName;
|
||||
string password = user.Password;
|
||||
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password))
|
||||
|
@ -50,7 +50,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
op.SecurityKey = tokenOption.SecurityKey;
|
||||
});
|
||||
}
|
||||
HttpContext.Log(userName, !string.IsNullOrEmpty(token));
|
||||
await HttpContext.Log(userName, !string.IsNullOrEmpty(token));
|
||||
return token;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <param name="phone"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<SMSResult> Put([FromServices]ISMSProvider provider, [FromQuery]string phone) => string.IsNullOrEmpty(phone) ? new SMSResult() { Result = false, Msg = "手机号不可为空" } : await provider.SendCodeAsync(phone);
|
||||
public async Task<SMSResult> Put([FromServices] ISMSProvider provider, [FromQuery] string phone) => string.IsNullOrEmpty(phone) ? new SMSResult() { Result = false, Msg = "手机号不可为空" } : await provider.SendCodeAsync(phone);
|
||||
|
||||
/// <summary>
|
||||
/// 跨域握手协议
|
||||
|
|
|
@ -5,6 +5,7 @@ using Longbow.Web.Mvc;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bootstrap.Admin.Controllers.Api
|
||||
{
|
||||
|
@ -22,7 +23,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public QueryData<Log> Get([FromQuery]QueryLogOption value)
|
||||
public QueryData<Log> Get([FromQuery] QueryLogOption value)
|
||||
{
|
||||
return value.RetrieveData();
|
||||
}
|
||||
|
@ -34,14 +35,14 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public bool Post([FromServices]IIPLocatorProvider ipLocator, [FromBody]Log value)
|
||||
public async Task<bool> Post([FromServices] IIPLocatorProvider ipLocator, [FromBody] Log value)
|
||||
{
|
||||
value.UserAgent = Request.Headers["User-Agent"];
|
||||
var agent = new UserAgent(value.UserAgent);
|
||||
value.Ip = HttpContext.Connection.RemoteIpAddress?.ToIPv4String() ?? "";
|
||||
value.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}";
|
||||
value.OS = $"{agent.OS?.Name} {agent.OS?.Version}";
|
||||
value.City = ipLocator.Locate(value.Ip);
|
||||
value.City = await ipLocator.Locate(value.Ip);
|
||||
value.UserName = User.Identity?.Name ?? string.Empty;
|
||||
return LogHelper.Save(value);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging.Configuration;
|
|||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
|
|
|
@ -44,7 +44,11 @@ namespace Microsoft.AspNetCore.Http
|
|||
FirstAccessTime = DateTime.Now,
|
||||
Referer = context.Request.Headers["Referer"]
|
||||
};
|
||||
v.Location = locator?.Locate(v.Ip) ?? "";
|
||||
var t = locator.Locate(v.Ip);
|
||||
if (t.IsCompletedSuccessfully)
|
||||
{
|
||||
v.Location = t.Result;
|
||||
}
|
||||
return proxy(new AutoExpireCacheEntry<OnlineUser>(v, 1000 * 60, __ => onlineUserSvr.TryRemove(key, out _)), null);
|
||||
}, (key, v) => proxy(v, () => v.Reset()));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bootstrap.Security" Version="5.2.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.13.1" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.13.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
<PackageReference Include="Longbow.Security.Cryptography" Version="5.2.0" />
|
||||
<PackageReference Include="Longbow.Tasks" Version="5.1.0" />
|
||||
<PackageReference Include="Longbow.TencentAuth" Version="5.2.0" />
|
||||
<PackageReference Include="Longbow.Web" Version="5.2.0" />
|
||||
<PackageReference Include="Longbow.Web" Version="5.2.1" />
|
||||
<PackageReference Include="Longbow.WeChatAuth" Version="5.2.0" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.11" />
|
||||
<PackageReference Include="PetaPoco.Extensions" Version="5.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -180,25 +180,25 @@ namespace Bootstrap.DataAccess
|
|||
/// 程序异常时长 默认1月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveExceptionsLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "程序异常保留时长" && d.Define == 0)?.Code, 1);
|
||||
public int RetrieveExceptionsLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "程序异常保留时长" && d.Define == 0)?.Code ?? "1", 1);
|
||||
|
||||
/// <summary>
|
||||
/// 操作日志时长 默认12月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "操作日志保留时长" && d.Define == 0)?.Code, 12);
|
||||
public int RetrieveLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "操作日志保留时长" && d.Define == 0)?.Code ?? "12", 12);
|
||||
|
||||
/// <summary>
|
||||
/// 登录日志时长 默认12月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveLoginLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "登录日志保留时长" && d.Define == 0)?.Code, 12);
|
||||
public int RetrieveLoginLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "登录日志保留时长" && d.Define == 0)?.Code ?? "12", 12);
|
||||
|
||||
/// <summary>
|
||||
/// Cookie保存时长 默认7天
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveCookieExpiresPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "Cookie保留时长" && d.Define == 0)?.Code, 7);
|
||||
public int RetrieveCookieExpiresPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "Cookie保留时长" && d.Define == 0)?.Code ?? "7", 7);
|
||||
|
||||
/// <summary>
|
||||
/// 获得 IP地理位置
|
||||
|
@ -229,13 +229,13 @@ namespace Bootstrap.DataAccess
|
|||
/// 获得 访问日志保留时长 默认为1个月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveAccessLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "访问日志保留时长" && d.Define == 0)?.Code, 1);
|
||||
public int RetrieveAccessLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "访问日志保留时长" && d.Define == 0)?.Code ?? "1", 1);
|
||||
|
||||
/// <summary>
|
||||
/// 获得 是否为演示系统 默认为 false 不是演示系统
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool RetrieveSystemModel() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "演示系统" && d.Define == 0)?.Code, "0") == "1";
|
||||
public bool RetrieveSystemModel() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "演示系统" && d.Define == 0)?.Code ?? "0", "0") == "1";
|
||||
|
||||
/// <summary>
|
||||
/// 获得 是否为演示系统 默认为 false 不是演示系统
|
||||
|
@ -282,7 +282,7 @@ namespace Bootstrap.DataAccess
|
|||
/// 获得自动锁屏时长 默认 30 秒
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveAutoLockScreenPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "自动锁屏时长" && d.Define == 0)?.Code, 30);
|
||||
public int RetrieveAutoLockScreenPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "自动锁屏时长" && d.Define == 0)?.Code ?? "30", 30);
|
||||
|
||||
/// <summary>
|
||||
/// 获得自动锁屏是否开启 默认关闭
|
||||
|
|
|
@ -6,6 +6,7 @@ using PetaPoco;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
|
@ -21,7 +22,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName">登录用户名</param>
|
||||
/// <param name="auth">是否登录成功</param>
|
||||
/// <returns></returns>
|
||||
public static bool Log(this HttpContext context, string userName, bool auth)
|
||||
public static async Task<bool> Log(this HttpContext context, string userName, bool auth)
|
||||
{
|
||||
var ipLocator = context.RequestServices.GetRequiredService<IIPLocatorProvider>();
|
||||
var ip = context.Connection.RemoteIpAddress?.ToIPv4String() ?? "";
|
||||
|
@ -35,11 +36,11 @@ namespace Bootstrap.DataAccess
|
|||
LoginTime = DateTime.Now,
|
||||
UserAgent = userAgent,
|
||||
Ip = ip,
|
||||
City = ipLocator.Locate(ip),
|
||||
Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}",
|
||||
OS = $"{agent.OS?.Name} {agent.OS?.Version}",
|
||||
Result = auth ? "登录成功" : "登录失败"
|
||||
};
|
||||
loginUser.City = await ipLocator.Locate(ip);
|
||||
return DbContextManager.Create<LoginUser>()?.Log(loginUser) ?? false;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace Bootstrap.DataAccess
|
|||
SaveUser(user, option.Roles);
|
||||
|
||||
// 记录登陆日志
|
||||
context.HttpContext.Log(user.UserName, true);
|
||||
await context.HttpContext.Log(user.UserName, true);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BootstrapBlazor" Version="5.6.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.9" />
|
||||
<PackageReference Include="BootstrapBlazor" Version="5.16.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.11" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.13.1" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.13.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
<PackageReference Include="Longbow.ComponentModel" Version="5.2.0" />
|
||||
<PackageReference Include="Longbow.Data" Version="5.2.0" />
|
||||
<PackageReference Include="Longbow.Security.Cryptography" Version="5.2.0" />
|
||||
<PackageReference Include="Longbow.Web" Version="5.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
||||
<PackageReference Include="Longbow.Web" Version="5.2.1" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BootstrapBlazor" Version="5.6.5" />
|
||||
<PackageReference Include="BootstrapBlazor" Version="5.16.0" />
|
||||
<PackageReference Include="Longbow.Logging" Version="5.2.0" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bootstrap.Client.Tasks
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.11" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.26" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.27" />
|
||||
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
|
|
Loading…
Reference in New Issue