-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathLogin.razor
More file actions
59 lines (49 loc) · 1.56 KB
/
Login.razor
File metadata and controls
59 lines (49 loc) · 1.56 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
@page "/login"
@inject IAuthService AuthService
@inject NavigationManager UriHelper
<h1>Login</h1>
@if (ShowErrors)
{
<div class="alert alert-danger" role="alert">
<p>@Error</p>
</div>
}
<div class="card">
<div class="card-body">
<h5 class="card-title">Please enter your details</h5>
<EditForm Model="@loginModel" OnValidSubmit="@HandleLogin">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="form-group">
<label for="email">Email address</label>
<InputText Id="email" Class="form-control" @bind-Value="@loginModel.Email" />
<ValidationMessage For="@(() => loginModel.Email)" />
</div>
<div class="form-group">
<label for="password">Password</label>
<InputText Id="password" type="password" Class="form-control" @bind-Value="@loginModel.Password" />
<ValidationMessage For="@(() => loginModel.Password)" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</EditForm>
</div>
</div>
@code {
private LoginModel loginModel = new LoginModel();
private bool ShowErrors;
private string Error = "";
private async Task HandleLogin()
{
ShowErrors = false;
var result = await AuthService.Login(loginModel);
if (result.Successful)
{
UriHelper.NavigateTo("/");
}
else
{
Error = result.Error;
ShowErrors = true;
}
}
}