42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using System.Globalization;
|
|
using DysonNetwork.Sphere.Localization;
|
|
using DysonNetwork.Sphere.Permission;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
namespace DysonNetwork.Sphere.Account;
|
|
|
|
public class AccountService(AppDatabase db, PermissionService pm, IMemoryCache cache, IStringLocalizerFactory localizerFactory)
|
|
{
|
|
public async Task PurgeAccountCache(Account account)
|
|
{
|
|
cache.Remove($"dyn_user_friends_{account.Id}");
|
|
|
|
var sessions = await db.AuthSessions.Where(e => e.Account.Id == account.Id).Select(e => e.Id)
|
|
.ToListAsync();
|
|
foreach (var session in sessions)
|
|
{
|
|
cache.Remove($"dyn_auth_{session}");
|
|
}
|
|
}
|
|
|
|
public async Task<Account?> LookupAccount(string probe)
|
|
{
|
|
var account = await db.Accounts.Where(a => a.Name == probe).FirstOrDefaultAsync();
|
|
if (account is not null) return account;
|
|
|
|
var contact = await db.AccountContacts
|
|
.Where(c => c.Content == probe)
|
|
.Include(c => c.Account)
|
|
.FirstOrDefaultAsync();
|
|
if (contact is not null) return contact.Account;
|
|
|
|
return null;
|
|
}
|
|
|
|
public IStringLocalizer GetEventLocalizer(string language)
|
|
{
|
|
return localizerFactory.Create(language, nameof(AccountEventResource));
|
|
}
|
|
} |