Add Login Module
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using AMREZ.EOP.Abstractions.Applications.Tenancy;
|
||||
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
|
||||
using AMREZ.EOP.Abstractions.Storage;
|
||||
using AMREZ.EOP.Domain.Entities.Tenancy;
|
||||
using AMREZ.EOP.Infrastructures.Data;
|
||||
using AMREZ.EOP.Infrastructures.Options;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
@@ -11,9 +13,19 @@ namespace AMREZ.EOP.Infrastructures.Repositories;
|
||||
public sealed class TenantRepository : ITenantRepository
|
||||
{
|
||||
private readonly IDbScope _scope;
|
||||
public TenantRepository(IDbScope scope) => _scope = scope;
|
||||
private readonly ITenantResolver _resolver;
|
||||
private readonly IHttpContextAccessor _http;
|
||||
|
||||
private AppDbContext Db() => _scope.Get<AppDbContext>();
|
||||
public TenantRepository(IDbScope scope, ITenantResolver resolver, IHttpContextAccessor http)
|
||||
{ _scope = scope; _resolver = resolver; _http = http; }
|
||||
|
||||
private AppDbContext Db()
|
||||
{
|
||||
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
|
||||
var platform = _resolver.Resolve(http, "@platform") ?? throw new InvalidOperationException("No platform tenant");
|
||||
_scope.EnsureForTenant(platform);
|
||||
return _scope.Get<AppDbContext>();
|
||||
}
|
||||
|
||||
private static string Norm(string s) => (s ?? string.Empty).Trim().ToLowerInvariant();
|
||||
|
||||
@@ -51,7 +63,7 @@ public sealed class TenantRepository : ITenantRepository
|
||||
if (cur is null) return false;
|
||||
|
||||
if (ifUnmodifiedSince.HasValue && cur.UpdatedAtUtc > ifUnmodifiedSince.Value)
|
||||
return false; // 412
|
||||
return false;
|
||||
|
||||
cur.Schema = row.Schema is null ? cur.Schema : (string.IsNullOrWhiteSpace(row.Schema) ? null : row.Schema.Trim());
|
||||
cur.ConnectionString = row.ConnectionString is null ? cur.ConnectionString : (string.IsNullOrWhiteSpace(row.ConnectionString) ? null : row.ConnectionString.Trim());
|
||||
@@ -70,7 +82,6 @@ public sealed class TenantRepository : ITenantRepository
|
||||
var t = await db.Set<TenantConfig>().FirstOrDefaultAsync(x => x.TenantKey == key, ct);
|
||||
if (t is null) return false;
|
||||
|
||||
// ❌ ไม่ลบนะ — ✅ deactivate
|
||||
if (t.IsActive)
|
||||
{
|
||||
t.IsActive = false;
|
||||
@@ -120,7 +131,7 @@ public sealed class TenantRepository : ITenantRepository
|
||||
if (ex is null) return false;
|
||||
|
||||
ex.IsActive = false;
|
||||
ex.TenantKey = null;
|
||||
ex.TenantKey = null;
|
||||
ex.IsPlatformBaseDomain = false;
|
||||
ex.UpdatedAtUtc = DateTimeOffset.UtcNow;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user