♻️ Moving to MagicOnion
This commit is contained in:
@ -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:
|
||||
|
Reference in New Issue
Block a user