Skip to content

Commit

Permalink
Merge pull request neozhu#726 from neozhu/improveloginfo
Browse files Browse the repository at this point in the history
Improveloginfo
  • Loading branch information
neozhu authored Aug 16, 2024
2 parents 5298cd8 + 91b2340 commit f3cd08b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task Handle(ResetPasswordNotification notification, CancellationTok
notification.UserName,
notification.Email
});
_logger.LogInformation("Password rest email sent to {Email}. sending result {Successful} {ErrorMessages}",
notification.Email, sendMailResult.Successful, string.Join(' ', sendMailResult.ErrorMessages));
_logger.LogInformation("Password rest email sent to {Email}. Reset Password Callback URL: {RequestUrl} sending result {Successful} {ErrorMessages}",
notification.Email, notification.RequestUrl, sendMailResult.Successful, string.Join(' ', sendMailResult.ErrorMessages));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task Handle(SendFactorCodeNotification notification, CancellationTo
notification.AuthenticatorCode, _settings.AppName, notification.Email, notification.UserName,
_settings.Company
});
_logger.LogInformation("Verification Code email sent to {Email}. sending result {Successful} {ErrorMessages}",
notification.Email, sendMailResult.Successful, string.Join(' ', sendMailResult.ErrorMessages));
_logger.LogInformation("Verification Code email sent to {Email}. Authenticator Code:{AuthenticatorCode} sending result {Successful} {ErrorMessages}",
notification.Email, notification.AuthenticatorCode,sendMailResult.Successful, string.Join(' ', sendMailResult.ErrorMessages));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task Handle(UserActivationNotification notification, CancellationTo
notification.UserName,
notification.Email
});
_logger.LogInformation("Activation email sent to {Email}. sending result {Successful} {Message}",
notification.Email, sendMailResult.Successful, string.Join(' ', sendMailResult.ErrorMessages));
_logger.LogInformation("Activation email sent to {Email}, Activation Callback URL: {ActivationUrl}. sending result {Successful} {Message}, ",
notification.Email, notification.ActivationUrl,sendMailResult.Successful, string.Join(' ', sendMailResult.ErrorMessages));
}
}
12 changes: 8 additions & 4 deletions src/Server.UI/Pages/Identity/Authentication/ExternalLogin.razor
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,16 @@

if (result.Succeeded)
{
Logger.LogInformation(
"{Name} logged in with {LoginProvider} provider.",
externalLoginInfo.Principal.Identity?.Name,
Logger.LogInformation("{UserName} successfully logged in using {LoginProvider} external provider.",
externalLoginInfo.Principal.Identity?.Name ?? "Unknown User",
externalLoginInfo.LoginProvider);
RedirectManager.RedirectTo(ReturnUrl);
}
else if (result.IsLockedOut)
{
Logger.LogWarning("{UserName} is locked out during login attempt with {LoginProvider} external provider.",
externalLoginInfo.Principal.Identity?.Name ?? "Unknown User",
externalLoginInfo.LoginProvider);
RedirectManager.RedirectTo(Lockout.PageUrl);
}

Expand Down Expand Up @@ -184,7 +186,9 @@
return;
}

Logger.LogInformation("{UserName} created an account using {Name} provider.", Input.Email, externalLoginInfo.LoginProvider);
Logger.LogInformation("A new account was created for user '{UserName}' using the external login provider '{LoginProvider}'.",
Input.Email,
externalLoginInfo.LoginProvider);

if (UserManager.Options.SignIn.RequireConfirmedEmail)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Server.UI/Pages/Identity/Authentication/Register.razor
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@
}

var userId = await UserManager.GetUserIdAsync(user);
Logger.LogInformation("{UserName} created a new account with password.", Input.UserName);
Logger.LogInformation("New user account created. Username: {UserName}, User ID: {UserId}, Tenant ID: {TenantId}, Assigned Role: {RoleName}.",
Input.UserName,
userId,
Input.TenantId,
RoleName.Basic);
if (UserManager.Options.SignIn.RequireConfirmedEmail)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);
Expand Down
27 changes: 11 additions & 16 deletions src/Server.UI/Pages/Identity/Users/Users.razor
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
@if (_canSearch)
{
<MudStack Row="true" AlignItems="AlignItems.Stretch">
<MudSelect T="string" Placeholder="@L["Search by role name"]" Value="@_searchRole" Clearable="true" ValueChanged="@(OnSearchRole)" Style="width:150px">
<MudSelect T="string" Placeholder="Search for role name" Value="@_searchRole" Clearable="true" ValueChanged="@(OnSearchRole)" Style="width:150px">
@foreach (var str in _roles)
{
<MudSelectItem Value="@str">@str</MudSelectItem>
Expand Down Expand Up @@ -223,7 +223,7 @@
</PropertyColumn>
<PropertyColumn Property="x => x.UserName" Title="@L[_currentDto.GetMemberDescription(x => x.UserName)]">
<CellTemplate>
<div class="d-flex align-center">
<div class="d-flex align-items-center">
<MudBadge Color="@(IsOnline(context.Item.DisplayName??context.Item.UserName) ? Color.Success : Color.Error)" Overlap="false" Dot="true" Bordered="true">
<MudAvatar>
@if (string.IsNullOrEmpty(context.Item.ProfilePictureDataUrl))
Expand Down Expand Up @@ -286,18 +286,19 @@
<PropertyColumn Property="x => x.IsActive" Title="@L[_currentDto.GetMemberDescription(x => x.IsActive)]">
<CellTemplate>
<div>
@if (!context.Item.IsActive)
@if (!context.Item.IsActive || (context.Item.LockoutEnd is not null && context.Item.LockoutEnd > DateTime.UtcNow))
{
<MudTooltip Text="@(_canDeactivation?L["Click to change status to active."]:L["No permission to change status."])" Delay="300">
<MudSwitch Disabled="@(!_canDeactivation)" T="bool" Value="@(context.Item.IsActive)" ValueChanged="@(()=>SetActive(context.Item))" ThumbIcon="@Icons.Material.Filled.Close" ThumbIconColor="Color.Error">
<MudTooltip Text="@L["Click to change status to active."]" Delay="300">
<MudSwitch T="bool" Value="context.Item.IsActive" ValueChanged="@(()=>SetActive(context.Item))" ThumbIcon="@Icons.Material.Filled.Close" ThumbIconColor="Color.Error">
</MudSwitch>
</MudTooltip>
}
else
{
<MudTooltip Text="@(_canDeactivation?L["Click to change status to inactive."]:L["No permission to change status."])" Delay="300">
<MudSwitch Disabled="@(!_canDeactivation)" T="bool" Value="context.Item.IsActive" ValueChanged="@(()=>SetActive(context.Item))" ThumbIcon="@Icons.Material.Filled.Done" ThumbIconColor="Color.Success">
<MudTooltip Text="@L["Click to change status to inactive."]" Delay="300">
<MudSwitch T="bool" Value="context.Item.IsActive" ValueChanged="@(()=>SetActive(context.Item))" ThumbIcon="@Icons.Material.Filled.Done" ThumbIconColor="Color.Success">
</MudSwitch>

</MudTooltip>
}
</div>
Expand Down Expand Up @@ -351,7 +352,6 @@
private bool _canManagePermissions;
private bool _canImport;
private bool _canExport;
private bool _canDeactivation;
private bool _loading;
private bool _exporting;
private bool _uploading;
Expand All @@ -373,7 +373,6 @@
_canManagePermissions = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.ManagePermissions)).Succeeded;
_canImport = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.Import)).Succeeded;
_canExport = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.Export)).Succeeded;
_canDeactivation = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.Deactivation)).Succeeded;
_roles = await RoleManager.Roles.Select(x => x.Name).ToListAsync();


