Enhance user authentication and management: add unverified user check, update error messages, and improve user interface for better usability
All checks were successful
Build And Push Dev Docker Image / docker (push) Successful in 1m52s

This commit is contained in:
troogs
2026-04-26 10:28:31 +02:00
parent 54effa67ac
commit 870930914e
4 changed files with 195 additions and 145 deletions

View File

@@ -1,4 +1,4 @@
using Blazorise.DataGrid;
using Blazorise;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Enums;
using FoodsharingSiegen.Contracts.Helper;
@@ -32,19 +32,24 @@ namespace FoodsharingSiegen.Server.Pages
private SetPasswordModal? PasswordModal { get; set; }
/// <summary>
/// Gets or sets the value of the selected company texts (ab)
/// Gets or sets the edit user modal
/// </summary>
private List<string> SelectedCompanyTexts { get; set; } = new();
private Modal? editUserModal { get; set; }
/// <summary>
/// Gets or sets the value of the selected user (ab)
/// Gets or sets the selected group texts
/// </summary>
private User? SelectedUser { get; set; }
private List<string> SelectedGroupTexts { get; set; } = new();
/// <summary>
/// Gets or sets the value of the user data grid (ab)
/// Gets or sets the edit model
/// </summary>
private DataGrid<User>? UserDataGrid { get; set; }
private User? EditModel { get; set; }
/// <summary>
/// Gets or sets a value indicating whether we are editing an existing user
/// </summary>
private bool IsEditing { get; set; }
/// <summary>
/// Gets the value of the user groups (ab)
@@ -56,6 +61,11 @@ namespace FoodsharingSiegen.Server.Pages
/// </summary>
private List<User>? UserList { get; set; }
/// <summary>
/// Gets the sorted users list
/// </summary>
private IEnumerable<User> SortedUsers => UserList?.OrderByDescending(x => x.Type).ThenBy(x => x.Name) ?? Enumerable.Empty<User>();
#endregion
#region Override InitializeDataAsync
@@ -84,6 +94,54 @@ namespace FoodsharingSiegen.Server.Pages
#endregion
#region Actions
private void CreateNewUser()
{
EditModel = new User();
IsEditing = false;
editUserModal?.Show();
}
private void EditUser(User user)
{
EditModel = user.Clone();
IsEditing = true;
editUserModal?.Show();
}
private void SetPassword(User user)
{
PasswordModal?.Show(user);
}
private async Task SaveUser()
{
if (EditModel == null) return;
if (IsEditing)
{
var updateR = await UserService.Update(EditModel);
if (!updateR.Success)
await Notification.Error($"Fehler beim Speichern: {updateR.ErrorMessage}")!;
else
await Notification.Success("Benutzer aktualisiert");
}
else
{
var addUserR = await UserService.AddUserAsync(EditModel);
if (!addUserR.Success)
await Notification.Error($"Fehler beim Anlegen: {addUserR.ErrorMessage}")!;
else
await Notification.Success("Benutzer erstellt");
}
await editUserModal?.Hide()!;
await LoadUsers();
}
#endregion
#region Private Method OnPasswordSet
/// <summary>
@@ -125,39 +183,5 @@ namespace FoodsharingSiegen.Server.Pages
}
#endregion
#region Private Method RowInserted
/// <summary>
/// Rows the inserted using the specified arg (a. beging, 01.04.2022)
/// </summary>
/// <param name="arg">The arg</param>
private async Task RowInserted(SavedRowItem<User, Dictionary<string, object>> arg)
{
var addUserR = await UserService.AddUserAsync(arg.OldItem);
if (!addUserR.Success)
await Notification.Error($"Fehler beim Anlegen: {addUserR.ErrorMessage}")!;
else
await LoadUsers();
}
#endregion
#region Private Method RowUpdated
/// <summary>
/// Rows the updated using the specified arg (a. beging, 01.04.2022)
/// </summary>
/// <param name="arg">The arg</param>
private async Task RowUpdated(SavedRowItem<User, Dictionary<string, object>> arg)
{
if (arg.OldItem?.Id == null || arg.OldItem.Id.Equals(Guid.Empty) || arg.Values?.Any() != true) return;
var updateR = await UserService.Update(arg.OldItem);
if (!updateR.Success)
await Notification.Error($"Fehler beim Speichern: {updateR.ErrorMessage}")!;
}
#endregion
}
}