diff options
author | vnugent <public@vaughnnugent.com> | 2024-02-14 14:44:04 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-02-14 14:44:04 -0500 |
commit | 0d3612601ee2ff42cc72c9a4e29de66ea9cdc3fd (patch) | |
tree | e3f69f017a2ec80088fc1966a5efa88a51a4466a /plugins/VNLib.Plugins.Essentials.Accounts.Registration/src/TokenRevocation/RevokedTokenStore.cs | |
parent | df7dc615532d3441f527374d18664c1a5a336de6 (diff) |
Squashed commit of the following:
commit 2735201257cd22981f96b54b4a6120f44cb93c4c
Author: vnugent <public@vaughnnugent.com>
Date: Mon Feb 12 20:26:57 2024 -0500
refactor: update latest sql extensions
commit eb3fea8181344e3550869f92b9643439053f79fe
Author: vnugent <public@vaughnnugent.com>
Date: Sun Feb 4 01:30:25 2024 -0500
submit pending changes
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Accounts.Registration/src/TokenRevocation/RevokedTokenStore.cs')
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.Accounts.Registration/src/TokenRevocation/RevokedTokenStore.cs | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Accounts.Registration/src/TokenRevocation/RevokedTokenStore.cs b/plugins/VNLib.Plugins.Essentials.Accounts.Registration/src/TokenRevocation/RevokedTokenStore.cs index 3a32db0..1a3e676 100644 --- a/plugins/VNLib.Plugins.Essentials.Accounts.Registration/src/TokenRevocation/RevokedTokenStore.cs +++ b/plugins/VNLib.Plugins.Essentials.Accounts.Registration/src/TokenRevocation/RevokedTokenStore.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Accounts.Registration @@ -41,32 +41,30 @@ namespace VNLib.Plugins.Essentials.Accounts.Registration.TokenRevocation public async Task<bool> IsRevokedAsync(string token, CancellationToken cancellation) { await using RegistrationContext context = new (Options.Value); - await context.OpenTransactionAsync(cancellation); //Select any that match tokens bool any = await (from t in context.RevokedRegistrationTokens where t.Token == token - select t).AnyAsync(cancellation); + select t) + .AnyAsync(cancellation); - await context.CommitTransactionAsync(cancellation); + await context.SaveAndCloseAsync(true, cancellation); return any; } public async Task RevokeAsync(string token, CancellationToken cancellation) { await using RegistrationContext context = new (Options.Value); - await context.OpenTransactionAsync(cancellation); //Add to table - context.RevokedRegistrationTokens.Add(new RevokedToken() + context.RevokedRegistrationTokens.Add(new RevokedToken { Created = DateTime.UtcNow, Token = token }); //Save changes and commit transaction - await context.SaveChangesAsync(cancellation); - await context.CommitTransactionAsync(cancellation); + await context.SaveAndCloseAsync(true, cancellation); } /// <summary> @@ -80,21 +78,15 @@ namespace VNLib.Plugins.Essentials.Accounts.Registration.TokenRevocation DateTime expiredBefore = DateTime.UtcNow.Subtract(validFor); await using RegistrationContext context = new (Options.Value); - await context.OpenTransactionAsync(cancellation); //Select any that match tokens RevokedToken[] expired = await context.RevokedRegistrationTokens.Where(t => t.Created < expiredBefore) .Select(static t => t) .ToArrayAsync(cancellation); - context.RevokedRegistrationTokens.RemoveRange(expired); - ERRNO count =await context.SaveChangesAsync(cancellation); - - await context.CommitTransactionAsync(cancellation); - - return count; + return await context.SaveAndCloseAsync(true, cancellation); } } }
\ No newline at end of file |