Expand Down Expand Up @@ -521,14 +520,9 @@
user.DisplayName = item.DisplayName;
user.Provider = item.Provider;
user.UserName = item.UserName;

user.IsActive = item.IsActive;
user.TenantId = item.TenantId;
user.SuperiorId = item.SuperiorId;
if (user.IsActive == false && item.IsActive && user.LockoutEnd is not null)
{
user.LockoutEnd = null;
}
user.IsActive = item.IsActive;
var identityResult = await UserManager.UpdateAsync(user);
if (identityResult.Succeeded)
{
Expand Down Expand Up @@ -702,11 +696,13 @@
private async Task DeactivateUser(ApplicationUser user, ApplicationUserDto item)
{
user.IsActive = false;
user.LockoutEnd = DateTimeOffset.MaxValue;
var identityResult = await UserManager.UpdateAsync(user);

if (identityResult.Succeeded)
{
item.IsActive = false;
item.LockoutEnd = DateTimeOffset.MaxValue;
Snackbar.Add($"{L["The user has been inactivated."]}", Severity.Info);
}
else
Expand All @@ -725,7 +721,6 @@
new Dictionary<string, object?> { ["userId"] = user.Id, ["token"] = code });
await Mediator.Publish(new ResetPasswordNotification(callbackUrl, item.Email, item.UserName));
Snackbar.Add(string.Format(L["A new password for {0} has been sent via email. The user will be required to enter a new password upon initial login."], item.UserName), Severity.Info);
Logger.LogInformation($"Password reset email sent to user {item.UserName} ({item.Id}) with callback URL {callbackUrl}");
}
private async Task OnResetPassword(ApplicationUserDto item)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Server.UI/Pages/SystemManagement/AuditTrails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>

<MudStack Row="true" AlignItems="AlignItems.Stretch">
<MudEnumSelect TEnum="AuditType?" Placeholder="@L["Search for audit type"]" Value="@Query.AuditType" Clearable="true" ValueChanged="@(s => OnSearch(s))" Style="min-width:120px" FullWidth="true"> </MudEnumSelect>
<MudEnumSelect TEnum="AuditType?" Placeholder="@L["Search by audit type"]" Value="@Query.AuditType" Clearable="true" ValueChanged="@(s => OnSearch(s))" Style="min-width:120px" FullWidth="true"> </MudEnumSelect>
<MudHidden Breakpoint="Breakpoint.SmAndDown">
<MudTextField T="string" ValueChanged="@(s => OnSearch(s))" Value="@Query.Keyword" Placeholder="Search" Adornment="Adornment.End" Style="min-width:120px" FullWidth="true"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Small">
Expand Down
2 changes: 1 addition & 1 deletion src/Server.UI/Pages/SystemManagement/Dictionaries.razor
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
@if (_canSearch)
{
<MudStack Row="true" AlignItems="AlignItems.Stretch">
<MudEnumSelect TEnum="Picklist?" Placeholder="@L["Search for picklist"]" Value="@_searchPicklist" Clearable="true" ValueChanged="@(s => OnSearch(s))" Style="width:160px" FullWidth="true"> </MudEnumSelect>
<MudEnumSelect TEnum="Picklist?" Placeholder="@L["Search by picklist"]" Value="@_searchPicklist" Clearable="true" ValueChanged="@(s => OnSearch(s))" Style="width:160px" FullWidth="true"> </MudEnumSelect>
<MudHidden Breakpoint="Breakpoint.SmAndDown">
<MudTextField T="string" ValueChanged="@(s => OnSearch(s))" Value="@_searchString" Placeholder="Search" Adornment="Adornment.End" Style="min-width:260px" FullWidth="true"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Small">
Expand Down

0 comments on commit f3cd08b

Please sign in to comment.