♻️ Moving to MagicOnion

This commit is contained in:
2025-07-07 21:54:51 +08:00
parent 1672d46038
commit 8d2f4a4c47
41 changed files with 790 additions and 530 deletions

View File

@ -2,6 +2,8 @@ using System.Globalization;
using System.Security.Cryptography;
using System.Text.Json;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Services;
using MagicOnion.Server;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using NodaTime;
@ -12,11 +14,9 @@ namespace DysonNetwork.Pass.Account;
public class MagicSpellService(
AppDatabase db,
// EmailService email,
IConfiguration configuration,
ILogger<MagicSpellService> logger
// IStringLocalizer<Localization.EmailResource> localizer
)
) : ServiceBase<IMagicSpellService>, IMagicSpellService
{
public async Task<MagicSpell> CreateMagicSpell(
Shared.Models.Account account,
@ -59,6 +59,17 @@ public class MagicSpellService(
return spell;
}
public async Task<MagicSpell?> GetMagicSpellAsync(string token)
{
var now = SystemClock.Instance.GetCurrentInstant();
var spell = await db.MagicSpells
.Where(s => s.Spell == token)
.Where(s => s.ExpiresAt == null || s.ExpiresAt > now)
.FirstOrDefaultAsync();
return spell;
}
public async Task NotifyMagicSpell(MagicSpell spell, bool bypassVerify = false)
{
var contact = await db.AccountContacts
@ -144,8 +155,15 @@ public class MagicSpellService(
}
}
public async Task ApplyMagicSpell(MagicSpell spell)
public async Task ApplyMagicSpell(string token)
{
var now = SystemClock.Instance.GetCurrentInstant();
var spell = await db.MagicSpells
.Where(s => s.Spell == token)
.Where(s => s.ExpiresAt == null || s.ExpiresAt > now)
.FirstOrDefaultAsync();
if (spell is null) throw new ArgumentException("Magic spell not found.");
switch (spell.Type)
{
case MagicSpellType.AuthPasswordReset: