mirror of
https://github.com/bitwarden/server
synced 2025-12-14 15:23:42 +00:00
Add recipe for getting emergency access invites
This commit is contained in:
@@ -18,7 +18,7 @@ public class EmergencyAccess : ITableObject<Guid>
|
||||
public string KeyEncrypted { get; set; }
|
||||
public EmergencyAccessType Type { get; set; }
|
||||
public EmergencyAccessStatusType Status { get; set; }
|
||||
public int WaitTimeDays { get; set; }
|
||||
public short WaitTimeDays { get; set; }
|
||||
public DateTime? RecoveryInitiatedDate { get; set; }
|
||||
public DateTime? LastNotificationDate { get; set; }
|
||||
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
|
||||
|
||||
@@ -79,7 +79,7 @@ public class EmergencyAccessService : IEmergencyAccessService
|
||||
Email = emergencyContactEmail.ToLowerInvariant(),
|
||||
Status = EmergencyAccessStatusType.Invited,
|
||||
Type = accessType,
|
||||
WaitTimeDays = waitTime,
|
||||
WaitTimeDays = (short)waitTime,
|
||||
CreationDate = DateTime.UtcNow,
|
||||
RevisionDate = DateTime.UtcNow,
|
||||
};
|
||||
|
||||
28
util/Seeder/Recipes/EmergencyAccessInviteRecipe.cs
Normal file
28
util/Seeder/Recipes/EmergencyAccessInviteRecipe.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Bit.Core.Auth.Enums;
|
||||
using Bit.Core.Auth.Models.Business.Tokenables;
|
||||
using Bit.Core.Tokens;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
|
||||
namespace Bit.Seeder.Recipes;
|
||||
|
||||
public class EmergencyAccessInviteRecipe(
|
||||
DatabaseContext db,
|
||||
IDataProtectorTokenFactory<EmergencyAccessInviteTokenable> dataProtectorTokenizer)
|
||||
{
|
||||
public RecipeResult Seed(string email)
|
||||
{
|
||||
var invites = db.EmergencyAccesses
|
||||
.Where(ea => ea.Email == email).ToList().Select(ea =>
|
||||
{
|
||||
var token = dataProtectorTokenizer.Protect(
|
||||
new EmergencyAccessInviteTokenable(ea, hoursTillExpiration: 1)
|
||||
);
|
||||
return $"/accept-emergency?id={ea.Id}&name=Dummy&email={ea.Email}&token={token}";
|
||||
});
|
||||
|
||||
return new RecipeResult
|
||||
{
|
||||
Result = invites,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -13,22 +13,16 @@ builder.Services.AddControllers();
|
||||
// Configure GlobalSettings from appsettings
|
||||
var globalSettings = builder.Services.AddGlobalSettingsServices(builder.Configuration, builder.Environment);
|
||||
|
||||
// Data Protection
|
||||
// Common services
|
||||
builder.Services.AddCustomDataProtectionServices(builder.Environment, globalSettings);
|
||||
|
||||
// Repositories
|
||||
builder.Services.AddTokenizers();
|
||||
builder.Services.AddDatabaseRepositories(globalSettings, forceEf: true);
|
||||
|
||||
// Identity Services
|
||||
builder.Services.AddScoped<Microsoft.AspNetCore.Identity.IPasswordHasher<Bit.Core.Entities.User>, Microsoft.AspNetCore.Identity.PasswordHasher<Bit.Core.Entities.User>>();
|
||||
|
||||
// RustSDK Services
|
||||
// Seeder services
|
||||
builder.Services.AddSingleton<Bit.RustSDK.RustSdkService>();
|
||||
|
||||
// Seeder Services
|
||||
builder.Services.AddScoped<Bit.Seeder.Factories.UserSeeder>();
|
||||
|
||||
// Recipe Service
|
||||
builder.Services.AddScoped<IRecipeService, RecipeService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
Reference in New Issue
Block a user