From ae651978b40fe8e5dde334dfc04de9888ef1bc49 Mon Sep 17 00:00:00 2001 From: PaulCooperWorkJustice Date: Mon, 19 Aug 2024 08:01:43 +0100 Subject: [PATCH] unlock functionality --- .../Pages/Identity/Users/Users.razor | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/Server.UI/Pages/Identity/Users/Users.razor b/src/Server.UI/Pages/Identity/Users/Users.razor index 696ea0d5..2b4a8c14 100644 --- a/src/Server.UI/Pages/Identity/Users/Users.razor +++ b/src/Server.UI/Pages/Identity/Users/Users.razor @@ -178,6 +178,10 @@ { @L["Reset Password"] } + @if (context.Item.LockoutEnd is not null) + { + @L["Unlock"] + } } else @@ -249,25 +253,19 @@
@if (context.Item.IsActive) { - @L["Active"] - @if (context.Item.LockoutEnd is not null) - { -
-

@L["Lockout End"]:

- -
- } + @L["Active"] } else { @L["Inactive"] + + } @if (context.Item.LockoutEnd is not null) { -
-

@L["Lockout End"]:

- -
- } +
+

@L["Lockout End"]:

+ +
}
@@ -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}.");