Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFODEV-619 - unlock functionality #147

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/Server.UI/Pages/Identity/Users/Users.razor
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
{
<MudMenuItem Disabled="@(!context.Item.IsActive)" OnClick="@(() => OnResetPassword(context.Item))">@L["Reset Password"]</MudMenuItem>
}
@if (context.Item.LockoutEnd is not null)
{
<MudMenuItem OnClick="@(() => OnUnlock(context.Item))">@L["Unlock"]</MudMenuItem>
}
</MudMenu>
}
else
Expand Down Expand Up @@ -249,25 +253,19 @@
<div>
@if (context.Item.IsActive)
{
<MudChip Color="Color.Success" Size="Size.Small" Icon="@Icons.Material.Filled.CheckCircleOutline">@L["Active"]</MudChip>
@if (context.Item.LockoutEnd is not null)
{
<div class="d-flex">
<p>@L["Lockout End"]: </p>
<ToLocal DateTime="@context.Item.LockoutEnd.Value.UtcDateTime.ToLocalTime()" Format="dd/mm/yyyy HH:MM:ss"></ToLocal>
</div>
}
<MudChip Color="Color.Success" Size="Size.Small" Icon="@Icons.Material.Filled.CheckCircleOutline">@L["Active"]</MudChip>
}
else
{
<MudChip Class="flex-grow-0" Color="Color.Surface" Size="Size.Small" Icon="@Icons.Material.Filled.HighlightOff">@L["Inactive"]</MudChip>

}
@if (context.Item.LockoutEnd is not null)
{
<div class="d-flex">
<p>@L["Lockout End"]: </p>
<ToLocal DateTime="@context.Item.LockoutEnd.Value.UtcDateTime.ToLocalTime()" Format="dd/mm/yyyy HH:MM:ss"></ToLocal>
</div>
}
<div class="d-flex">
<p>@L["Lockout End"]: </p>
<ToLocal DateTime="@context.Item.LockoutEnd.Value.UtcDateTime.ToLocalTime()" Format="dd/mm/yyyy HH:MM:ss"></ToLocal>
</div>
}
</div>
</CellTemplate>
Expand Down Expand Up @@ -655,6 +653,24 @@

}

private async Task OnUnlock(ApplicationUserDto item)
{
var user = await UserManager.FindByIdAsync(item.Id!) ?? throw new NotFoundException($"Application user not found {item.Id}.");

user.LockoutEnd = null;
var identityResult = await UserManager.UpdateAsync(user);

if (identityResult.Succeeded)
{
item.LockoutEnd = null;
Snackbar.Add($"{L["The user has been unlocked."]}", Severity.Info);
}
else
{
Snackbar.Add($"{string.Join(",", identityResult.Errors.Select(x => x.Description).ToArray())}", Severity.Error);
}
}

private async Task OnSetActive(ApplicationUserDto item)
{
var user = await UserManager.FindByIdAsync(item.Id!) ?? throw new NotFoundException($"Application user not found {item.Id}.");
Expand Down
Loading