-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Indented * Update packages again. * Update libs again. * Custom auth. * Custom auth settings. * Tests more stable. * Test the auth. * Cleanup * Small fixes.
- Loading branch information
1 parent
f503a13
commit 61e02d1
Showing
34 changed files
with
409 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
backend/src/Notifo.Identity/MongoDb/MongoDbConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ========================================================================== | ||
// Notifo.io | ||
// ========================================================================== | ||
// Copyright (c) Sebastian Stehle | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
namespace Notifo.Identity.MongoDb; | ||
|
||
public sealed class MongoDbConfiguration<T> | ||
{ | ||
public string Id { get; set; } | ||
|
||
public T Value { get; set; } | ||
|
||
public DateTime Expires { get; set; } | ||
} |
61 changes: 61 additions & 0 deletions
61
backend/src/Notifo.Identity/MongoDb/MongoDbConfigurationStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// ========================================================================== | ||
// Notifo.io | ||
// ========================================================================== | ||
// Copyright (c) Sebastian Stehle | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
using MongoDB.Driver; | ||
using Notifo.Identity.Dynamic; | ||
using Notifo.Infrastructure.MongoDb; | ||
|
||
namespace Notifo.Identity.MongoDb; | ||
|
||
public sealed class MongoDbConfigurationStore<T> : MongoDbRepository<MongoDbConfiguration<T>>, IConfigurationStore<T> where T : class | ||
{ | ||
public MongoDbConfigurationStore(IMongoDatabase database) | ||
: base(database) | ||
{ | ||
} | ||
|
||
protected override string CollectionName() | ||
{ | ||
return "Identity_Configuration"; | ||
} | ||
|
||
protected override Task SetupCollectionAsync(IMongoCollection<MongoDbConfiguration<T>> collection, | ||
CancellationToken ct = default) | ||
{ | ||
return collection.Indexes.CreateOneAsync( | ||
new CreateIndexModel<MongoDbConfiguration<T>>( | ||
IndexKeys.Ascending(x => x.Expires), | ||
new CreateIndexOptions | ||
{ | ||
ExpireAfter = TimeSpan.Zero | ||
}), | ||
cancellationToken: ct); | ||
} | ||
|
||
public async Task<T?> GetAsync(string key, | ||
CancellationToken ct = default) | ||
{ | ||
var entity = await Collection.Find(x => x.Id == key).FirstOrDefaultAsync(ct); | ||
|
||
return entity?.Value; | ||
} | ||
|
||
public async Task SetAsync(string key, T value, TimeSpan ttl, | ||
CancellationToken ct = default) | ||
{ | ||
var expires = DateTime.UtcNow + ttl; | ||
|
||
await Collection.UpdateOneAsync( | ||
Filter.Eq(x => x.Id, key), | ||
Update | ||
.SetOnInsert(x => x.Id, key) | ||
.Set(x => x.Value, value) | ||
.Set(x => x.Expires, expires), | ||
Upsert, | ||
cancellationToken: ct); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.