Added mail system. Added password reset and email verify. Switched to new event system. Added event based mail sending
This commit is contained in:
65
Moonlight/Shared/Components/Auth/ChangePassword.razor
Normal file
65
Moonlight/Shared/Components/Auth/ChangePassword.razor
Normal file
@@ -0,0 +1,65 @@
|
||||
@using Moonlight.App.Services
|
||||
@using Moonlight.App.Services.Users
|
||||
@using Moonlight.App.Models.Forms
|
||||
@using Moonlight.App.Models.Enums
|
||||
|
||||
@inject IdentityService IdentityService
|
||||
@inject UserService UserService
|
||||
|
||||
<div class="w-100">
|
||||
<div class="card-body">
|
||||
<div class="text-start mb-8">
|
||||
<h1 class="text-dark mb-3 fs-3x">
|
||||
Change your password
|
||||
</h1>
|
||||
<div class="text-gray-400 fw-semibold fs-6">
|
||||
You need to change your password in order to continue
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SmartForm Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="fv-row mb-7">
|
||||
<input @bind="Form.Password" type="password" placeholder="Password" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-7">
|
||||
<input @bind="Form.RepeatedPassword" type="password" placeholder="Repeat password" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-stack">
|
||||
<button type="submit" class="btn btn-primary me-2 flex-shrink-0">Continue</button>
|
||||
</div>
|
||||
</SmartForm>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private UpdateAccountPasswordForm Form = new();
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
if (Form.Password != Form.RepeatedPassword)
|
||||
throw new DisplayException("The password do not match");
|
||||
|
||||
// Because of UserService.Auth.ChangePassword may logout the user before we can reset the flag
|
||||
// we reset the flag before changing the password and if any error occurs we simple set it again
|
||||
|
||||
try
|
||||
{
|
||||
IdentityService.Flags[UserFlag.PasswordPending] = false;
|
||||
await IdentityService.SaveFlags();
|
||||
|
||||
await UserService.Auth.ChangePassword(IdentityService.CurrentUser, Form.Password);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
IdentityService.Flags[UserFlag.PasswordPending] = true;
|
||||
await IdentityService.SaveFlags();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
await IdentityService.Authenticate();
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-stack flex-wrap gap-3 fs-base fw-semibold mb-10">
|
||||
<a href="/reset-password" class="link-primary">
|
||||
<a href="/password-reset" class="link-primary">
|
||||
Forgot Password ?
|
||||
</a>
|
||||
<a href="/register" class="link-primary">
|
||||
|
||||
46
Moonlight/Shared/Components/Auth/MailVerify.razor
Normal file
46
Moonlight/Shared/Components/Auth/MailVerify.razor
Normal file
@@ -0,0 +1,46 @@
|
||||
@using Moonlight.App.Services.Users
|
||||
@using Moonlight.App.Services
|
||||
|
||||
@inject UserService UserService
|
||||
@inject IdentityService IdentityService
|
||||
|
||||
<div class="w-100">
|
||||
<div class="card-body">
|
||||
@if (HasBeenSend)
|
||||
{
|
||||
<div class="text-start mb-8">
|
||||
<h1 class="text-dark mb-3 fs-3x">
|
||||
Email verification sent
|
||||
</h1>
|
||||
<div class="text-gray-400 fw-semibold fs-6">
|
||||
You should receive an email shortly. If you see no email in your inbox, look inside your spam folder
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="text-start mb-8">
|
||||
<h1 class="text-dark mb-3 fs-3x">
|
||||
Verify your email address
|
||||
</h1>
|
||||
<div class="text-gray-400 fw-semibold fs-6">
|
||||
We will sent you an email to verify your account
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<WButton OnClick="Send" Text="Continue" CssClasses="btn btn-primary me-2 flex-shrink-0" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private bool HasBeenSend = false;
|
||||
|
||||
private async Task Send()
|
||||
{
|
||||
await UserService.Auth.SendVerification(IdentityService.CurrentUser);
|
||||
HasBeenSend = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
56
Moonlight/Shared/Components/Auth/PasswordReset.razor
Normal file
56
Moonlight/Shared/Components/Auth/PasswordReset.razor
Normal file
@@ -0,0 +1,56 @@
|
||||
@page "/password-reset"
|
||||
|
||||
@using Moonlight.App.Services.Users
|
||||
@using Moonlight.App.Models.Forms
|
||||
|
||||
@inject UserService UserService
|
||||
|
||||
<div class="w-100">
|
||||
<div class="card-body">
|
||||
@if (HasBeenSend)
|
||||
{
|
||||
<div class="text-start mb-8">
|
||||
<h1 class="text-dark mb-3 fs-3x">
|
||||
Password reset email sent
|
||||
</h1>
|
||||
<div class="text-gray-400 fw-semibold fs-6">
|
||||
You should receive the email shortly. If you see no email in your inbox, look inside your spam folder
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="text-start mb-8">
|
||||
<h1 class="text-dark mb-3 fs-3x">
|
||||
Reset your password
|
||||
</h1>
|
||||
<div class="text-gray-400 fw-semibold fs-6">
|
||||
We will sent you an email to reset your account password
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SmartForm Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="fv-row mb-8">
|
||||
<input @bind="Form.Email" type="text" placeholder="Email" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-stack">
|
||||
<button type="submit" class="btn btn-primary me-2 flex-shrink-0">Continue</button>
|
||||
</div>
|
||||
</SmartForm>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private bool HasBeenSend = false;
|
||||
private ResetPasswordForm Form = new();
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await UserService.Auth.SendResetPassword(Form.Email);
|
||||
HasBeenSend = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@
|
||||
ErrorMessages.Add(displayException.Message);
|
||||
}
|
||||
else
|
||||
throw e;
|
||||
throw;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -37,7 +37,14 @@
|
||||
<div class="menu-item px-3">
|
||||
<div class="menu-content d-flex align-items-center px-3">
|
||||
<div class="symbol symbol-50px me-5">
|
||||
<img alt="Logo" src="/metronic8/demo38/assets/media/avatars/300-2.jpg">
|
||||
@if (IdentityService.CurrentUser.Avatar == null)
|
||||
{
|
||||
<img src="/assets/img/avatar.png" alt="Avatar">
|
||||
}
|
||||
else
|
||||
{
|
||||
<img src="/api/bucket/avatars/@(IdentityService.CurrentUser.Avatar)" alt="Avatar">
|
||||
}
|
||||
</div>
|
||||
<div class="d-flex flex-column">
|
||||
<div class="fw-bold d-flex align-items-center fs-5">
|
||||
@@ -73,7 +80,7 @@
|
||||
{
|
||||
[CascadingParameter]
|
||||
public DefaultLayout Layout { get; set; }
|
||||
|
||||
|
||||
private async Task Logout()
|
||||
{
|
||||
await IdentityService.Authenticate("");
|
||||
|
||||
@@ -22,9 +22,15 @@
|
||||
{
|
||||
if (!IdentityService.Flags[UserFlag.MailVerified] && ConfigService.Get().Security.EnableEmailVerify)
|
||||
{
|
||||
<OverlayLayout>
|
||||
<MailVerify />
|
||||
</OverlayLayout>
|
||||
}
|
||||
else if (IdentityService.Flags[UserFlag.PasswordPending])
|
||||
{
|
||||
<OverlayLayout>
|
||||
<ChangePassword />
|
||||
</OverlayLayout>
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -43,6 +49,12 @@
|
||||
<Register />
|
||||
</OverlayLayout>
|
||||
}
|
||||
else if (url.LocalPath == "/password-reset")
|
||||
{
|
||||
<OverlayLayout>
|
||||
<PasswordReset />
|
||||
</OverlayLayout>
|
||||
}
|
||||
else
|
||||
{
|
||||
<OverlayLayout>
|
||||
|
||||
Reference in New Issue
Block a user