initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
@page "/account/access-denied"
|
||||
@using Indotalent.Features.Root
|
||||
@using MudBlazor
|
||||
@layout MainLayout
|
||||
|
||||
<PageTitle>Access Denied - Insufficient Permissions</PageTitle>
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.Medium" Class="d-flex align-center justify-center" Style="height: calc(100vh - 64px);">
|
||||
|
||||
<div class="text-center">
|
||||
|
||||
<MudIcon Icon="@Icons.Material.Filled.GppBad"
|
||||
Size="Size.Large"
|
||||
Color="Color.Error"
|
||||
Class="mb-6"
|
||||
Style="font-size: 120px;" />
|
||||
|
||||
<MudText Typo="Typo.h3" Class="mb-4" Style="font-weight: 800; color: #1a1a1a;">Access Denied</MudText>
|
||||
|
||||
<MudText Typo="Typo.body1" Class="mb-6" Style="color: #64748b;">
|
||||
Sorry, you do not have the required permissions to access this module.<br />
|
||||
This area is restricted to authorized administrative personnel only.
|
||||
</MudText>
|
||||
|
||||
<MudPaper Elevation="1" Class="pa-4 mb-8 d-inline-block" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">
|
||||
<strong>Error Code:</strong> <code>AGS_AUTH_INSUFFICIENT_PERMISSIONS</code>
|
||||
</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #94a3b8; font-family: 'Consolas', monospace;">
|
||||
Verification failed for the current security context.
|
||||
</MudText>
|
||||
</MudPaper>
|
||||
|
||||
<div class="d-flex align-center justify-center gap-4">
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Large"
|
||||
OnClick="GoHome"
|
||||
StartIcon="@Icons.Material.Filled.Home"
|
||||
Style="border-radius: 0px; font-weight: 700;">
|
||||
Back to Home
|
||||
</MudButton>
|
||||
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Default"
|
||||
Size="Size.Large"
|
||||
OnClick="Logout"
|
||||
StartIcon="@Icons.Material.Filled.Logout"
|
||||
Style="border-radius: 0px; font-weight: 700; border: 2px solid #e2e8f0;">
|
||||
Logout & Switch Account
|
||||
</MudButton>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
[Inject] private NavigationManager Nav { get; set; } = default!;
|
||||
|
||||
private void GoHome() => Nav.NavigateTo("/");
|
||||
private void Logout() => Nav.NavigateTo("/account/logout");
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
@inject NavigationManager Navigation
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@attribute [AllowAnonymous]
|
||||
|
||||
<AuthorizeView>
|
||||
<NotAuthorized>
|
||||
@{
|
||||
var returnUrl = Navigation.ToBaseRelativePath(Navigation.Uri);
|
||||
Navigation.NavigateTo($"/account/login?returnUrl={Uri.EscapeDataString(returnUrl)}", forceLoad: false);
|
||||
}
|
||||
</NotAuthorized>
|
||||
<Authorized>
|
||||
@{
|
||||
Navigation.NavigateTo("/account/access-denied");
|
||||
}
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
using Indotalent.ConfigFrontEnd.Service;
|
||||
using Indotalent.Data.Entities;
|
||||
using Indotalent.Features.Account.ForgotPassword.Cqrs;
|
||||
using Indotalent.Features.Account.Login.Cqrs;
|
||||
using Indotalent.Features.Account.Register.Cqrs;
|
||||
using Indotalent.Features.Account.ResetPassword.Cqrs;
|
||||
using Indotalent.Features.Account.TenantSelection.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Indotalent.Features.Account;
|
||||
|
||||
public static class AccountEndPoint
|
||||
{
|
||||
public static IEndpointConventionBuilder MapAccountEndpoints(this IEndpointRouteBuilder endpoints)
|
||||
{
|
||||
var group = endpoints.MapGroup("/account").WithTags("Account");
|
||||
|
||||
group.MapPost("/signin-sso", async ([FromQuery] string email, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager, IOptions<JwtSettingsModel> jwtOptions, HttpContext context) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(email)) return Results.Json(new { status = 401, title = "Email is required" }, statusCode: 401);
|
||||
|
||||
var user = await userManager.FindByEmailAsync(email);
|
||||
|
||||
if (user == null || !user.IsActive)
|
||||
{
|
||||
return Results.Json(new { status = 401, title = "Account not found or inactive" }, statusCode: 401);
|
||||
}
|
||||
|
||||
var jwtSettings = jwtOptions.Value;
|
||||
var token = JwtService.GenerateNewJwt(user, jwtSettings);
|
||||
var refreshToken = Guid.NewGuid().ToString().Replace("-", "");
|
||||
|
||||
user.RefreshToken = refreshToken;
|
||||
user.LastLoginAt = DateTime.Now;
|
||||
await userManager.UpdateAsync(user);
|
||||
|
||||
await signInManager.SignInAsync(user, isPersistent: true);
|
||||
|
||||
context.Response.Cookies.Append("X-Auth-Token", token, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTimeOffset.UtcNow.AddDays(1)
|
||||
});
|
||||
|
||||
context.Response.Cookies.Append("X-Refresh-Token", refreshToken, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTimeOffset.UtcNow.AddDays(7)
|
||||
});
|
||||
|
||||
return Results.Ok(new { status = 200, title = "SSO Login successful" });
|
||||
});
|
||||
|
||||
group.MapGet("/active-user-exists", async ([FromQuery] string email, UserManager<ApplicationUser> userManager) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(email))
|
||||
{
|
||||
return Results.Ok(new { exists = false, isActive = false });
|
||||
}
|
||||
|
||||
var user = await userManager.FindByEmailAsync(email);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return Results.Ok(new { exists = false, isActive = false });
|
||||
}
|
||||
|
||||
return Results.Ok(new { exists = true, isActive = user.IsActive });
|
||||
});
|
||||
|
||||
group.MapPost("/signin", async ([FromBody] LoginRequest request, IMediator mediator, HttpContext context, UserManager<ApplicationUser> userManager) =>
|
||||
{
|
||||
var command = new LoginCommand(request);
|
||||
var response = await mediator.Send(command);
|
||||
|
||||
if (response.Succeeded)
|
||||
{
|
||||
var user = await userManager.FindByEmailAsync(request.Email);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
context.Response.Cookies.Append("X-Auth-Token", response.Token!, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTimeOffset.UtcNow.AddDays(1)
|
||||
});
|
||||
|
||||
context.Response.Cookies.Append("X-Refresh-Token", user.RefreshToken!, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTimeOffset.UtcNow.AddDays(7)
|
||||
});
|
||||
}
|
||||
|
||||
return Results.Ok(new { status = 200, title = response.Message });
|
||||
}
|
||||
return Results.Json(new { status = 401, title = response.Message }, statusCode: 401);
|
||||
});
|
||||
|
||||
|
||||
|
||||
group.MapPost("/refresh-token", async (HttpContext context) =>
|
||||
{
|
||||
var userManager = context.RequestServices.GetRequiredService<UserManager<ApplicationUser>>();
|
||||
var jwtSettings = context.RequestServices.GetRequiredService<IOptions<JwtSettingsModel>>().Value;
|
||||
|
||||
var refreshToken = context.Request.Headers["X-Refresh-Token"].ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(refreshToken)) return Results.Unauthorized();
|
||||
|
||||
var user = await userManager.Users.FirstOrDefaultAsync(u => u.RefreshToken == refreshToken);
|
||||
|
||||
if (user == null || !user.IsActive) return Results.Unauthorized();
|
||||
|
||||
var newToken = JwtService.GenerateNewJwt(user, jwtSettings);
|
||||
|
||||
context.Response.Cookies.Append("X-Auth-Token", newToken, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTimeOffset.UtcNow.AddDays(1)
|
||||
});
|
||||
|
||||
return Results.Ok(new LoginResponse { Succeeded = true, Token = newToken });
|
||||
});
|
||||
|
||||
group.MapPost("/signup", async ([FromBody] CreateUserRequest request, IMediator mediator) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = new CreateUserCommand(request);
|
||||
var response = await mediator.Send(command);
|
||||
return Results.Ok(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.BadRequest(new { errors = new[] { ex.Message } });
|
||||
}
|
||||
});
|
||||
|
||||
group.MapPost("/signout", async (
|
||||
SignInManager<ApplicationUser> signInManager,
|
||||
UserManager<ApplicationUser> userManager,
|
||||
HttpContext context) =>
|
||||
{
|
||||
var userId = context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
var user = await userManager.FindByIdAsync(userId);
|
||||
if (user != null)
|
||||
{
|
||||
user.RefreshToken = null;
|
||||
await userManager.UpdateAsync(user);
|
||||
}
|
||||
}
|
||||
|
||||
await signInManager.SignOutAsync();
|
||||
|
||||
context.Response.Cookies.Delete("X-Auth-Token");
|
||||
context.Response.Cookies.Delete("X-Refresh-Token");
|
||||
|
||||
return Results.Ok(new { status = 200, title = "Successfully signed out" });
|
||||
|
||||
});
|
||||
|
||||
group.MapPost("/forgot-password", async ([FromBody] ForgotPasswordRequest request, IMediator mediator) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = new ForgotPasswordCommand(request);
|
||||
var response = await mediator.Send(command);
|
||||
return Results.Ok(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.BadRequest(new { errors = new[] { ex.Message } });
|
||||
}
|
||||
});
|
||||
|
||||
group.MapPost("/logout", async (SignInManager<ApplicationUser> signInManager) =>
|
||||
{
|
||||
await signInManager.SignOutAsync();
|
||||
return Results.Ok(new { title = "Success user logout" });
|
||||
}).RequireAuthorization();
|
||||
|
||||
group.MapPost("/reset-password", async ([FromBody] ResetPasswordRequest request, IMediator mediator) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = new ResetPasswordCommand(request);
|
||||
var response = await mediator.Send(command);
|
||||
return Results.Ok(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.BadRequest(new { errors = new[] { ex.Message } });
|
||||
}
|
||||
});
|
||||
|
||||
group.MapGet("/my-tenants", async (IMediator mediator, HttpContext context) =>
|
||||
{
|
||||
var userId = context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrEmpty(userId)) return Results.Unauthorized();
|
||||
|
||||
var query = new GetTenantsQuery(userId);
|
||||
var response = await mediator.Send(query);
|
||||
return Results.Ok(response);
|
||||
}).RequireAuthorization();
|
||||
|
||||
group.MapPost("/confirm-tenant", async (
|
||||
[FromBody] ConfirmTenantRequest request,
|
||||
IMediator mediator,
|
||||
HttpContext context,
|
||||
SignInManager<ApplicationUser> signInManager,
|
||||
UserManager<ApplicationUser> userManager) =>
|
||||
{
|
||||
var userId = context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrEmpty(userId)) return Results.Unauthorized();
|
||||
|
||||
var command = new ConfirmTenantCommand(userId, request);
|
||||
var response = await mediator.Send(command);
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
return Results.Json(new { success = false, title = response.Message }, statusCode: 400);
|
||||
}
|
||||
|
||||
var user = await userManager.FindByIdAsync(userId);
|
||||
if (user == null) return Results.Unauthorized();
|
||||
|
||||
var principal = await signInManager.CreateUserPrincipalAsync(user);
|
||||
var identity = (ClaimsIdentity?)principal.Identity;
|
||||
|
||||
if (identity != null)
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.GroupSid, request.TenantId));
|
||||
var jwtClaims = new List<Claim>
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, user.Id ?? string.Empty),
|
||||
new Claim(ClaimTypes.Name, user.UserName ?? string.Empty),
|
||||
new Claim(ClaimTypes.Email, user.Email ?? string.Empty),
|
||||
new Claim(ClaimTypes.GivenName, user.FullName ?? string.Empty),
|
||||
new Claim(ClaimTypes.GroupSid, request.TenantId)
|
||||
};
|
||||
|
||||
var jwtSettings = context.RequestServices.GetRequiredService<IOptions<JwtSettingsModel>>().Value;
|
||||
var newToken = JwtService.GenerateNewJwtWithClaims(user, jwtClaims, jwtSettings);
|
||||
var newRefreshToken = Guid.NewGuid().ToString().Replace("-", "");
|
||||
|
||||
user.RefreshToken = newRefreshToken;
|
||||
await userManager.UpdateAsync(user);
|
||||
|
||||
context.Response.Cookies.Append("X-Auth-Token", newToken, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTimeOffset.UtcNow.AddDays(1)
|
||||
});
|
||||
|
||||
return Results.Ok(new { success = true, token = newToken });
|
||||
}
|
||||
|
||||
return Results.Json(new { success = false, title = "Failed to reconstruct security claims" }, statusCode: 400);
|
||||
}).RequireAuthorization();
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,606 @@
|
||||
@using Indotalent.Shared.Consts
|
||||
@inherits LayoutComponentBase
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<MudThemeProvider Theme="_theme" />
|
||||
<MudDialogProvider />
|
||||
<MudSnackbarProvider />
|
||||
<MudPopoverProvider />
|
||||
|
||||
<style>
|
||||
/* ===== FONT ===== */
|
||||
@@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;450;500;600;700;800&display=swap');
|
||||
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
/* ===== SPLIT CONTAINER ===== */
|
||||
.auth-split-container {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* ===== LEFT PANEL - GRADIENT BRANDING ===== */
|
||||
.auth-left-panel {
|
||||
width: 50%;
|
||||
background: linear-gradient(135deg, #6366F1 0%, #5558E6 30%, #4F46E5 60%, #4338CA 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.auth-left-panel::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -120px;
|
||||
right: -120px;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.auth-left-panel::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -80px;
|
||||
left: -80px;
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.auth-left-content {
|
||||
max-width: 28rem;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.auth-brand-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.auth-brand-icon {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 0.75rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
backdrop-filter: blur(8px);
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.auth-brand-icon:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.auth-brand-icon svg {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.auth-brand-name {
|
||||
color: #ffffff;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.auth-brand-sub {
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-size: 0.8125rem;
|
||||
}
|
||||
|
||||
.auth-welcome-title {
|
||||
color: #ffffff;
|
||||
font-size: 1.875rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.25;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.auth-welcome-desc {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.auth-feature-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
.auth-feature-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.auth-feature-check {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
border-radius: 0.25rem;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
margin-top: 0.125rem;
|
||||
}
|
||||
|
||||
.auth-feature-check svg {
|
||||
width: 0.75rem;
|
||||
height: 0.75rem;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.auth-feature-text-title {
|
||||
color: #ffffff;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.auth-feature-text-desc {
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-size: 0.75rem;
|
||||
margin-top: 0.125rem;
|
||||
}
|
||||
|
||||
.auth-support-card {
|
||||
padding: 1rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
backdrop-filter: blur(8px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 0.75rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.auth-support-avatar {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.auth-support-avatar svg {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.auth-support-title {
|
||||
color: #ffffff;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.auth-support-desc {
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
/* ===== RIGHT PANEL - FORM AREA ===== */
|
||||
.auth-right-panel {
|
||||
width: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 1.5rem;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.auth-form-wrapper {
|
||||
width: 100%;
|
||||
max-width: 28rem;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
border-radius: 1rem !important;
|
||||
border: 1px solid #e2e8f0 !important;
|
||||
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04) !important;
|
||||
background: #ffffff !important;
|
||||
}
|
||||
|
||||
.auth-card-footer {
|
||||
margin-top: 1rem;
|
||||
text-align: center;
|
||||
font-size: 0.75rem;
|
||||
color: #94a3b8;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
/* ===== MOBILE BRAND STRIP ===== */
|
||||
.auth-mobile-brand {
|
||||
display: none;
|
||||
text-align: center;
|
||||
padding: 1.25rem 1rem 0.75rem;
|
||||
background: linear-gradient(135deg, #6366F1 0%, #4F46E5 100%);
|
||||
}
|
||||
|
||||
.auth-mobile-brand-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.auth-mobile-brand-icon {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 0.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.auth-mobile-brand-icon svg {
|
||||
width: 1.125rem;
|
||||
height: 1.125rem;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.auth-mobile-brand-name {
|
||||
color: #ffffff;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* ===== RESPONSIVE ===== */
|
||||
@@media (max-width: 1023px) {
|
||||
.auth-left-panel {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.auth-right-panel {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
align-items: flex-start;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.auth-form-wrapper {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.auth-mobile-brand {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
border-radius: 0.75rem !important;
|
||||
}
|
||||
}
|
||||
|
||||
@@media (min-width: 1280px) {
|
||||
.auth-left-panel {
|
||||
padding: 4rem;
|
||||
}
|
||||
|
||||
.auth-right-panel {
|
||||
padding: 2.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== PAGE COMPONENTS SHARED STYLES ===== */
|
||||
.page-header {
|
||||
text-align: center;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.page-header h2 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: #0f172a;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.page-header p {
|
||||
font-size: 0.875rem;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: #475569;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.form-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.forgot-link {
|
||||
font-size: 0.8125rem;
|
||||
color: #64748b;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
.forgot-link:hover {
|
||||
color: #6366F1;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.remember-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.divider-or {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin: 1.5rem 0;
|
||||
}
|
||||
|
||||
.divider-or::before,
|
||||
.divider-or::after {
|
||||
content: '';
|
||||
flex: 1;
|
||||
height: 1px;
|
||||
background: #e2e8f0;
|
||||
}
|
||||
|
||||
.divider-or span {
|
||||
font-size: 0.75rem;
|
||||
color: #94a3b8;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.auth-link {
|
||||
color: #6366F1;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
.auth-link:hover {
|
||||
color: #4F46E5;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.btn-google {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 1rem;
|
||||
background: transparent;
|
||||
color: #475569;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
border-radius: 0.5rem;
|
||||
border: 1.5px solid #e2e8f0;
|
||||
transition: all 0.2s;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
font-family: "Poppins", sans-serif;
|
||||
}
|
||||
|
||||
.btn-google:hover {
|
||||
border-color: #c4b5fd;
|
||||
background: #f5f3ff;
|
||||
}
|
||||
|
||||
/* ===== LOGOUT / CONFIRM STYLES ===== */
|
||||
.logout-container,
|
||||
.confirm-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
padding: 1.5rem 0;
|
||||
}
|
||||
|
||||
.logout-icon-wrapper,
|
||||
.confirm-icon-wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.logout-icon-circle,
|
||||
.confirm-icon-circle {
|
||||
width: 5rem;
|
||||
height: 5rem;
|
||||
border-radius: 50%;
|
||||
background: rgba(99, 102, 241, 0.1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.logout-icon-circle svg,
|
||||
.confirm-icon-circle svg {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
color: #6366F1;
|
||||
}
|
||||
|
||||
.logout-title,
|
||||
.confirm-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: #0f172a;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.logout-desc,
|
||||
.confirm-desc {
|
||||
font-size: 0.875rem;
|
||||
color: #64748b;
|
||||
margin-bottom: 1.5rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="auth-split-container">
|
||||
|
||||
@* Left Panel - Branding *@
|
||||
<div class="auth-left-panel">
|
||||
<div class="auth-left-content">
|
||||
<div class="auth-brand-row">
|
||||
<div class="auth-brand-icon" @onclick="NavigateToHome">
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<div class="auth-brand-name">Blazor CRM</div>
|
||||
<div class="auth-brand-sub">Complete Source Code Solution</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 class="auth-welcome-title">Your Business,<br/>Your CRM, Your Way</h2>
|
||||
<p class="auth-welcome-desc">A complete, end-to-end CRM with full source code. Manage your leads, sales, purchases, and inventory — all in one place.</p>
|
||||
|
||||
<div class="auth-feature-list">
|
||||
<div class="auth-feature-item">
|
||||
<div class="auth-feature-check">
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<div class="auth-feature-text-title">Pipeline & Lead Management</div>
|
||||
<div class="auth-feature-text-desc">Campaigns, budgets, leads, contacts & sales team</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="auth-feature-item">
|
||||
<div class="auth-feature-check">
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<div class="auth-feature-text-title">Sales & Purchase</div>
|
||||
<div class="auth-feature-text-desc">Orders, invoices, payments & full procurement</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="auth-feature-item">
|
||||
<div class="auth-feature-check">
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<div class="auth-feature-text-title">Inventory & Reporting</div>
|
||||
<div class="auth-feature-text-desc">Products, warehouses, stock counts & full reports</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="auth-support-card">
|
||||
<div class="auth-support-avatar">
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M7.5 8.25h9m-9 3H12m-9.75 1.51c0 1.6 1.123 2.994 2.707 3.227 1.129.166 2.27.293 3.423.379.35.026.67.21.865.501L12 21l2.755-4.133a1.14 1.14 0 01.865-.501 48.172 48.172 0 003.423-.379c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0012 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<div class="auth-support-title">Production-Ready Source Code</div>
|
||||
<div class="auth-support-desc">Built with .NET 10, Blazor Server & MudBlazor 9</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Right Panel - Form Area *@
|
||||
<div class="auth-right-panel">
|
||||
|
||||
@* Mobile Brand Strip *@
|
||||
<div style="width: 100%; display: flex; flex-direction: column;">
|
||||
<div class="auth-mobile-brand">
|
||||
<div class="auth-mobile-brand-inner">
|
||||
<div class="auth-mobile-brand-icon">
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
|
||||
</svg>
|
||||
</div>
|
||||
<span class="auth-mobile-brand-name">@GlobalConsts.AppInitial</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="auth-form-wrapper" style="margin: 0 auto; width: 100%; max-width: 28rem; padding: 0 0.25rem;">
|
||||
<MudCard Elevation="0" Class="auth-card pa-2">
|
||||
<MudCardContent Class="pa-6">
|
||||
@Body
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
|
||||
<div class="auth-card-footer">
|
||||
© @DateTime.Now.Year @GlobalConsts.AppInitial. ALL RIGHTS RESERVED.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private MudTheme _theme = new()
|
||||
{
|
||||
PaletteLight = new PaletteLight()
|
||||
{
|
||||
Primary = "#6366F1",
|
||||
Secondary = "#818CF8",
|
||||
Tertiary = "#A5B4FC",
|
||||
AppbarBackground = "#6366F1",
|
||||
DrawerBackground = "#F8FAFC",
|
||||
Background = "#F8FAFC",
|
||||
Surface = "#FFFFFF",
|
||||
TextPrimary = "#1E293B",
|
||||
TextSecondary = "#64748B",
|
||||
Divider = "#E2E8F0",
|
||||
DividerLight = "#F1F5F9",
|
||||
},
|
||||
Typography = new Typography()
|
||||
{
|
||||
Default = new DefaultTypography()
|
||||
{
|
||||
FontFamily = new[] { "Poppins", "sans-serif" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void NavigateToHome()
|
||||
{
|
||||
Navigation.NavigateTo("/", forceLoad: true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
@page "/account/confirm-email"
|
||||
@layout AuthenticationLayout
|
||||
@using Indotalent.Shared.Consts
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
@using System.Text
|
||||
@using Indotalent.Data.Entities
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>Confirming Email - @GlobalConsts.AppInitial</PageTitle>
|
||||
|
||||
<div class="confirm-container">
|
||||
<div class="confirm-icon-wrapper">
|
||||
<div class="confirm-icon-circle">
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="confirm-title">Verifying Your Account</div>
|
||||
<div class="confirm-desc">Please wait while we validate your email address...</div>
|
||||
|
||||
<MudProgressCircular Color="Color.Primary" Indeterminate="true" Size="Size.Large" />
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[SupplyParameterFromQuery] public string? userId { get; set; }
|
||||
[SupplyParameterFromQuery] public string? code { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(code))
|
||||
{
|
||||
Snackbar.Add("Invalid or expired confirmation link.", Severity.Error);
|
||||
Navigation.NavigateTo("/account/login");
|
||||
return;
|
||||
}
|
||||
|
||||
var user = await UserManager.FindByIdAsync(userId);
|
||||
if (user == null)
|
||||
{
|
||||
Snackbar.Add("User record not found.", Severity.Error);
|
||||
Navigation.NavigateTo("/account/login");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var decodedCode = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
|
||||
var result = await UserManager.ConfirmEmailAsync(user, decodedCode);
|
||||
await Task.Delay(500);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
Snackbar.Add("Email verified successfully! You can now sign in.", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Verification failed. The link may have expired.", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Snackbar.Add("An error occurred during verification.", Severity.Error);
|
||||
}
|
||||
|
||||
Navigation.NavigateTo("/account/login");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
@page "/account/forgot-password"
|
||||
@layout AuthenticationLayout
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Indotalent.Shared.Consts
|
||||
@using Microsoft.JSInterop
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>Forgot Password - @GlobalConsts.AppInitial</PageTitle>
|
||||
|
||||
<div class="page-header">
|
||||
<h2>Forgot Password?</h2>
|
||||
<p>Enter your email address below and we'll send you a link to reset your password.</p>
|
||||
</div>
|
||||
|
||||
<MudForm @ref="form" @bind-IsValid="@success">
|
||||
|
||||
<label class="form-label">Email Address</label>
|
||||
<MudTextField T="string"
|
||||
@bind-Value="model.Email"
|
||||
Variant="Variant.Outlined"
|
||||
Placeholder="name@example.com"
|
||||
Margin="Margin.Dense"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Email"
|
||||
Required="true"
|
||||
Validation="@(new EmailAddressAttribute() { ErrorMessage = "Invalid email address format" })"
|
||||
For="@(() => model.Email)"
|
||||
Class="mb-6" />
|
||||
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Large"
|
||||
FullWidth="true"
|
||||
Disabled="!success || isProcessing"
|
||||
OnClick="HandleForgotPassword"
|
||||
Style="text-transform:none; border-radius: 8px; height: 48px; font-weight: 600;">
|
||||
@if (isProcessing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" Color="Color.Inherit" />
|
||||
<span class="ms-2">Sending link...</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Send Reset Link</span>
|
||||
}
|
||||
</MudButton>
|
||||
</MudForm>
|
||||
|
||||
<div style="text-align: center; margin-top: 1.5rem;">
|
||||
<span style="font-size: 0.875rem; color: #64748b;">
|
||||
Remember your password?
|
||||
<a class="auth-link" href="/account/login">Back to Sign In</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private MudForm form = default!;
|
||||
private bool success;
|
||||
private bool isProcessing;
|
||||
private ForgotPasswordModel model = new();
|
||||
|
||||
private class ForgotPasswordModel
|
||||
{
|
||||
public string Email { get; set; } = "";
|
||||
}
|
||||
|
||||
private async Task HandleForgotPassword()
|
||||
{
|
||||
await form.Validate();
|
||||
if (!success) return;
|
||||
|
||||
isProcessing = true;
|
||||
StateHasChanged();
|
||||
|
||||
var result = await JSRuntime.InvokeAsync<ApiResponse>("apiForgotPassword", model.Email);
|
||||
|
||||
if (result.Status == 200)
|
||||
{
|
||||
Snackbar.Add("If your email is registered, a reset link has been sent.", Severity.Success);
|
||||
await Task.Delay(500);
|
||||
Navigation.NavigateTo("/account/login");
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add(result.Title ?? "Failed to send reset link", Severity.Error);
|
||||
}
|
||||
|
||||
isProcessing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private class ApiResponse
|
||||
{
|
||||
public int Status { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
<script>
|
||||
window.apiForgotPassword = async (email) => {
|
||||
try {
|
||||
const response = await fetch('/api/account/forgot-password', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
return { status: 200, title: 'Success' };
|
||||
} else {
|
||||
const data = await response.json();
|
||||
let msg = 'Error processing request';
|
||||
if (data.errors && data.errors.length > 0) msg = data.errors[0];
|
||||
return { status: response.status, title: msg };
|
||||
}
|
||||
} catch (error) {
|
||||
return { status: 500, title: 'Network error' };
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,70 @@
|
||||
using Indotalent.Data.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using System.Text;
|
||||
|
||||
namespace Indotalent.Features.Account.ForgotPassword.Cqrs;
|
||||
|
||||
public class ForgotPasswordRequest
|
||||
{
|
||||
public string Email { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class ForgotPasswordResponse
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public record ForgotPasswordCommand(ForgotPasswordRequest Data) : IRequest<ForgotPasswordResponse>;
|
||||
|
||||
public class ForgotPasswordHandler : IRequestHandler<ForgotPasswordCommand, ForgotPasswordResponse>
|
||||
{
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly IEmailSender<ApplicationUser> _emailSender;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public ForgotPasswordHandler(
|
||||
UserManager<ApplicationUser> userManager,
|
||||
IEmailSender<ApplicationUser> emailSender,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_emailSender = emailSender;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public async Task<ForgotPasswordResponse> Handle(ForgotPasswordCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(request.Data.Email);
|
||||
|
||||
if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
|
||||
{
|
||||
return new ForgotPasswordResponse { Message = "If your email is registered, you will receive a reset link." };
|
||||
}
|
||||
|
||||
var code = await _userManager.GeneratePasswordResetTokenAsync(user);
|
||||
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||
|
||||
var requestHttp = _httpContextAccessor.HttpContext?.Request;
|
||||
var scheme = requestHttp?.Scheme ?? "https";
|
||||
var host = requestHttp?.Host.Value ?? "localhost:8080";
|
||||
|
||||
var callbackUrl = $"{scheme}://{host}/account/reset-password?userId={user.Id}&code={code}";
|
||||
|
||||
var message = $@"
|
||||
<div style=""font-family: Arial, sans-serif;"">
|
||||
<h3>Password Reset Request</h3>
|
||||
<p>Hello, {user.FullName}!</p>
|
||||
<p>We received a request to reset your password. Click the link below to proceed:</p>
|
||||
<p><a href=""{callbackUrl}"" style=""color: #2196F3; font-weight: bold;"">Reset Password</a></p>
|
||||
<br/>
|
||||
<p style=""font-size: 0.8em; color: #666;"">If you didn't request this, you can safely ignore this email.</p>
|
||||
<p style=""font-size: 0.8em; color: #666;"">{callbackUrl}</p>
|
||||
</div>";
|
||||
|
||||
await _emailSender.SendPasswordResetLinkAsync(user, user.Email!, message);
|
||||
|
||||
return new ForgotPasswordResponse { Message = "Reset link has been sent." };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
@page "/account/login"
|
||||
@layout AuthenticationLayout
|
||||
@using Indotalent.Shared.Consts
|
||||
@using Microsoft.JSInterop
|
||||
@using Indotalent.Infrastructure.Authentication.Identity
|
||||
@using Microsoft.Extensions.Options
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IOptions<IdentitySettingsModel> IdentityOptions
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>Sign In - @GlobalConsts.AppInitial</PageTitle>
|
||||
|
||||
<div class="page-header">
|
||||
<h2>Sign In</h2>
|
||||
<p>Enter your credentials to access your account</p>
|
||||
</div>
|
||||
|
||||
<MudForm @ref="form" @bind-IsValid="@success" Validation="@(new Func<EditContext, Task<bool>>(ValidateForm))" Class="w-100">
|
||||
|
||||
<label class="form-label">Email Address</label>
|
||||
<MudTextField T="string"
|
||||
@bind-Value="model.Email"
|
||||
Variant="Variant.Outlined"
|
||||
Placeholder="you@company.com"
|
||||
Margin="Margin.Dense"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Email"
|
||||
Required="true"
|
||||
For="@(() => model.Email)"
|
||||
Class="mb-4" />
|
||||
|
||||
<div class="form-label-row">
|
||||
<label class="form-label">Password</label>
|
||||
<a class="forgot-link" href="/account/forgot-password">Forgot password?</a>
|
||||
</div>
|
||||
<MudTextField T="string"
|
||||
@bind-Value="model.Password"
|
||||
Variant="Variant.Outlined"
|
||||
Placeholder="Enter your password"
|
||||
Margin="Margin.Dense"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Lock"
|
||||
InputType="@(showPassword ? InputType.Text : InputType.Password)"
|
||||
AdornmentEndIcon="@(showPassword? Icons.Material.Filled.Visibility : Icons.Material.Filled.VisibilityOff)"
|
||||
OnAdornmentEndClick="() => showPassword = !showPassword"
|
||||
Required="true"
|
||||
For="@(() => model.Password)"
|
||||
Class="mb-2" />
|
||||
|
||||
<div class="remember-row">
|
||||
<MudCheckBox T="bool"
|
||||
@bind-Value="rememberMe"
|
||||
Label="Remember me"
|
||||
Color="Color.Primary"
|
||||
Dense="true" />
|
||||
</div>
|
||||
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Large"
|
||||
FullWidth="true"
|
||||
Disabled="!success || isProcessing"
|
||||
OnClick="HandleLogin"
|
||||
Style="text-transform:none; border-radius: 8px; height: 48px; font-weight: 600;">
|
||||
@if (isProcessing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" Color="Color.Inherit" />
|
||||
<span class="ms-2">Signing in...</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Sign In</span>
|
||||
}
|
||||
</MudButton>
|
||||
|
||||
@if (IdentityOptions.Value.SsoFirebase.IsUsed)
|
||||
{
|
||||
<div class="divider-or">
|
||||
<span>Or continue with</span>
|
||||
</div>
|
||||
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
FullWidth="true"
|
||||
Size="Size.Large"
|
||||
Disabled="isProcessing"
|
||||
OnClick="HandleFirebaseGoogleLogin"
|
||||
StartIcon="@Icons.Custom.Brands.Google"
|
||||
Style="text-transform:none; border-radius: 8px; background-color: white; height: 44px; border: 1.5px solid #e2e8f0; font-weight: 500; color: #475569;">
|
||||
Sign in with Google
|
||||
</MudButton>
|
||||
}
|
||||
</MudForm>
|
||||
|
||||
<div style="text-align: center; margin-top: 1.5rem;">
|
||||
<span style="font-size: 0.875rem; color: #64748b;">
|
||||
Don't have an account?
|
||||
<a class="auth-link" href="/account/register">Create one</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private MudForm form = default!;
|
||||
private bool success;
|
||||
private bool isProcessing;
|
||||
private bool showPassword;
|
||||
private bool rememberMe;
|
||||
private LoginModel model = new();
|
||||
|
||||
private async Task<bool> ValidateForm(EditContext context) => await Task.FromResult(true);
|
||||
|
||||
private async Task HandleLogin()
|
||||
{
|
||||
await form.Validate();
|
||||
if (!success) return;
|
||||
isProcessing = true;
|
||||
StateHasChanged();
|
||||
|
||||
var result = await JSRuntime.InvokeAsync<ApiJSRuntimeResponse>("apiAccountSignIn", model.Email, model.Password, rememberMe);
|
||||
ProcessLoginResult(result);
|
||||
}
|
||||
|
||||
private async Task HandleFirebaseGoogleLogin()
|
||||
{
|
||||
isProcessing = true;
|
||||
StateHasChanged();
|
||||
|
||||
var firebaseUser = await JSRuntime.InvokeAsync<FirebaseUserResponse>("signInWithGoogle");
|
||||
|
||||
if (firebaseUser == null || string.IsNullOrEmpty(firebaseUser.Email))
|
||||
{
|
||||
Snackbar.Add("Google Sign-In failed or cancelled.", Severity.Error);
|
||||
isProcessing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var checkResult = await JSRuntime.InvokeAsync<ActiveCheckResponse>("apiCheckActiveUser", firebaseUser.Email);
|
||||
bool openForPublic = IdentityOptions.Value.SsoFirebase.OpenForPublic;
|
||||
|
||||
if (checkResult.Exists)
|
||||
{
|
||||
if (checkResult.IsActive)
|
||||
{
|
||||
await ExecuteSsoSignIn(firebaseUser.Email);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Account is registered but not active.", Severity.Warning);
|
||||
isProcessing = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var registerResult = await JSRuntime.InvokeAsync<ApiJSRuntimeResponse>(
|
||||
"apiAccountSignUpSso",
|
||||
firebaseUser.Email,
|
||||
firebaseUser.Email,
|
||||
openForPublic
|
||||
);
|
||||
|
||||
if (registerResult.Status == 200)
|
||||
{
|
||||
if (openForPublic)
|
||||
{
|
||||
await ExecuteSsoSignIn(firebaseUser.Email);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Registration successful. Please wait for admin approval.", Severity.Info);
|
||||
isProcessing = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Failed to auto-register account.", Severity.Error);
|
||||
isProcessing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteSsoSignIn(string email)
|
||||
{
|
||||
var result = await JSRuntime.InvokeAsync<ApiJSRuntimeResponse>("apiAccountSsoSignIn", email);
|
||||
ProcessLoginResult(result);
|
||||
}
|
||||
|
||||
private void ProcessLoginResult(ApiJSRuntimeResponse result)
|
||||
{
|
||||
if (result.Status == 200)
|
||||
{
|
||||
Snackbar.Add(result.Title ?? "Login successful!", Severity.Success);
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(500);
|
||||
Navigation.NavigateTo("/account/tenant-selection", forceLoad: true);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add(result.Title ?? "Sign in failed.", Severity.Error);
|
||||
isProcessing = false;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private class ApiJSRuntimeResponse { public int? Status { get; set; } public string? Title { get; set; } public string? Message { get; set; } }
|
||||
private class FirebaseUserResponse { public string? Email { get; set; } }
|
||||
private class ActiveCheckResponse { public bool Exists { get; set; } public bool IsActive { get; set; } }
|
||||
private class LoginModel { public string Email { get; set; } = ""; public string Password { get; set; } = ""; }
|
||||
}
|
||||
|
||||
<script>
|
||||
window.apiAccountSignIn = async (email, password, rememberMe) => {
|
||||
try {
|
||||
const response = await fetch('/api/account/signin', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, password, rememberMe }),
|
||||
credentials: 'include'
|
||||
});
|
||||
const result = await response.json();
|
||||
return { status: response.status, title: result.title };
|
||||
} catch (error) {
|
||||
return { status: 500, title: 'Network error' };
|
||||
}
|
||||
};
|
||||
|
||||
window.apiCheckActiveUser = async (email) => {
|
||||
try {
|
||||
const response = await fetch(`/api/account/active-user-exists?email=${encodeURIComponent(email)}`);
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
return { exists: false, isActive: false };
|
||||
}
|
||||
};
|
||||
|
||||
window.apiAccountSignUpSso = async (email, fullName, isOpenForPublic) => {
|
||||
try {
|
||||
const response = await fetch('/api/account/signup', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
email: email,
|
||||
fullName: fullName,
|
||||
password: 'SSO_AUTO_GENERATED_PASSWORD_123!',
|
||||
isActive: isOpenForPublic,
|
||||
emailConfirmed: isOpenForPublic
|
||||
})
|
||||
});
|
||||
const result = await response.json();
|
||||
return { status: response.status, message: result.message };
|
||||
} catch (error) {
|
||||
return { status: 500 };
|
||||
}
|
||||
};
|
||||
|
||||
window.apiAccountSsoSignIn = async (email) => {
|
||||
try {
|
||||
const response = await fetch(`/api/account/signin-sso?email=${encodeURIComponent(email)}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include'
|
||||
});
|
||||
const result = await response.json();
|
||||
return { status: response.status, title: result.title };
|
||||
} catch (error) {
|
||||
return { status: 500, title: 'SSO Network error' };
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,74 @@
|
||||
using Indotalent.ConfigFrontEnd.Service;
|
||||
using Indotalent.Data.Entities;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Indotalent.Features.Account.Login.Cqrs;
|
||||
|
||||
public class LoginRequest
|
||||
{
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public bool RememberMe { get; set; }
|
||||
}
|
||||
|
||||
public class LoginResponse
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
public bool IsNotAllowed { get; set; }
|
||||
public string? Token { get; set; }
|
||||
public string? RefreshToken { get; set; }
|
||||
}
|
||||
|
||||
public record LoginCommand(LoginRequest Data) : IRequest<LoginResponse>;
|
||||
|
||||
public class LoginHandler : IRequestHandler<LoginCommand, LoginResponse>
|
||||
{
|
||||
private readonly SignInManager<ApplicationUser> _signInManager;
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly JwtSettingsModel _jwtSettings;
|
||||
|
||||
public LoginHandler(
|
||||
SignInManager<ApplicationUser> signInManager,
|
||||
UserManager<ApplicationUser> userManager,
|
||||
IOptions<JwtSettingsModel> jwtSettings)
|
||||
{
|
||||
_signInManager = signInManager;
|
||||
_userManager = userManager;
|
||||
_jwtSettings = jwtSettings.Value;
|
||||
}
|
||||
|
||||
public async Task<LoginResponse> Handle(LoginCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(request.Data.Email);
|
||||
if (user == null) return new LoginResponse { Succeeded = false, Message = "Invalid credentials" };
|
||||
|
||||
var result = await _signInManager.PasswordSignInAsync(user, request.Data.Password, request.Data.RememberMe, false);
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
var token = JwtService.GenerateNewJwt(user, _jwtSettings);
|
||||
|
||||
var refreshToken = Guid.NewGuid().ToString().Replace("-", "");
|
||||
|
||||
user.RefreshToken = refreshToken;
|
||||
user.LastLoginAt = DateTime.Now;
|
||||
await _userManager.UpdateAsync(user);
|
||||
|
||||
return new LoginResponse
|
||||
{
|
||||
Succeeded = true,
|
||||
Message = "Login successful",
|
||||
Token = token,
|
||||
RefreshToken = refreshToken
|
||||
};
|
||||
}
|
||||
|
||||
return new LoginResponse { Succeeded = false, Message = "Invalid credentials" };
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
@page "/account/logout"
|
||||
@layout AuthenticationLayout
|
||||
|
||||
@using Indotalent.Shared.Consts
|
||||
@using Microsoft.JSInterop
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<PageTitle>Sign Out - @GlobalConsts.AppInitial</PageTitle>
|
||||
|
||||
<div class="logout-container">
|
||||
<div class="logout-icon-wrapper">
|
||||
<div class="logout-icon-circle">
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="logout-title">Sign Out</div>
|
||||
<div class="logout-desc">Are you sure you want to sign out of your account?</div>
|
||||
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Size="Size.Large"
|
||||
FullWidth="true"
|
||||
Disabled="@isLoggingOut"
|
||||
OnClick="Logout"
|
||||
Style="text-transform:none; border-radius: 8px; background-color: #6366F1; color: white; height: 48px; font-weight: 600;">
|
||||
@if (isLoggingOut)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" Color="Color.Inherit" />
|
||||
<span class="ms-2">Signing out...</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Sign Out</span>
|
||||
}
|
||||
</MudButton>
|
||||
|
||||
<MudButton Variant="Variant.Text"
|
||||
Class="mt-3"
|
||||
FullWidth="true"
|
||||
Href="/account/tenant-selection"
|
||||
Disabled="@isLoggingOut"
|
||||
Style="text-transform:none; color: #94A3B8; font-weight: 600; border-radius: 8px;">
|
||||
Cancel
|
||||
</MudButton>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private bool isLoggingOut;
|
||||
|
||||
private async Task Logout()
|
||||
{
|
||||
isLoggingOut = true;
|
||||
StateHasChanged();
|
||||
|
||||
var result = await JSRuntime.InvokeAsync<ApiJSRuntimeResponse>("apiAccountLogout");
|
||||
|
||||
if (result.Status == 200)
|
||||
{
|
||||
Snackbar.Add("Successfully signed out!", Severity.Success);
|
||||
await Task.Delay(500);
|
||||
Navigation.NavigateTo("/", forceLoad: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add(result.Title ?? "Failed to logout.", Severity.Error);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
isLoggingOut = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private class ApiJSRuntimeResponse
|
||||
{
|
||||
public int? Status { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
<script>
|
||||
window.apiAccountLogout = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/account/signout', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
credentials: 'include'
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Unknown error occurred');
|
||||
}
|
||||
return { status: 200, title: 'Success user logout' };
|
||||
} catch (error) {
|
||||
return { status: 500, title: 'Server / Network error' };
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,183 @@
|
||||
@page "/account/register"
|
||||
@layout AuthenticationLayout
|
||||
|
||||
@using Indotalent.Shared.Consts
|
||||
@using Microsoft.JSInterop
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Navigation
|
||||
@inject IConfiguration Configuration
|
||||
|
||||
<PageTitle>Sign Up - @GlobalConsts.AppInitial</PageTitle>
|
||||
|
||||
<div class="page-header">
|
||||
<h2>Sign Up</h2>
|
||||
<p>Please register your account</p>
|
||||
</div>
|
||||
|
||||
<MudForm @ref="form" @bind-IsValid="@success" Validation="@(new Func<EditContext, Task<bool>>(ValidateForm))">
|
||||
|
||||
<label class="form-label">Full Name</label>
|
||||
<MudTextField T="string"
|
||||
@bind-Value="model.FullName"
|
||||
Variant="Variant.Outlined"
|
||||
Placeholder="Enter your full name"
|
||||
Margin="Margin.Dense"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Person"
|
||||
Required="true"
|
||||
For="@(() => model.FullName)"
|
||||
Class="mb-4" />
|
||||
|
||||
<label class="form-label">Email Address</label>
|
||||
<MudTextField T="string"
|
||||
@bind-Value="model.Email"
|
||||
Variant="Variant.Outlined"
|
||||
Placeholder="Enter your email"
|
||||
Margin="Margin.Dense"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Email"
|
||||
Required="true"
|
||||
For="@(() => model.Email)"
|
||||
Class="mb-4" />
|
||||
|
||||
<label class="form-label">Password</label>
|
||||
<MudTextField T="string"
|
||||
@bind-Value="model.Password"
|
||||
Variant="Variant.Outlined"
|
||||
Placeholder="Create a password"
|
||||
Margin="Margin.Dense"
|
||||
InputType="@(showPassword ? InputType.Text : InputType.Password)"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Lock"
|
||||
AdornmentEndIcon="@(showPassword? Icons.Material.Filled.Visibility : Icons.Material.Filled.VisibilityOff)"
|
||||
OnAdornmentEndClick="() => showPassword = !showPassword"
|
||||
Required="true"
|
||||
For="@(() => model.Password)"
|
||||
Class="mb-6" />
|
||||
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Large"
|
||||
FullWidth="true"
|
||||
Disabled="!success || isProcessing"
|
||||
OnClick="HandleRegister"
|
||||
Style="text-transform:none; border-radius: 8px; height: 48px; font-weight: 600;">
|
||||
@if (isProcessing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" Color="Color.Inherit" />
|
||||
<span class="ms-2">Creating account...</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Create Account</span>
|
||||
}
|
||||
</MudButton>
|
||||
</MudForm>
|
||||
|
||||
<div style="text-align: center; margin-top: 1.5rem;">
|
||||
<span style="font-size: 0.875rem; color: #64748b;">
|
||||
Already have an account?
|
||||
<a class="auth-link" href="/account/login">Sign In</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private MudForm form = default!;
|
||||
private bool success;
|
||||
private bool isProcessing;
|
||||
private bool showPassword;
|
||||
|
||||
private RegisterModel model = new();
|
||||
|
||||
private class RegisterModel
|
||||
{
|
||||
public string FullName { get; set; } = "";
|
||||
public string Email { get; set; } = "";
|
||||
public string Password { get; set; } = "";
|
||||
}
|
||||
|
||||
private async Task<bool> ValidateForm(EditContext context)
|
||||
{
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private async Task HandleRegister()
|
||||
{
|
||||
await form.Validate();
|
||||
|
||||
if (!success) return;
|
||||
|
||||
isProcessing = true;
|
||||
StateHasChanged();
|
||||
|
||||
var result = await JSRuntime.InvokeAsync<ApiJSRuntimeResponse>("apiAccountRegister", model.FullName, model.Email, model.Password);
|
||||
|
||||
if (result.Status == 200)
|
||||
{
|
||||
var requireConfirmation = Configuration.GetValue<bool>("IdentitySettings:SignIn:RequireConfirmedAccount");
|
||||
|
||||
if (requireConfirmation)
|
||||
{
|
||||
Snackbar.Add("Registration successful! Please check your email to confirm your account.", Severity.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Registration successful! You can now sign in.", Severity.Success);
|
||||
}
|
||||
|
||||
await Task.Delay(500);
|
||||
Navigation.NavigateTo("/account/login");
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add(result.Title ?? "Registration failed", Severity.Error);
|
||||
}
|
||||
|
||||
isProcessing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private class ApiJSRuntimeResponse
|
||||
{
|
||||
public int? Status { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
<script>
|
||||
window.apiAccountRegister = async (fullName, email, password) => {
|
||||
try {
|
||||
const response = await fetch('/api/account/signup', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ fullName, email, password })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
return { status: 200, title: 'Success account registration' };
|
||||
} else {
|
||||
let errorMessage = data.title || data.message || 'Registration failed';
|
||||
|
||||
if (data.errors) {
|
||||
if (Array.isArray(data.errors) && data.errors.length > 0) {
|
||||
errorMessage = data.errors[0];
|
||||
} else if (typeof data.errors === 'object') {
|
||||
const firstKey = Object.keys(data.errors)[0];
|
||||
if (firstKey) {
|
||||
errorMessage = data.errors[firstKey][0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { status: response.status, title: errorMessage };
|
||||
}
|
||||
} catch (error) {
|
||||
return { status: 500, title: 'Server / Network error' };
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,131 @@
|
||||
using Indotalent.Data.Entities;
|
||||
using Indotalent.Infrastructure.Authorization.Identity;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Text;
|
||||
|
||||
namespace Indotalent.Features.Account.Register.Cqrs;
|
||||
|
||||
public class CreateUserRequest
|
||||
{
|
||||
public string FullName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public bool IsActive { get; set; } = true;
|
||||
public bool EmailConfirmed { get; set; } = false;
|
||||
}
|
||||
|
||||
public class CreateUserResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
|
||||
public record CreateUserCommand(CreateUserRequest Data) : IRequest<CreateUserResponse>;
|
||||
|
||||
public class RegisterHandler : IRequestHandler<CreateUserCommand, CreateUserResponse>
|
||||
{
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly IEmailSender<ApplicationUser> _emailSender;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public RegisterHandler(
|
||||
UserManager<ApplicationUser> userManager,
|
||||
IEmailSender<ApplicationUser> emailSender,
|
||||
IConfiguration configuration,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
AppDbContext context)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_emailSender = emailSender;
|
||||
_configuration = configuration;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<CreateUserResponse> Handle(CreateUserCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = new ApplicationUser
|
||||
{
|
||||
UserName = request.Data.Email,
|
||||
Email = request.Data.Email,
|
||||
FullName = request.Data.FullName,
|
||||
IsActive = request.Data.IsActive,
|
||||
EmailConfirmed = request.Data.EmailConfirmed,
|
||||
};
|
||||
|
||||
var result = await _userManager.CreateAsync(user, request.Data.Password);
|
||||
|
||||
if (!result.Succeeded)
|
||||
{
|
||||
var errors = result.Errors.Select(x => x.Description).ToList();
|
||||
throw new Exception(string.Join(", ", errors));
|
||||
}
|
||||
|
||||
// Assign default roles: Member and TenantAdmin (but not Admin)
|
||||
var rolesToAdd = new List<string> { ApplicationRoles.Member, ApplicationRoles.TenantAdmin };
|
||||
|
||||
await _userManager.AddToRolesAsync(user, rolesToAdd);
|
||||
|
||||
// Create default tenant for the new user
|
||||
var tenant = new Data.Entities.Tenant
|
||||
{
|
||||
Name = "Default Tenant",
|
||||
Description = $"Default tenant for {request.Data.Email}",
|
||||
EmailAddress = request.Data.Email,
|
||||
IsActive = true
|
||||
};
|
||||
|
||||
_context.Tenant.Add(tenant);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Create TenantUser linking the user to the default tenant
|
||||
var tenantUser = new Data.Entities.TenantUser
|
||||
{
|
||||
TenantId = tenant.Id,
|
||||
UserId = user.Id,
|
||||
Summary = $"Default tenant assignment for {request.Data.FullName}",
|
||||
IsActive = true
|
||||
};
|
||||
|
||||
_context.TenantUser.Add(tenantUser);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
var requireConfirmation = _configuration.GetValue<bool>("IdentitySettings:SignIn:RequireConfirmedAccount");
|
||||
|
||||
if (requireConfirmation)
|
||||
{
|
||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||
|
||||
var requestHttp = _httpContextAccessor.HttpContext?.Request;
|
||||
var scheme = requestHttp?.Scheme ?? "https";
|
||||
var host = requestHttp?.Host.Value ?? "localhost:8080";
|
||||
|
||||
var callbackUrl = $"{scheme}://{host}/account/confirm-email?userId={user.Id}&code={code}";
|
||||
|
||||
var message = $@"
|
||||
<div style=""font-family: Arial, sans-serif;"">
|
||||
<h3>Welcome, {user.FullName}!</h3>
|
||||
<p>Please confirm your account by clicking the link below:</p>
|
||||
<p><a href=""{callbackUrl}"" style=""color: #2196F3; font-weight: bold; text-decoration: underline;"">Confirm Account</a></p>
|
||||
<br/>
|
||||
<p style=""font-size: 0.8em; color: #666;"">If the link doesn't work, copy and paste this URL into your browser:</p>
|
||||
<p style=""font-size: 0.8em; color: #666;"">{callbackUrl}</p>
|
||||
</div>";
|
||||
|
||||
await _emailSender.SendConfirmationLinkAsync(user, user.Email!, message);
|
||||
}
|
||||
|
||||
return new CreateUserResponse
|
||||
{
|
||||
Id = user.Id,
|
||||
Email = user.Email
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
@page "/account/reset-password"
|
||||
@layout AuthenticationLayout
|
||||
@using Indotalent.Shared.Consts
|
||||
@using Microsoft.JSInterop
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>Reset Password - @GlobalConsts.AppInitial</PageTitle>
|
||||
|
||||
<div class="page-header">
|
||||
<h2>Create New Password</h2>
|
||||
<p>Please enter your new password below.</p>
|
||||
</div>
|
||||
|
||||
<MudForm @ref="form" @bind-IsValid="@success">
|
||||
<label class="form-label">New Password</label>
|
||||
<MudTextField T="string"
|
||||
@bind-Value="model.NewPassword"
|
||||
Variant="Variant.Outlined"
|
||||
Placeholder="Enter new password"
|
||||
Margin="Margin.Dense"
|
||||
InputType="@(showPassword ? InputType.Text : InputType.Password)"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Lock"
|
||||
AdornmentEndIcon="@(showPassword? Icons.Material.Filled.Visibility : Icons.Material.Filled.VisibilityOff)"
|
||||
OnAdornmentEndClick="() => showPassword = !showPassword"
|
||||
Required="true"
|
||||
Class="mb-4" />
|
||||
|
||||
<label class="form-label">Confirm New Password</label>
|
||||
<MudTextField T="string"
|
||||
@bind-Value="model.ConfirmPassword"
|
||||
Variant="Variant.Outlined"
|
||||
Placeholder="Repeat new password"
|
||||
Margin="Margin.Dense"
|
||||
InputType="@(showPassword ? InputType.Text : InputType.Password)"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Lock"
|
||||
Required="true"
|
||||
Validation="@(new Func<string, string?>(PasswordMatch))"
|
||||
Class="mb-6" />
|
||||
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Large"
|
||||
FullWidth="true"
|
||||
Disabled="!success || isProcessing"
|
||||
OnClick="HandleResetPassword"
|
||||
Style="text-transform:none; border-radius: 8px; height: 48px; font-weight: 600;">
|
||||
@if (isProcessing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" Color="Color.Inherit" />
|
||||
<span class="ms-2">Resetting...</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Reset Password</span>
|
||||
}
|
||||
</MudButton>
|
||||
</MudForm>
|
||||
|
||||
@code {
|
||||
[SupplyParameterFromQuery] public string? userId { get; set; }
|
||||
[SupplyParameterFromQuery] public string? code { get; set; }
|
||||
|
||||
private MudForm form = default!;
|
||||
private bool success;
|
||||
private bool isProcessing;
|
||||
private bool showPassword;
|
||||
private ResetModel model = new();
|
||||
|
||||
private class ResetModel
|
||||
{
|
||||
public string NewPassword { get; set; } = "";
|
||||
public string ConfirmPassword { get; set; } = "";
|
||||
}
|
||||
|
||||
private string? PasswordMatch(string arg)
|
||||
{
|
||||
if (model.NewPassword != arg) return "Passwords do not match";
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task HandleResetPassword()
|
||||
{
|
||||
await form.Validate();
|
||||
if (!success) return;
|
||||
|
||||
if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(code))
|
||||
{
|
||||
Snackbar.Add("Invalid reset token or user ID.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
isProcessing = true;
|
||||
StateHasChanged();
|
||||
|
||||
var result = await JSRuntime.InvokeAsync<ApiResponse>("apiResetPassword", userId, code, model.NewPassword);
|
||||
|
||||
if (result.Status == 200)
|
||||
{
|
||||
Snackbar.Add("Password reset successful! You can now sign in.", Severity.Success);
|
||||
await Task.Delay(500);
|
||||
Navigation.NavigateTo("/account/login");
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add(result.Title ?? "Failed to reset password", Severity.Error);
|
||||
}
|
||||
|
||||
isProcessing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private class ApiResponse
|
||||
{
|
||||
public int Status { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
<script>
|
||||
window.apiResetPassword = async (userId, code, newPassword) => {
|
||||
try {
|
||||
const response = await fetch('/api/account/reset-password', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ userId, code, newPassword })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
return { status: 200, title: 'Success' };
|
||||
} else {
|
||||
const data = await response.json();
|
||||
let msg = 'Failed to reset password';
|
||||
if (data.errors && data.errors.length > 0) msg = data.errors[0];
|
||||
return { status: response.status, title: msg };
|
||||
}
|
||||
} catch (error) {
|
||||
return { status: 500, title: 'Network error' };
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.Data.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using System.Text;
|
||||
|
||||
namespace Indotalent.Features.Account.ResetPassword.Cqrs;
|
||||
|
||||
public class ResetPasswordRequest
|
||||
{
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
public string Code { get; set; } = string.Empty;
|
||||
public string NewPassword { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class ResetPasswordResponse
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public record ResetPasswordCommand(ResetPasswordRequest Data) : IRequest<ResetPasswordResponse>;
|
||||
|
||||
public class ResetPasswordHandler : IRequestHandler<ResetPasswordCommand, ResetPasswordResponse>
|
||||
{
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
|
||||
public ResetPasswordHandler(UserManager<ApplicationUser> userManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public async Task<ResetPasswordResponse> Handle(ResetPasswordCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await _userManager.FindByIdAsync(request.Data.UserId);
|
||||
if (user == null)
|
||||
{
|
||||
throw new Exception("User not found.");
|
||||
}
|
||||
|
||||
var decodedCode = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(request.Data.Code));
|
||||
var result = await _userManager.ResetPasswordAsync(user, decodedCode, request.Data.NewPassword);
|
||||
|
||||
if (!result.Succeeded)
|
||||
{
|
||||
var errors = result.Errors.Select(x => x.Description).ToList();
|
||||
throw new Exception(string.Join(", ", errors));
|
||||
}
|
||||
|
||||
return new ResetPasswordResponse { Message = "Password has been reset successfully." };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
@page "/account/tenant-selection"
|
||||
@layout AuthenticationLayout
|
||||
@using Indotalent.Shared.Consts
|
||||
@attribute [Authorize]
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.JSInterop
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<PageTitle>Select Tenant - @GlobalConsts.AppInitial</PageTitle>
|
||||
|
||||
<div class="page-header">
|
||||
<h2>Select Tenant</h2>
|
||||
<p>Please select a tenant to continue</p>
|
||||
</div>
|
||||
|
||||
<div class="w-100">
|
||||
@if (isLoading)
|
||||
{
|
||||
<div style="display: flex; justify-content: center; padding: 3rem 0;">
|
||||
<MudProgressCircular Color="Color.Primary" Indeterminate="true" Size="Size.Large" />
|
||||
</div>
|
||||
}
|
||||
else if (!myTenants.Any())
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Variant="Variant.Outlined" Class="my-4" Style="border-radius: 8px;">
|
||||
You don't have access to any tenant. Please contact your Administrator.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div style="max-height: 320px; overflow-y: auto; padding-right: 4px;">
|
||||
<MudList T="TenantDto" Clickable="true" SelectionMode="SelectionMode.SingleSelection" Class="pa-0">
|
||||
@foreach (var item in myTenants)
|
||||
{
|
||||
<MudListItem OnClick="() => HandleSelectTenant(item.TenantId)"
|
||||
Icon="@Icons.Material.Filled.Business"
|
||||
IconColor="Color.Primary"
|
||||
Class="py-3 my-2"
|
||||
Style="border: 1px solid #e2e8f0; border-radius: 8px; background-color: #f8fafc; transition: all 0.2s ease-in-out;">
|
||||
<ChildContent>
|
||||
<div class="d-flex flex-column">
|
||||
<MudText Typo="Typo.subtitle1" Style="font-weight: 700; color: #0f172a;">
|
||||
@item.TenantName
|
||||
</MudText>
|
||||
@if (!string.IsNullOrEmpty(item.Description))
|
||||
{
|
||||
<MudText Typo="Typo.caption" Style="color: #64748b;">
|
||||
@item.Description
|
||||
</MudText>
|
||||
}
|
||||
</div>
|
||||
</ChildContent>
|
||||
</MudListItem>
|
||||
}
|
||||
</MudList>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div style="text-align: center; margin-top: 1.5rem;">
|
||||
<span style="font-size: 0.875rem; color: #64748b;">
|
||||
Want to sign in with another account?
|
||||
<a class="auth-link" href="/account/logout">Sign Out</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private bool isLoading = true;
|
||||
private List<TenantDto> myTenants = new();
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
myTenants = await JSRuntime.InvokeAsync<List<TenantDto>>("apiAccountFetchMyTenants");
|
||||
isLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleSelectTenant(string tenantId)
|
||||
{
|
||||
var result = await JSRuntime.InvokeAsync<ApiResult>("apiAccountConfirmTenant", tenantId);
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
Snackbar.Add("Tenant workspace loaded successfully.", Severity.Success);
|
||||
Navigation.NavigateTo("/home", forceLoad: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Failed to assign tenant workspace.", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public class TenantDto { public string TenantId { get; set; } = ""; public string TenantName { get; set; } = ""; public string? Description { get; set; } }
|
||||
public class ApiResult { public bool Success { get; set; } }
|
||||
}
|
||||
|
||||
<script>
|
||||
window.apiAccountFetchMyTenants = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/account/my-tenants', {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
});
|
||||
if (response.status === 200) {
|
||||
return await response.json();
|
||||
}
|
||||
return [];
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
window.apiAccountConfirmTenant = async (tenantId) => {
|
||||
try {
|
||||
const response = await fetch('/api/account/confirm-tenant', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ tenantId }),
|
||||
credentials: 'include'
|
||||
});
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
return { success: false };
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,67 @@
|
||||
using Indotalent.Data.Entities;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Account.TenantSelection.Cqrs;
|
||||
|
||||
public record GetTenantsQuery(string UserId) : IRequest<List<TenantLookupDto>>;
|
||||
|
||||
public class TenantLookupDto
|
||||
{
|
||||
public string TenantId { get; set; } = string.Empty;
|
||||
public string TenantName { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public class GetTenantsHandler : IRequestHandler<GetTenantsQuery, List<TenantLookupDto>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetTenantsHandler(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<List<TenantLookupDto>> Handle(GetTenantsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Set<TenantUser>()
|
||||
.IgnoreQueryFilters()
|
||||
.Where(tu => tu.UserId == request.UserId && tu.IsActive)
|
||||
.Select(tu => new TenantLookupDto
|
||||
{
|
||||
TenantId = tu.TenantId ?? string.Empty,
|
||||
TenantName = tu.Tenant != null ? (tu.Tenant.Name ?? "Unknown") : "Unknown",
|
||||
Description = tu.Tenant != null ? (tu.Tenant.Description ?? "") : ""
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public record ConfirmTenantRequest(string TenantId);
|
||||
public record ConfirmTenantResponse(bool Success, string Message);
|
||||
public record ConfirmTenantCommand(string UserId, ConfirmTenantRequest Data) : IRequest<ConfirmTenantResponse>;
|
||||
|
||||
public class ConfirmTenantHandler : IRequestHandler<ConfirmTenantCommand, ConfirmTenantResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public ConfirmTenantHandler(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<ConfirmTenantResponse> Handle(ConfirmTenantCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var hasAccess = await _context.Set<TenantUser>()
|
||||
.IgnoreQueryFilters()
|
||||
.AnyAsync(tu => tu.UserId == request.UserId && tu.TenantId == request.Data.TenantId && tu.IsActive, cancellationToken);
|
||||
|
||||
if (!hasAccess)
|
||||
{
|
||||
return new ConfirmTenantResponse(false, "Access denied to the selected organization.");
|
||||
}
|
||||
|
||||
return new ConfirmTenantResponse(true, "Tenant authorized.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
@using MudBlazor
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
Reference in New Issue
Block a user