Skip to content

Commit

Permalink
Merge pull request #401 from NielsPilgaard/feature/login-overhaul
Browse files Browse the repository at this point in the history
make login+register look better
  • Loading branch information
NielsPilgaard authored Jul 28, 2024
2 parents b265bc0 + 8cc6f8c commit d1a47e4
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 101 deletions.
100 changes: 44 additions & 56 deletions src/web/Jordnaer/Components/Account/Pages/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,53 @@

@inject SignInManager<ApplicationUser> SignInManager
@inject ILogger<Login> Logger
@inject NavigationManager NavigationManager
@inject IdentityRedirectManager RedirectManager

<MetadataComponent Title="Log ind"/>

<h1>Log ind</h1>
<div class="row">
<div class="col-md-4">
<section>
<StatusMessage Message="@_errorMessage" />
<EditForm Model="Input" method="post" OnValidSubmit="LoginUser" FormName="login">
<DataAnnotationsValidator />
<hr />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="[email protected]" />
<label for="email" class="form-label">Email</label>
<ValidationMessage For="() => Input.Email" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.Password" class="form-control" autocomplete="current-password" aria-required="true" placeholder="adgangskode" />
<label for="password" class="form-label">Adgangskode</label>
<ValidationMessage For="() => Input.Password" class="text-danger" />
</div>
<div class="checkbox mb-3">
<label class="form-label">
<InputCheckbox @bind-Value="Input.RememberMe" class="darker-border-checkbox form-check-input" />
Husk mig
</label>
</div>
<div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Log ind</button>
</div>
<div>
<p>
<a href="Account/ForgotPassword">Glemt din adgangskode?</a>
</p>
<p>
<a href="@(NavigationManager.GetUriWithQueryParameters("Account/Register", new Dictionary<string, object?> { ["ReturnUrl"] = ReturnUrl }))">Registrer som ny bruger</a>
</p>
<p>
<a href="Account/ResendEmailConfirmation">Gensend emailbekræftelse</a>
</p>
</div>
</EditForm>
</section>
</div>
<div class="col-md-6 col-md-offset-2">
<section>
<h3>Brug en anden tjeneste til at logge ind.</h3>
<hr />
<ExternalLoginPicker />
</section>
</div>
</div>
<MudContainer MaxWidth="MaxWidth.Small">
<MudPaper Elevation="3" Class="pa-4">
<EditForm Model="Input" OnValidSubmit="LoginUser" FormName="login">
<StatusMessage Message="@_errorMessage"/>
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="[email protected]" />
<label for="email" class="form-label">Email</label>
<ValidationMessage For="() => Input.Email" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.Password" class="form-control" autocomplete="current-password" aria-required="true" placeholder="adgangskode" />
<label for="password" class="form-label">Adgangskode</label>
<ValidationMessage For="() => Input.Password" class="text-danger" />
</div>
<div class="checkbox mb-3">
<label class="form-label">
<InputCheckbox @bind-Value="Input.RememberMe" class="darker-border-checkbox form-check-input" />
Husk mig
</label>
</div>
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Info" FullWidth>
Log ind
</MudButton>
<MudDivider DividerType="DividerType.FullWidth" Class="my-3"/>
<MudStack>
<MudLink Href="/Account/ForgotPassword">Glemt din adgangskode?</MudLink>
<MudLink Href="/Account/ResendEmailConfirmation">Gensend emailbekræftelse</MudLink>
<MudButton ButtonType="ButtonType.Button"
Variant="Variant.Filled"
Color="Color.Success"
FullWidth
Href="/Account/Register">
Opret ny konto
</MudButton>
</MudStack>
</EditForm>
</MudPaper>
<MudPaper Elevation="3" Class="pa-4 mt-4">
<ExternalLoginPicker />
</MudPaper>
</MudContainer>

