Compare commits
2 Commits
fec25072c4
...
803a9f86e1
| Author | SHA1 | Date | |
|---|---|---|---|
| 803a9f86e1 | |||
| b3182b3ae7 |
@@ -1,14 +1,12 @@
|
|||||||
@page "/register"
|
@page "/register"
|
||||||
@using Sandbox.Models.ViewModels
|
@using Sandbox.Models.ViewModels
|
||||||
@using Sandbox.Services.AuthService
|
|
||||||
|
|
||||||
@* @inject AuthenticationStateProvider AuthenticationStateProvider *@
|
@* @inject AuthenticationStateProvider AuthenticationStateProvider *@
|
||||||
@* @inject NavigationManager NavigationManager *@
|
@* @inject NavigationManager NavigationManager *@
|
||||||
@inject IAuthService AuthService
|
|
||||||
|
|
||||||
<title>Register</title>
|
<title>Register</title>
|
||||||
|
|
||||||
<EditForm Model="user" OnValidSubmit="HandleRegistration">
|
<EditForm Model="user" OnValidSubmit="HandleRegistration" FormName="registerForm">
|
||||||
<DataAnnotationsValidator/>
|
<DataAnnotationsValidator/>
|
||||||
<div class="d-flex justify-content-center align-items-center">
|
<div class="d-flex justify-content-center align-items-center">
|
||||||
<div class="col-md-4 p-5 shadow-sm border rounded-3">
|
<div class="col-md-4 p-5 shadow-sm border rounded-3">
|
||||||
@@ -48,6 +46,7 @@
|
|||||||
|
|
||||||
@code {
|
@code {
|
||||||
UserRegister user = new();
|
UserRegister user = new();
|
||||||
|
HttpClient _http = new();
|
||||||
|
|
||||||
private string message = string.Empty;
|
private string message = string.Empty;
|
||||||
private string messageCssClass = string.Empty;
|
private string messageCssClass = string.Empty;
|
||||||
@@ -55,7 +54,8 @@
|
|||||||
|
|
||||||
async void HandleRegistration()
|
async void HandleRegistration()
|
||||||
{
|
{
|
||||||
var result = await AuthService.Register(user.Email, user.Password);
|
var response = await _http.PostAsJsonAsync("api/auth/register", user);
|
||||||
|
var result = await response.Content.ReadFromJsonAsync<ServiceResponse<int>>();
|
||||||
message = result.Message;
|
message = result.Message;
|
||||||
messageCssClass = result.Success ? "text-success" : "text-danger";
|
messageCssClass = result.Success ? "text-success" : "text-danger";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Sandbox.Components;
|
using Sandbox.Components;
|
||||||
|
using Sandbox.Models.ViewModels;
|
||||||
using Sandbox.Services.AuthService;
|
using Sandbox.Services.AuthService;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -23,6 +24,9 @@ app.UseHttpsRedirection();
|
|||||||
|
|
||||||
app.UseAntiforgery();
|
app.UseAntiforgery();
|
||||||
|
|
||||||
|
app.MapPost("/register", async (UserRegister request, IAuthService authService) =>
|
||||||
|
await authService.Register(request.Email, request.Password));
|
||||||
|
|
||||||
app.MapStaticAssets();
|
app.MapStaticAssets();
|
||||||
app.MapRazorComponents<App>()
|
app.MapRazorComponents<App>()
|
||||||
.AddInteractiveServerRenderMode();
|
.AddInteractiveServerRenderMode();
|
||||||
|
|||||||
Reference in New Issue
Block a user