PIAPS_CW/WebApp/Pages/TwoFactor.cshtml.cs

35 lines
961 B
C#
Raw Normal View History

2024-06-22 18:43:07 +04:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{
public class TwoFactorModel : PageModel
{
[BindProperty]
public int[] Code { get; set; } = [];
public void OnGet()
{
}
public IActionResult OnPost(string[] code)
{
var stringCode = string.Join(string.Empty, Code);
if (string.IsNullOrEmpty(stringCode))
{
throw new Exception("Looo");
}
var response = (string)APIClient.PostRequest("user/verifycode", new { code = stringCode });
var isCorrect = Convert.ToBoolean(response);
if (isCorrect)
{
this.SetJWT((string)TempData["jwt"]);
return RedirectToPage("Index");
}
else
{
throw new Exception("Wrong code! Please retry");
}
}
}
}