Skip to content

Commit

Permalink
#115 chore: login using radzen login component
Browse files Browse the repository at this point in the history
  • Loading branch information
joseantmazonsb committed Mar 17, 2022
1 parent b93d4a1 commit 7b19b69
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 48 deletions.
8 changes: 6 additions & 2 deletions Linguard/Auth/Models/Credentials.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
namespace Auth.Models;

public class Credentials : ICredentials {
public string Login { get; set; }
public string Password { get; set; }
public Credentials(string login, string password) {
Login = login;
Password = password;
}
public string Login { get; }
public string Password { get;}
}
4 changes: 2 additions & 2 deletions Linguard/Auth/Models/ICredentials.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Auth.Models;

public interface ICredentials {
public string Login { get; set; }
public string Password { get; set; }
public string Login { get; }
public string Password { get; }
}
50 changes: 7 additions & 43 deletions Linguard/Web/Pages/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,12 @@
@using global::Auth.Models
@using Linguard.Web.Services

<PageTitle>@($"{AssemblyInfo.Product} | {Title}")</PageTitle>
<PageTitle>@($"{AssemblyInfo.Product} | Sign in")</PageTitle>

<RadzenHeading Text="@Title" class="mb-3 text-center"/>
<RadzenCard class="align-items-center" Style="margin-bottom: 10rem">
<RadzenTemplateForm Data="@_credentials" Submit="@((ICredentials args) => { DoLogin(args); })">
<div class="row">
<div class="col">
<div class="row">
<div class="col">
<RadzenLabel Text="Username"/>
</div>
</div>
<div class="row mt-2">
<div class="col">
<RadzenTextBox Placeholder="michael_scott" @bind-Value="@_credentials.Login"/>
</div>
</div>
</div>
</div>
<div class="row mt-2">
<div class="col">
<div class="row">
<div class="col">
<RadzenLabel Text="Password"/>
</div>
</div>
<div class="row mt-2">
<div class="col">
<RadzenPassword @bind-Value="@_credentials.Password"/>
</div>
</div>
</div>
</div>
<div class="row mt-3 d-flex">
<div class="col-md-12 align-items-end">
<RadzenButton ButtonType="ButtonType.Submit" Icon="login" Text="Login" class="me-2"
ButtonStyle="ButtonStyle.Primary"/>
</div>
</div>
<RadzenHeading Text="Hello there!" class="mb-3 text-center"/>
<RadzenCard class="w-100" Style="margin-bottom: 10rem">
<RadzenTemplateForm Data="@("")">
<RadzenLogin AllowResetPassword="false" AllowRegister="false" Login="DoLogin"/>
</RadzenTemplateForm>
</RadzenCard>

Expand All @@ -54,12 +21,9 @@
@inject IAuthenticationService _authenticationService

@code {
const string Title = "Welcome!";

private readonly ICredentials _credentials = new Credentials();

private async void DoLogin(ICredentials credentials) {
private async void DoLogin(LoginArgs args) {
try {
var credentials = new Credentials(args.Username, args.Password);
var result = await _authenticationService.Login(credentials);
if (result.User.Identity is {IsAuthenticated: false }) {
_logger.LogError("Login failed: unable to authenticate user.");
Expand Down
2 changes: 1 addition & 1 deletion Linguard/Web/Shared/Layouts/LoginLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<RadzenLayout>
<ChildContent>
<RadzenBody @ref="_body" class="m-md-auto">
<RadzenBody @ref="_body" class="m-md-auto col-xxl-3">
<ChildContent>
<RadzenContentContainer Name="main">
<ErrorBoundary @ref="errorBoundary">
Expand Down

0 comments on commit 7b19b69

Please sign in to comment.