✨ Added magic spell page
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DysonNetwork.Pass.Account;
|
||||
|
||||
@@ -16,4 +17,48 @@ public class MagicSpellController(AppDatabase db, MagicSpellService sp) : Contro
|
||||
await sp.NotifyMagicSpell(spell, true);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("{spellWord}")]
|
||||
public async Task<ActionResult> GetMagicSpell(string spellWord)
|
||||
{
|
||||
var word = Uri.UnescapeDataString(spellWord);
|
||||
var spell = await db.MagicSpells
|
||||
.Where(x => x.Spell == word)
|
||||
.Include(x => x.Account)
|
||||
.ThenInclude(x => x.Profile)
|
||||
.FirstOrDefaultAsync();
|
||||
if (spell is null)
|
||||
return NotFound();
|
||||
return Ok(spell);
|
||||
}
|
||||
|
||||
public record class MagicSpellApplyRequest
|
||||
{
|
||||
public string? NewPassword { get; set; }
|
||||
}
|
||||
|
||||
[HttpPost("{spellWord}/apply")]
|
||||
public async Task<ActionResult> ApplyMagicSpell([FromRoute] string spellWord, [FromBody] MagicSpellApplyRequest request)
|
||||
{
|
||||
var word = Uri.UnescapeDataString(spellWord);
|
||||
var spell = await db.MagicSpells
|
||||
.Where(x => x.Spell == word)
|
||||
.Include(x => x.Account)
|
||||
.ThenInclude(x => x.Profile)
|
||||
.FirstOrDefaultAsync();
|
||||
if (spell is null)
|
||||
return NotFound();
|
||||
try
|
||||
{
|
||||
if (spell.Type == MagicSpellType.AuthPasswordReset && request.NewPassword is not null)
|
||||
await sp.ApplyPasswordReset(spell, request.NewPassword);
|
||||
else
|
||||
await sp.ApplyMagicSpell(spell);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user