Connexion et inscription marche

pull/11/head
rahassou 2 years ago
parent 7255cd2aed
commit d5fe0df397

@ -9,7 +9,7 @@ namespace CraftSharp.Models
public string? UserName { get; set; } public string? UserName { get; set; }
[Required(ErrorMessage = "Le mot de passe est obligatoire.")] [Required(ErrorMessage = "Le mot de passe est obligatoire.")]
[MinLength(6, ErrorMessage = "Le mot de passe est trop court")] [MinLength(4, ErrorMessage = "Le mot de passe est trop court")]
public string? Password { get; set; } public string? Password { get; set; }
} }
} }

@ -6,15 +6,12 @@ namespace CraftSharp.Models
{ {
[Required(ErrorMessage = "Le pseudo est obligatoire.")] [Required(ErrorMessage = "Le pseudo est obligatoire.")]
[MinLength(4, ErrorMessage = "Le pseudo est trop long")] [MinLength(4, ErrorMessage = "Le pseudo est trop court")]
[MaxLength(50, ErrorMessage = "Le pseudo est trop long")]
public string? UserName { get; set; } public string? UserName { get; set; }
[Required(ErrorMessage = "L'email est obligatoire.")]
[RegularExpression(@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$", ErrorMessage = "Le format de l'email n'est pas correcte.")]
public string? Email { get; set; }
[Required(ErrorMessage = "Le mot de passe est obligatoire.")] [Required(ErrorMessage = "Le mot de passe est obligatoire.")]
[StringLength(50, ErrorMessage = "Le mot de passe est trop long")] [MinLength(4, ErrorMessage = "Le mot de passe est trop court")]
public string? Password { get; set; } public string? Password { get; set; }
[Required(ErrorMessage = "Vous devez confirmer votre mot de passe")] [Required(ErrorMessage = "Vous devez confirmer votre mot de passe")]

@ -18,11 +18,11 @@
<ValidationMessage For="@(() => loginRequest.Password)" /> <ValidationMessage For="@(() => loginRequest.Password)" />
<br /> <br />
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> <button class="btn btn-lg btn-primary btn-block" type="submit">Se connecter</button>
<br /> <br />
<label class="text-danger">@error</label> <label class="text-danger">@error</label>
<NavLink href="register"> <NavLink href="inscription">
<h6 class="font-weight-normal text-center">Creer un compte</h6> <h6 class="font-weight-normal text-center">Creer un compte</h6>
</NavLink> </NavLink>
</EditForm> </EditForm>

@ -12,6 +12,27 @@
<img src="images/@(Localizer["subtext-img"]).png" width="70%" /> <img src="images/@(Localizer["subtext-img"]).png" width="70%" />
<br /> <br />
Welcome to your new app. <AuthorizeView>
<Authorized>
<h1>Hello @context.User.Identity.Name !!</h1>
<p>Welcome to Blazor Learner.</p>
<ul>
@foreach (var claim in context.User.Claims)
{
<li>@claim.Type: @claim.Value</li>
}
</ul>
</Authorized>
<Authorizing>
<h1>Loading ...</h1>
</Authorizing>
<NotAuthorized>
<h1>Echec de la connexion!</h1>
<p>Vous n'etes pas connecté</p>
</NotAuthorized>
</AuthorizeView>
<SurveyPrompt Title="How is Blazor working for you?" /> <SurveyPrompt Title="How is Blazor working for you?" />

@ -5,11 +5,12 @@
<div class="option"> <div class="option">
<h1>Inscription</h1> <h1>Inscription</h1>
<div> <div>
<EditForm class="form-signin" OnValidSubmit="OnSubmit" Model="registerRequest"> <EditForm class="form-signin" OnValidSubmit="@OnSubmit" Model="@registerRequest">
<DataAnnotationsValidator /> <DataAnnotationsValidator />
<ValidationSummary />
<label for="inputUsername" class="sr-only">Pseudonyme</label> <label for="inputUsername" class="sr-only">Pseudonyme</label>
<InputText id="inputUsername" class="form-control" placeholder="Username" autofocus @bind-Value="@registerRequest.UserName" /> <InputText id="inputUsername" class="form-control" placeholder="Entrez votre pseudonyme" autofocus @bind-Value="@registerRequest.UserName" />
<ValidationMessage For="@(() => registerRequest.UserName)" /> <ValidationMessage For="@(() => registerRequest.UserName)" />
<br /> <br />
@ -23,10 +24,10 @@
<ValidationMessage For="@(() => registerRequest.PasswordConfirm)" /> <ValidationMessage For="@(() => registerRequest.PasswordConfirm)" />
<br /> <br />
<button class="btn btn-lg btn-primary btn-block" type="submit">S'inscrire'</button> <button class="btn btn-lg btn-primary btn-block" type="submit">S'inscrire</button>
<label class="text-danger">@error</label> <label class="text-danger">@error</label>
<NavLink href="login"> <NavLink href="connexion">
<h6 class="font-weight-normal text-center">Vous avez un compte ? Connectez vous</h6> <h6 class="font-weight-normal text-center">Vous avez un compte ? Connectez vous</h6>
</NavLink> </NavLink>
</EditForm> </EditForm>

@ -21,16 +21,10 @@ namespace CraftSharp.Pages
private async Task OnSubmit() private async Task OnSubmit()
{ {
error = null;
try
{
await AuthStateProvider.Register(registerRequest); await AuthStateProvider.Register(registerRequest);
NavigationManager.NavigateTo(""); NavigationManager.NavigateTo("");
}
catch (Exception ex)
{
error = ex.Message;
}
} }
} }
} }