@code {
private AlertMessage? _errorMessage;

[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;

Expand All @@ -80,8 +69,7 @@

public async Task LoginUser()
{
// TODO: Set lockoutOnFailure to true to prevent brute forcing
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true);
if (result.Succeeded)
{
Logger.LogInformation("User logged in.");
Expand All @@ -91,7 +79,7 @@
{
RedirectManager.RedirectTo(
"Account/LoginWith2fa",
new() { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe });
new Dictionary<string, object?> { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe });
}
else if (result.IsLockedOut)
{
Expand Down
72 changes: 33 additions & 39 deletions src/web/Jordnaer/Components/Account/Pages/Register.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,38 @@
@inject IdentityRedirectManager RedirectManager
@inject IDbContextFactory<JordnaerDbContext> DbContextFactory

<PageTitle>Registrer</PageTitle>

<h1>Registrer</h1>
<PageTitle>Opret en ny konto</PageTitle>
@*TODO: This page needs some UI love*@
<div class="row">
<div class="col-md-4">
<StatusMessage Message="@Message" />
<EditForm Model="Input" asp-route-returnUrl="@ReturnUrl" method="post" OnValidSubmit="RegisterUser" FormName="register">
<DataAnnotationsValidator />
<h2>Opret en ny konto.</h2>
<hr />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" class="form-control" autocomplete="email" aria-required="true" placeholder="[email protected]" />
<label for="email">Email</label>
<ValidationMessage For="() => Input.Email" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.Password" class="form-control" autocomplete="new-password" aria-required="true" placeholder="" />
<label for="password">Kodeord</label>
<ValidationMessage For="() => Input.Password" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" placeholder="" />
<label for="confirm-password">Bekræft kodeord</label>
<ValidationMessage For="() => Input.ConfirmPassword" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Registrer</button>
<MudContainer MaxWidth="MaxWidth.Small">

<MudPaper Elevation="3" Class="pa-4" >
<StatusMessage Message="@Message" />
<EditForm Model="Input" asp-route-returnUrl="@ReturnUrl" method="post" OnValidSubmit="RegisterUser" FormName="register">
<DataAnnotationsValidator />
<h2 class="font-open-sans-medium" style="@($"color: {JordnaerPalette.RedHeader}")">Opret en ny konto</h2>
<hr />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" class="form-control" autocomplete="email" aria-required="true" placeholder="[email protected]" />
<label for="email">Email</label>
<ValidationMessage For="() => Input.Email" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.Password" class="form-control" autocomplete="new-password" aria-required="true" placeholder="" />
<label for="password">Kodeord</label>
<ValidationMessage For="() => Input.Password" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" placeholder="" />
<label for="confirm-password">Bekræft kodeord</label>
<ValidationMessage For="() => Input.ConfirmPassword" class="text-danger" />
</div>
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Success" FullWidth>Opret</MudButton>
</EditForm>
</div>
<div class="col-md-6 col-md-offset-2">
<section>
<h3>Brug en anden tjeneste til at registrere dig.</h3>
<hr />
<ExternalLoginPicker />
</section>
</div>

</div>
</MudPaper>
<MudPaper Elevation="3" Class="pa-4 mt-4">
<ExternalLoginPicker />
</MudPaper>
</MudContainer>

@code {
private IEnumerable<IdentityError>? _identityErrors;
Expand All @@ -61,9 +55,9 @@
[SupplyParameterFromQuery]
private string? ReturnUrl { get; set; }

private AlertMessage? Message => _identityErrors is null
? null
: new AlertMessage(_identityErrors.Select(error => error.Description), true);
private AlertMessage? Message => _identityErrors is null
? null
: new AlertMessage(_identityErrors.Select(error => error.Description), true);

public async Task RegisterUser(EditContext editContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@inject SignInManager<ApplicationUser> SignInManager
@inject IdentityRedirectManager RedirectManager

@if (_externalLogins.Length == 0)
{
<div>
Expand All @@ -12,8 +13,8 @@
}
else
{
<form class="form-horizontal" action="Account/PerformExternalLogin" method="post">
<MudStack Justify="Justify.Center" Style="max-width: 400px">
<form class="d-flex justify-content-center" action="Account/PerformExternalLogin" method="post">
<MudStack Style="width: 500px">
<AntiforgeryToken />
<input type="hidden" name="ReturnUrl" value="@ReturnUrl" />
@foreach (var provider in _externalLogins)
Expand All @@ -26,6 +27,7 @@ else
Style="background-color: #3B5998;
color: white;"
ButtonType="ButtonType.Submit"
FullWidth
name="provider"
value="@provider.Name">
Log ind med Facebook
Expand All @@ -37,6 +39,7 @@ else
Style="background-color: #dd4b39;
color: white;"
ButtonType="ButtonType.Submit"
FullWidth
name="provider"
value="@provider.Name">
Log ind med Google
Expand All @@ -47,6 +50,7 @@ else
Variant="Variant.Filled"
Color="Color.Primary"
ButtonType="ButtonType.Submit"
FullWidth
name="provider"
value="@provider.Name">
Log ind med Microsoft
Expand Down
2 changes: 1 addition & 1 deletion src/web/Jordnaer/Pages/Groups/MyGroups.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Description="Oversigt over dine grupper, og dine afventende anmodninger"/>

<MudButton
Href="groups/create"
Href="/groups/create"
Variant="Variant.Filled"
Color="Color.Success"
StartIcon="@Icons.Material.Filled.GroupAdd">
Expand Down
8 changes: 5 additions & 3 deletions src/web/Jordnaer/Pages/Shared/TopBar.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@inject NavigationManager Navigation

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / test

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(370,16)-(370,72)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / test

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(384,16)-(384,72)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / test

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(410,20)-(410,83)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / test

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(424,20)-(424,75)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / test

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(440,20)-(440,76)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(370,16)-(370,72)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(384,16)-(384,72)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(410,20)-(410,83)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(424,20)-(424,75)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(440,20)-(440,76)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(370,16)-(370,72)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(384,16)-(384,72)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(410,20)-(410,83)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(424,20)-(424,75)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(440,20)-(440,76)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(370,16)-(370,72)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/web/Jordnaer/Pages/Shared/TopBar.razor

View workflow job for this annotation

GitHub Actions / deploy

Illegal Attribute 'Title' on 'MudIconButton' using pattern 'LowerCase' source location '(384,16)-(384,72)' (https://mudblazor.com/features/analyzers)

<MudAppBar Fixed="false" Elevation="0" Dense Style="@($"background: {JordnaerTheme.CustomTheme.PaletteLight.BackgroundGray}")">
<MudIconButton Href="/users" Title="Personer" Icon="@Icons.Material.Filled.PersonSearch" />
<MudIconButton Href="/groups" Title="Grupper" Icon="@Icons.Material.Filled.Groups" />
Expand All @@ -22,11 +24,11 @@
else
{
} *@
<MudIconButton Title="Redigér Profil" Href="profile" Icon="@Icons.Material.Filled.Person" />
<MudIconButton Title="Log ud" Href="Account/Logout" Icon="@Icons.Material.Filled.Logout" />
<MudIconButton Title="Redigér Profil" Href="/profile" Icon="@Icons.Material.Filled.Person" />
<MudIconButton Title="Log ud" Href="/Account/Logout" Icon="@Icons.Material.Filled.Logout" />
</Authorized>
<NotAuthorized>
<MudIconButton Title="Log ind" Href="/Account/Login" Icon="@Icons.Material.Filled.Login" Variant="Variant.Outlined" Color="Color.Default" />
</NotAuthorized>
</AuthorizeView>
</MudAppBar>
</MudAppBar>

0 comments on commit d1a47e4

Please sign in to comment.