mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-07-14 03:23:48 +08:00
🔄refactor: 替换EF为SqlSugar
This commit is contained in:
@@ -18,6 +18,10 @@ using Infrastructure;
|
|||||||
using OpenAuth.Repository;
|
using OpenAuth.Repository;
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Interface;
|
using OpenAuth.Repository.Interface;
|
||||||
|
using SqlSugar;
|
||||||
|
using Infrastructure.Extensions.AutofacManager;
|
||||||
|
using Infrastructure.Utilities;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
@@ -29,15 +33,28 @@ namespace OpenAuth.App
|
|||||||
{
|
{
|
||||||
private SystemAuthStrategy _systemAuth;
|
private SystemAuthStrategy _systemAuth;
|
||||||
private NormalAuthStrategy _normalAuthStrategy;
|
private NormalAuthStrategy _normalAuthStrategy;
|
||||||
private readonly IUnitWork<OpenAuthDBContext> _unitWork;
|
|
||||||
|
protected ISqlSugarClient SugarClient;
|
||||||
|
|
||||||
public AuthContextFactory(SystemAuthStrategy sysStrategy
|
public AuthContextFactory(SystemAuthStrategy sysStrategy
|
||||||
, NormalAuthStrategy normalAuthStrategy
|
, NormalAuthStrategy normalAuthStrategy
|
||||||
, IUnitWork<OpenAuthDBContext> unitWork)
|
, ISqlSugarClient client)
|
||||||
{
|
{
|
||||||
_systemAuth = sysStrategy;
|
_systemAuth = sysStrategy;
|
||||||
_normalAuthStrategy = normalAuthStrategy;
|
_normalAuthStrategy = normalAuthStrategy;
|
||||||
_unitWork = unitWork;
|
string tenantId = Define.DEFAULT_TENANT_ID;
|
||||||
|
var httpContextAccessor = AutofacContainerModule.GetService<IHttpContextAccessor>();
|
||||||
|
if (httpContextAccessor != null)
|
||||||
|
{
|
||||||
|
tenantId = httpContextAccessor.GetTenantId();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tenantId != Define.DEFAULT_TENANT_ID) //如果不是默认租户,则使用租户id获取连接
|
||||||
|
{
|
||||||
|
client = client.AsTenant().GetConnection(tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
SugarClient = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthStrategyContext GetAuthStrategyContext(string username)
|
public AuthStrategyContext GetAuthStrategyContext(string username)
|
||||||
@@ -52,7 +69,7 @@ namespace OpenAuth.App
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
service = _normalAuthStrategy;
|
service = _normalAuthStrategy;
|
||||||
service.User = _unitWork.FirstOrDefault<SysUser>(u => u.Account == username);
|
service.User = SugarClient.Queryable<SysUser>().First(u => u.Account == username);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AuthStrategyContext(service);
|
return new AuthStrategyContext(service);
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ using Infrastructure.Helpers;
|
|||||||
using OpenAuth.Repository;
|
using OpenAuth.Repository;
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Interface;
|
using OpenAuth.Repository.Interface;
|
||||||
|
using SqlSugar;
|
||||||
|
using Infrastructure.Extensions.AutofacManager;
|
||||||
|
using Infrastructure.Utilities;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAuth.App.SSO
|
namespace OpenAuth.App.SSO
|
||||||
@@ -17,15 +21,27 @@ namespace OpenAuth.App.SSO
|
|||||||
{
|
{
|
||||||
|
|
||||||
//这个地方使用IRepository<User> 而不使用UserManagerApp是防止循环依赖
|
//这个地方使用IRepository<User> 而不使用UserManagerApp是防止循环依赖
|
||||||
public IRepository<SysUser,OpenAuthDBContext> _app;
|
protected ISqlSugarClient SugarClient;
|
||||||
private ICacheContext _cacheContext;
|
private ICacheContext _cacheContext;
|
||||||
private AppManager _appInfoService;
|
private AppManager _appInfoService;
|
||||||
|
|
||||||
public LoginParse( AppManager infoService, ICacheContext cacheContext, IRepository<SysUser,OpenAuthDBContext> userApp)
|
public LoginParse( AppManager infoService, ICacheContext cacheContext, ISqlSugarClient client)
|
||||||
{
|
{
|
||||||
_appInfoService = infoService;
|
_appInfoService = infoService;
|
||||||
_cacheContext = cacheContext;
|
_cacheContext = cacheContext;
|
||||||
_app = userApp;
|
string tenantId = Define.DEFAULT_TENANT_ID;
|
||||||
|
var httpContextAccessor = AutofacContainerModule.GetService<IHttpContextAccessor>();
|
||||||
|
if (httpContextAccessor != null)
|
||||||
|
{
|
||||||
|
tenantId = httpContextAccessor.GetTenantId();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tenantId != Define.DEFAULT_TENANT_ID) //如果不是默认租户,则使用租户id获取连接
|
||||||
|
{
|
||||||
|
client = client.AsTenant().GetConnection(tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
SugarClient = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginResult Do(PassportLoginRequest model)
|
public LoginResult Do(PassportLoginRequest model)
|
||||||
@@ -54,7 +70,7 @@ namespace OpenAuth.App.SSO
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sysUserInfo = _app.FirstOrDefault(u =>u.Account == model.Account);
|
sysUserInfo = SugarClient.Queryable<SysUser>().First(u =>u.Account == model.Account);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sysUserInfo == null)
|
if (sysUserInfo == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user