-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathRegister.razor
More file actions
67 lines (57 loc) · 1.98 KB
/
Register.razor
File metadata and controls
67 lines (57 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@page "/register"
@inject IAuthService AuthService
@inject NavigationManager UriHelper
<h1>Register</h1>
@if (ShowErrors)
{
<div class="alert alert-danger" role="alert">
@foreach (var error in Errors)
{
<p>error</p>
}
</div>
}
<div class="card">
<div class="card-body">
<h5 class="card-title">Please enter your details</h5>
<EditForm Model="@RegisterModel" OnValidSubmit="@HandleRegistration">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="form-group">
<label for="email">Email address</label>
<InputText Id="email" Class="form-control" @bind-Value="@RegisterModel.Email" />
<ValidationMessage For="@(() => RegisterModel.Email)" />
</div>
<div class="form-group">
<label for="password">Password</label>
<InputText Id="password" Class="form-control" @bind-Value="@RegisterModel.Password" />
<ValidationMessage For="@(() => RegisterModel.Password)" />
</div>
<div class="form-group">
<label for="password">Confirm Password</label>
<InputText Id="password" Class="form-control" @bind-Value="@RegisterModel.ConfirmPassword" />
<ValidationMessage For="@(() => RegisterModel.ConfirmPassword)" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</EditForm>
</div>
</div>
@code {
private RegisterModel RegisterModel = new RegisterModel();
private bool ShowErrors;
private IEnumerable<string> Errors;
private async Task HandleRegistration()
{
ShowErrors = false;
var result = await AuthService.Register(RegisterModel);
if (result.Successful)
{
UriHelper.NavigateTo("/login");
}
else
{
Errors = result.Errors;
ShowErrors = true;
}
}
}