Skip to content

Commit

Permalink
unlock functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulCooperWorkJustice committed Aug 19, 2024
1 parent 7bbc60d commit ae65197
Showing 1 changed file with 29 additions and 13 deletions.
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

0 comments on commit ae65197

Please sign in to comment.