Swarm/DysonNetwork.Sphere/Pages/MagicSpellPage.cshtml.cs
LittleSheep 0ebeab672b Magic spell for one time code
🗑️ Drop the usage of casbin
♻️ Refactor the permission service
♻️ Refactor the flow of creating an account
🧱 Email infra structure
2025-04-29 20:37:10 +08:00

24 lines
746 B
C#

using DysonNetwork.Sphere.Account;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Sphere.Pages;
public class MagicSpellPage(AppDatabase db, MagicSpellService spells) : PageModel
{
public async Task<ActionResult> OnGet(string spellWord)
{
var now = SystemClock.Instance.GetCurrentInstant();
var spell = await db.MagicSpells
.Where(e => e.Spell == spellWord)
.Where(e => e.ExpiresAt == null || now >= e.ExpiresAt)
.Where(e => e.AffectedAt == null || now >= e.AffectedAt)
.FirstOrDefaultAsync();
ViewData["Spell"] = spell;
return Page();
}
}