From 0d3612601ee2ff42cc72c9a4e29de66ea9cdc3fd Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 14 Feb 2024 14:44:04 -0500 Subject: Squashed commit of the following: commit 2735201257cd22981f96b54b4a6120f44cb93c4c Author: vnugent Date: Mon Feb 12 20:26:57 2024 -0500 refactor: update latest sql extensions commit eb3fea8181344e3550869f92b9643439053f79fe Author: vnugent Date: Sun Feb 4 01:30:25 2024 -0500 submit pending changes --- .../src/TokenRevocation/RevokedTokenStore.cs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'plugins/VNLib.Plugins.Essentials.Accounts.Registration/src/TokenRevocation/RevokedTokenStore.cs') 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 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); } /// @@ -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 -- cgit