Redesign login UI, add theme toggle, refactor user update
- Redesigned login page with two-panel layout and branding - Added HexaDistro logo and theme toggle to sidebar/header - Refactored user update: roles via update endpoint, removed assignRole API/controller - Extended UpdateUserRequest for username, role, password changes - UserService.UpdateAsync syncs changes with AuthHex, with rollback - Stock balances client dedupes by itemId-locationId - Middleware matcher excludes static assets from auth checks - Improved localStorage clearing for user context - Added lucide-react for icons - Minor UI/code cleanups for consistency and UX
This commit is contained in:
@@ -44,7 +44,7 @@ public class UserService(IUserRepository repo, IUnitOfWork uow, IAuthHexClient a
|
||||
email = request.Username,
|
||||
fullname = request.FullName,
|
||||
password = request.Password,
|
||||
roleId = request.RoleId,
|
||||
roleId = request.RoleId.ToString(),
|
||||
userTypeId = "00000001-0000-0000-0000-200000000000",
|
||||
sendCredentialsEmail = false
|
||||
}, reference: user.Id.ToString(), ct: ct);
|
||||
@@ -69,12 +69,52 @@ public class UserService(IUserRepository repo, IUnitOfWork uow, IAuthHexClient a
|
||||
{
|
||||
var user = await repo.GetByIdAsync(id);
|
||||
if (user is null || !user.IsActive) return null;
|
||||
|
||||
user.FullName = request.FullName;
|
||||
if (!string.IsNullOrWhiteSpace(request.Username))
|
||||
user.Username = request.Username;
|
||||
if (request.RoleId.HasValue)
|
||||
user.FK_RoleId = request.RoleId.Value;
|
||||
user.UpdatedAt = DateTime.Now;
|
||||
|
||||
await uow.BeginAsync(ct);
|
||||
try
|
||||
{
|
||||
repo.Update(user);
|
||||
|
||||
var hasUsernameChange = !string.IsNullOrWhiteSpace(request.Username);
|
||||
var hasRoleChange = request.RoleId.HasValue;
|
||||
|
||||
if (hasUsernameChange || hasRoleChange)
|
||||
{
|
||||
var payload = new Dictionary<string, object> { ["userId"] = user.Id.ToString() };
|
||||
if (hasUsernameChange) payload["userName"] = request.Username!;
|
||||
if (hasRoleChange) payload["roleCode"] = request.RoleId!.Value.ToString();
|
||||
|
||||
var authResult = await authHex.CallAsync("UpdateUser", payload, reference: user.Id.ToString(), ct: ct);
|
||||
if (!authResult.Success)
|
||||
{
|
||||
await uow.RollbackAsync(ct);
|
||||
throw new InvalidOperationException($"AuthHex update failed: {authResult.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.CurrentPassword) && !string.IsNullOrWhiteSpace(request.NewPassword))
|
||||
{
|
||||
var authResult = await authHex.CallAsync("ChangeUserPassword", new
|
||||
{
|
||||
userId = user.Id.ToString(),
|
||||
currentPassword = request.CurrentPassword,
|
||||
newPassword = request.NewPassword
|
||||
}, reference: user.Id.ToString(), ct: ct);
|
||||
|
||||
if (!authResult.Success)
|
||||
{
|
||||
await uow.RollbackAsync(ct);
|
||||
throw new InvalidOperationException($"AuthHex password change failed: {authResult.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
await uow.CommitAsync(ct);
|
||||
}
|
||||
catch
|
||||
@@ -87,22 +127,9 @@ public class UserService(IUserRepository repo, IUnitOfWork uow, IAuthHexClient a
|
||||
|
||||
public async Task<UserResponse?> AssignRoleAsync(Guid id, AssignUserRoleRequest request, CancellationToken ct = default)
|
||||
{
|
||||
var user = await repo.GetByIdAsync(id);
|
||||
if (user is null || !user.IsActive) return null;
|
||||
user.FK_RoleId = request.RoleId;
|
||||
user.UpdatedAt = DateTime.Now;
|
||||
await uow.BeginAsync(ct);
|
||||
try
|
||||
{
|
||||
repo.Update(user);
|
||||
await uow.CommitAsync(ct);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await uow.RollbackAsync(ct);
|
||||
throw;
|
||||
}
|
||||
return ToResponse(user);
|
||||
return await UpdateAsync(id, new UpdateUserRequest(
|
||||
FullName: (await repo.GetByIdAsync(id))?.FullName ?? string.Empty,
|
||||
RoleId: request.RoleId), ct);
|
||||
}
|
||||
|
||||
public async Task<bool> AssignScopeAsync(Guid id, AssignUserScopeRequest request, CancellationToken ct = default)
|
||||
|
||||
Reference in New Issue
Block a user