PIAPS_CW/WebApp/Pages/SignUp.cshtml.cs

38 lines
1.0 KiB
C#
Raw Permalink Normal View History

using Contracts.BindingModels;
using Contracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using WebApp.Helpers;
namespace WebApp.Pages
{
public class SignUpModel : PageModel
{
[BindProperty]
public UserBindingModel UserModel { get; set; }
public void OnGet()
{
}
public IActionResult OnPostAsync()
{
var userRole = APIClient.GetRequest<RoleViewModel>($"role/get?name={Roles.User}");
if (userRole is null)
{
throw new Exception("User role is not found");
}
UserModel.Role = new() { Id = userRole.Id };
var response = APIClient.PostRequest("user/registration", UserModel);
if (response is null || response is not string)
{
throw new Exception("Something wrong LOL!");
}
2024-06-22 18:43:07 +04:00
TempData["jwt"] = (string)response;
2024-06-22 18:43:07 +04:00
return RedirectToPage("TwoFactor");
}
}
}