@ -45,6 +45,7 @@
</button> </button>
<button @onclick=@goInscription> S'inscrire <button @onclick=@goInscription> S'inscrire
</button> </button>
<button type="button" class="btn btn-link ml-md-auto" @onclick="@LogoutClick">Se deconnecter</button>
</div> </div>
</div> </div>
</div> </div>

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Components; using CraftSharp.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
@ -9,6 +11,15 @@ namespace CraftSharp.Shared
[Inject] [Inject]
public IStringLocalizer<Index> Localizer { get; set; } public IStringLocalizer<Index> Localizer { get; set; }
[Inject]
public CustomStateProvider AuthStateProvider { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
[CascadingParameter]
private Task<AuthenticationState> AuthenticationState { get; set; }
void goInscription() void goInscription()
{ {
navigationManager.NavigateTo("inscription"); navigationManager.NavigateTo("inscription");
@ -18,5 +29,19 @@ namespace CraftSharp.Shared
{ {
navigationManager.NavigateTo("connexion"); navigationManager.NavigateTo("connexion");
} }
protected override async Task OnParametersSetAsync()
{
if (!(await AuthenticationState).User.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo("/inscription");
}
}
private async Task LogoutClick()
{
await AuthStateProvider.Logout();
NavigationManager.NavigateTo("/inscription");
}
} }
} }

@ -2,7 +2,6 @@
@inject NavigationManager navigationManager @inject NavigationManager navigationManager
<div class="connexionBody"> <div class="connexionBody">
<button @onclick=@getBack id="back">Retour</button>
<header> <header>
<img src="../images/CraftSharp-Logo.png"/> <img src="../images/CraftSharp-Logo.png"/>
</header> </header>

@ -6,9 +6,6 @@ namespace CraftSharp.Shared
{ {
public partial class InscriptionLayout public partial class InscriptionLayout
{ {
void getBack()
{
navigationManager.NavigateTo("");
}
} }
} }

@ -29,10 +29,10 @@ footer {
justify-content: space-between; justify-content: space-between;
} }
footer p { footer p {
color: white; color: white;
font-family: Minecraft; font-family: Minecraft;
} }
.p2 { .p2 {
float: right; float: right;
@ -50,3 +50,8 @@ button {
padding-top: 6px; padding-top: 6px;
font-family: Minecraft; font-family: Minecraft;
} }
h1 {
color: white;
font-family: Minecraft;
}

@ -10,4 +10,5 @@
@using CraftSharp.Shared @using CraftSharp.Shared
@using Blazorise.DataGrid @using Blazorise.DataGrid
@using Blazored.Modal @using Blazored.Modal
@using Blazored.Modal.Services @using Blazored.Modal.Services
@using Microsoft.AspNetCore.Components.Authorization
Loading…
Cancel
Save