43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using DysonNetwork.Shared.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NodaTime;
|
|
|
|
namespace DysonNetwork.Sphere.Pages.Spell;
|
|
|
|
public class MagicSpellPage(DysonNetwork.Shared.Services.IMagicSpellService magicSpellService) : PageModel
|
|
{
|
|
[BindProperty] public MagicSpell? CurrentSpell { get; set; }
|
|
[BindProperty] public string? NewPassword { get; set; }
|
|
|
|
public bool IsSuccess { get; set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync(string spellWord)
|
|
{
|
|
spellWord = Uri.UnescapeDataString(spellWord);
|
|
var now = SystemClock.Instance.GetCurrentInstant();
|
|
CurrentSpell = await magicSpellService.GetMagicSpellAsync(spellWord);
|
|
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
if (CurrentSpell?.Id == null)
|
|
return Page();
|
|
|
|
var now = SystemClock.Instance.GetCurrentInstant();
|
|
var spell = await magicSpellService.GetMagicSpellByIdAsync(CurrentSpell.Id);
|
|
|
|
if (spell == null || spell.Type == MagicSpellType.AuthPasswordReset && string.IsNullOrWhiteSpace(NewPassword))
|
|
return Page();
|
|
|
|
if (spell.Type == MagicSpellType.AuthPasswordReset)
|
|
await magicSpellService.ApplyPasswordReset(spell, NewPassword!);
|
|
else
|
|
await magicSpellService.ApplyMagicSpell(spell.Spell);
|
|
IsSuccess = true;
|
|
return Page();
|
|
}
|
|
} |