Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add attachment uploader/viewer component (#81)
Leendert de Borst4137cc473655
diff --git a/.vscode/launch.json b/.vscode/launch.jsonnew file mode 100644index 000000000..9a1931e18--- /dev/null+++ b/.vscode/launch.json@@ -0,0 +1,19 @@+{+ "version": "0.2.0",+ "configurations": [+ {+ "name": "C#: AliasVault.WebApp [http]",+ "type": "dotnet",+ "request": "launch",+ "projectPath": "${workspaceFolder}/src/AliasVault.WebApp/AliasVault.WebApp.csproj",+ "launchConfigurationId": "TargetFramework=;http",+ },+ {+ "name": "C#: AliasVault.Api [http]",+ "type": "dotnet",+ "request": "launch",+ "projectPath": "${workspaceFolder}/src/AliasVault.Api/AliasVault.Api.csproj",+ "launchConfigurationId": "TargetFramework=;http"+ }+ ]+}\ No newline at end of filediff --git a/src/AliasVault.WebApp/Auth/Services/AuthService.cs b/src/AliasVault.WebApp/Auth/Services/AuthService.csindex e914aeb87..39ee5f04f 100644--- a/src/AliasVault.WebApp/Auth/Services/AuthService.cs+++ b/src/AliasVault.WebApp/Auth/Services/AuthService.cs@@ -108,7 +108,9 @@ public class AuthService(HttpClient httpClient, ILocalStorageService localStoragpublic string GetEncryptionKeyAsBase64Async(){// Enable this line for debugging to skip unlock screen.- return Convert.ToBase64String(GetEncryptionKeyAsync());+ return "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB=";++ // return Convert.ToBase64String(GetEncryptionKeyAsync());}/// <summary>diff --git a/src/AliasVault.WebApp/Components/Attachments/AttachmentUploader.razor b/src/AliasVault.WebApp/Components/Attachments/AttachmentUploader.razornew file mode 100644index 000000000..d0fc632c4--- /dev/null+++ b/src/AliasVault.WebApp/Components/Attachments/AttachmentUploader.razor@@ -0,0 +1,97 @@+@inject IJSRuntime JSRuntime++<div class="col">+ <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-xl font-semibold dark:text-white">Attachments</h3>+ <div class="grid gap-6">+ <div class="col-span-6 sm:col-span-3">+ <InputFile OnChange="@HandleFileSelection" class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400" />+ @if (!string.IsNullOrEmpty(statusMessage))+ {+ <p class="mt-2 text-sm text-gray-500 dark:text-gray-400">@statusMessage</p>+ }+ @if (Attachments.Any())+ {+ <div class="mt-4">+ <h4 class="mb-2 text-lg font-semibold dark:text-white">Attachments:</h4>+ <ul class="list-disc list-inside">+ @foreach (var attachment in Attachments)+ {+ <li class="flex items-center justify-between text-sm text-gray-600 dark:text-gray-400">+ <span>@attachment.Filename</span>+ <button type="button" @onclick="() => DeleteAttachment(attachment)" class="text-red-500 hover:text-red-700">+ Delete+ </button>+ </li>+ }+ </ul>+ </div>+ }+ </div>+ </div>+ </div>+</div>++@code {+ [Parameter]+ public List<Attachment> Attachments { get; set; } = new List<Attachment>();++ [Parameter]+ public EventCallback<List<Attachment>> AttachmentsChanged { get; set; }++ [Parameter]+ public Guid CredentialId { get; set; }++ private string statusMessage = string.Empty;++ private async Task HandleFileSelection(InputFileChangeEventArgs e)+ {+ statusMessage = "Uploading...";+ foreach (var file in e.GetMultipleFiles(int.MaxValue))+ {+ try+ {+ using var ms = new MemoryStream();+ await file.OpenReadStream().CopyToAsync(ms);++ var attachment = new Attachment+ {+ Filename = file.Name,+ Blob = ms.ToArray(),+ CreatedAt = DateTime.UtcNow,+ UpdatedAt = DateTime.UtcNow,+ };++ Attachments.Add(attachment);+ await AttachmentsChanged.InvokeAsync(Attachments);++ statusMessage = "File uploaded successfully.";+ }+ catch (Exception ex)+ {+ statusMessage = $"Error uploading file: {ex.Message}";+ await JSRuntime.InvokeVoidAsync("console.error", ex.Message);+ }+ }++ StateHasChanged();+ }++ private async Task DeleteAttachment(Attachment attachment)+ {+ try+ {+ Attachments.Remove(attachment);+ await AttachmentsChanged.InvokeAsync(Attachments);++ statusMessage = "Attachment deleted successfully.";+ }+ catch (Exception ex)+ {+ statusMessage = $"Error deleting attachment: {ex.Message}";+ await JSRuntime.InvokeVoidAsync("console.error", ex.Message);+ }++ StateHasChanged();+ }+}\ No newline at end of filediff --git a/src/AliasVault.WebApp/Components/Attachments/AttachmentViewer.razor b/src/AliasVault.WebApp/Components/Attachments/AttachmentViewer.razornew file mode 100644index 000000000..e317f1ce9--- /dev/null+++ b/src/AliasVault.WebApp/Components/Attachments/AttachmentViewer.razor@@ -0,0 +1,65 @@+@inject IJSRuntime JSRuntime++<div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-xl font-semibold dark:text-white">Attachments</h3>+ @if (Attachments.Any())+ {+ <div class="overflow-x-auto">+ <table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">+ <thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">+ <tr>+ <th scope="col" class="px-6 py-3">Filename</th>+ <th scope="col" class="px-6 py-3">Created At</th>+ <th scope="col" class="px-6 py-3">Actions</th>+ </tr>+ </thead>+ <tbody>+ @foreach (var attachment in Attachments)+ {+ <tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">+ <td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">+ @attachment.Filename+ </td>+ <td class="px-6 py-4">+ @attachment.CreatedAt.ToLocalTime().ToString("g")+ </td>+ <td class="px-6 py-4">+ <button @onclick="() => DownloadAttachment(attachment)" class="font-medium text-blue-600 dark:text-blue-500 hover:underline">Download</button>+ </td>+ </tr>+ }+ </tbody>+ </table>+ </div>+ }+ else+ {+ <p class="text-gray-500 dark:text-gray-400">No attachments available.</p>+ }+</div>++@code {+ [Parameter]+ public ICollection<Attachment> Attachments { get; set; } = new List<Attachment>();++ private async Task DownloadAttachment(Attachment attachment)+ {+ try+ {+ if (attachment.Blob != null)+ {+ await JSRuntime.InvokeVoidAsync("downloadFileFromStream", attachment.Filename, attachment.Blob);+ }+ else+ {+ // Handle the case where the attachment or its content is not found+ Console.Error.WriteLine($"Attachment not found or has no content: {attachment.Id}");+ }+ }+ catch (Exception ex)+ {+ // Handle any exceptions that occur during the download process+ Console.Error.WriteLine($"Error downloading attachment: {ex.Message}");+ }+ }+}\ No newline at end of filediff --git a/src/AliasVault.WebApp/Models/CredentialEdit.cs b/src/AliasVault.WebApp/Models/CredentialEdit.csindex 44a61e9a4..06c15c4d4 100644--- a/src/AliasVault.WebApp/Models/CredentialEdit.cs+++ b/src/AliasVault.WebApp/Models/CredentialEdit.cs@@ -67,4 +67,9 @@ public class CredentialEdit/// Gets or sets the Alias LastUpdate./// </summary>public DateTime LastUpdate { get; set; }++ /// <summary>+ /// Gets or sets the Attachment list.+ /// </summary>+ public List<Attachment> Attachments { get; set; } = new List<Attachment>();}diff --git a/src/AliasVault.WebApp/Pages/Credentials/AddEdit.razor b/src/AliasVault.WebApp/Pages/Credentials/AddEdit.razorindex 5c445bfee..66077c270 100644--- a/src/AliasVault.WebApp/Pages/Credentials/AddEdit.razor+++ b/src/AliasVault.WebApp/Pages/Credentials/AddEdit.razor@@ -75,6 +75,20 @@ else</div></div></div>++ <div class="col">+ <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-xl font-semibold dark:text-white">Attachments</h3>+ <div class="grid gap-6">+ <div class="col-span-6 sm:col-span-3">+ <AttachmentUploader+ Attachments="@Obj.Attachments"+ AttachmentsChanged="@HandleAttachmentsChanged"+ CredentialId="@Obj.Id" />+ </div>+ </div>+ </div>+ </div></div><div class="col col-span-2"><div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">@@ -258,6 +272,12 @@ else}}+ private void HandleAttachmentsChanged(List<Attachment> updatedAttachments)+ {+ Obj.Attachments = updatedAttachments;+ StateHasChanged();+ }+private async Task GenerateRandomIdentity(){IsIdentityLoading = true;@@ -351,7 +371,6 @@ elseprivate CredentialEdit CredentialToCredentialEdit(Credential alias){- Console.WriteLine("passwordCount: " + alias.Passwords.Count);return new CredentialEdit{Id = alias.Id,@@ -367,6 +386,7 @@ else},Alias = alias.Alias,AliasBirthDate = alias.Alias.BirthDate.ToString("yyyy-MM-dd"),+ Attachments = alias.Attachments.ToList(),CreateDate = alias.CreatedAt,LastUpdate = alias.UpdatedAt};@@ -389,6 +409,7 @@ elsealias.Password,},Alias = alias.Alias,+ Attachments = alias.Attachments,};if (string.IsNullOrWhiteSpace(alias.AliasBirthDate))diff --git a/src/AliasVault.WebApp/Pages/Credentials/View.razor b/src/AliasVault.WebApp/Pages/Credentials/View.razorindex 502fe5d90..cfdb20770 100644--- a/src/AliasVault.WebApp/Pages/Credentials/View.razor+++ b/src/AliasVault.WebApp/Pages/Credentials/View.razor@@ -53,6 +53,11 @@ else@Alias.Notes</div>}++ @if (Alias.Attachments != null && Alias.Attachments.Count > 0)+ {+ <AttachmentViewer Attachments="@Alias.Attachments" />+ }</div><div class="col-span-2"><div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">diff --git a/src/AliasVault.WebApp/Pages/Home.razor b/src/AliasVault.WebApp/Pages/Home.razorindex 26f330a4c..6ae6f4e41 100644--- a/src/AliasVault.WebApp/Pages/Home.razor+++ b/src/AliasVault.WebApp/Pages/Home.razor@@ -12,7 +12,7 @@<div class="flex items-center justify-between"><h1 class="text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white">Credentials</h1><a href="/add-credentials" class="px-4 py-2 text-white bg-primary-600 rounded-lg hover:bg-primary-700 focus:ring-4 focus:ring-primary-300 dark:bg-primary-500 dark:hover:bg-primary-600 dark:focus:ring-primary-800">- + Add new credential+ + Add new credentials</a></div><p>Find all of your credentials below.</p>diff --git a/src/AliasVault.WebApp/Services/CredentialService.cs b/src/AliasVault.WebApp/Services/CredentialService.csindex 0d57e1dd1..915face5a 100644--- a/src/AliasVault.WebApp/Services/CredentialService.cs+++ b/src/AliasVault.WebApp/Services/CredentialService.cs@@ -83,6 +83,11 @@ public class CredentialService(HttpClient httpClient, DbService dbService)Value = loginObject.Passwords.First().Value,});+ foreach (var attachment in loginObject.Attachments)+ {+ login.Attachments.Add(attachment);+ }+await context.Credentials.AddAsync(login);await context.SaveChangesAsync();@@ -108,12 +113,11 @@ public class CredentialService(HttpClient httpClient, DbService dbService)var context = await dbService.GetDbContextAsync();// Get the existing entry.- var login = await context.Credentials- .Include(x => x.Alias)- .Include(x => x.Service)- .Include(x => x.Passwords)- .Where(x => x.Id == loginObject.Id)- .FirstAsync();+ var login = await LoadEntryAsync(loginObject.Id);+ if (login is null)+ {+ throw new InvalidOperationException("Login object not found.");+ }login.UpdatedAt = DateTime.UtcNow;login.Notes = loginObject.Notes;@@ -139,6 +143,29 @@ public class CredentialService(HttpClient httpClient, DbService dbService)login.Service.Logo = loginObject.Service.Logo;login.Service.UpdatedAt = DateTime.UtcNow;+ // Remove attachments that are no longer in the list+ var existingAttachments = login.Attachments.ToList();+ foreach (var existingAttachment in existingAttachments)+ {+ if (!loginObject.Attachments.Any(a => a.Id == existingAttachment.Id))+ {+ context.Entry(existingAttachment).State = EntityState.Deleted;+ }+ }++ // Add new attachments+ foreach (var attachment in loginObject.Attachments)+ {+ if (!login.Attachments.Any(a => a.Id == attachment.Id))+ {+ login.Attachments.Add(attachment);+ }+ else+ {+ context.Entry(attachment).State = EntityState.Modified;+ }+ }+await dbService.SaveDatabaseAsync();return login.Id;@@ -157,6 +184,8 @@ public class CredentialService(HttpClient httpClient, DbService dbService).Include(x => x.Passwords).Include(x => x.Alias).Include(x => x.Service)+ .Include(x => x.Attachments)+ .AsSplitQuery().Where(x => x.Id == loginId).FirstOrDefaultAsync();@@ -164,6 +193,28 @@ public class CredentialService(HttpClient httpClient, DbService dbService)}/// <summary>+<<<<<<< Updated upstream+=======+ /// Load all entries from database.+ /// </summary>+ /// <returns>Alias object.</returns>+ public async Task<List<Credential>> LoadAllAsync()+ {+ var context = await dbService.GetDbContextAsync();++ var loginObject = await context.Credentials+ .Include(x => x.Passwords)+ .Include(x => x.Alias)+ .Include(x => x.Service)+ .Include(x => x.Attachments)+ .AsSplitQuery()+ .ToListAsync();++ return loginObject;+ }++ /// <summary>+>>>>>>> Stashed changes/// Get list with all login entries./// </summary>/// <returns>List of CredentialListEntry objects.</returns>@@ -175,6 +226,7 @@ public class CredentialService(HttpClient httpClient, DbService dbService)return await context.Credentials.Include(x => x.Alias).Include(x => x.Service)+ .AsSplitQuery().Select(x => new CredentialListEntry{Id = x.Id,diff --git a/src/AliasVault.WebApp/_Imports.razor b/src/AliasVault.WebApp/_Imports.razorindex ccf76db47..0193a822a 100644--- a/src/AliasVault.WebApp/_Imports.razor+++ b/src/AliasVault.WebApp/_Imports.razor@@ -14,6 +14,7 @@@using AliasVault.WebApp.Components@using AliasVault.WebApp.Components.Models@using AliasVault.WebApp.Components.Alerts+@using AliasVault.WebApp.Components.Attachments@using AliasVault.WebApp.Components.Loading@using AliasVault.WebApp.Models@using AliasVault.WebApp.Pages.Basediff --git a/src/AliasVault.WebApp/wwwroot/css/tailwind.css b/src/AliasVault.WebApp/wwwroot/css/tailwind.cssindex 2ee757947..b2389ab9d 100644--- a/src/AliasVault.WebApp/wwwroot/css/tailwind.css+++ b/src/AliasVault.WebApp/wwwroot/css/tailwind.css@@ -582,6 +582,10 @@ video {position: relative;}+.inset-0 {+ inset: 0px;+}+.inset-y-0 {top: 0px;bottom: 0px;@@ -706,6 +710,10 @@ video {margin-top: 0px;}+.mt-2 {+ margin-top: 0.5rem;+}+.mt-4 {margin-top: 1rem;}@@ -754,8 +762,8 @@ video {height: 2.5rem;}-.h-28 {- height: 7rem;+.h-12 {+ height: 3rem;}.h-4 {@@ -794,6 +802,10 @@ video {width: 2.5rem;}+.w-12 {+ width: 3rem;+}+.w-28 {width: 7rem;}@@ -834,6 +846,10 @@ video {min-width: 100%;}+.max-w-md {+ max-width: 28rem;+}+.max-w-screen-2xl {max-width: 1536px;}@@ -864,10 +880,18 @@ video {cursor: pointer;}+.list-inside {+ list-style-position: inside;+}+.list-none {list-style-type: none;}+.list-disc {+ list-style-type: disc;+}+.grid-cols-1 {grid-template-columns: repeat(1, minmax(0, 1fr));}@@ -876,6 +900,10 @@ video {grid-template-columns: repeat(2, minmax(0, 1fr));}+.grid-cols-3 {+ grid-template-columns: repeat(3, minmax(0, 1fr));+}+.grid-cols-4 {grid-template-columns: repeat(4, minmax(0, 1fr));}@@ -888,10 +916,6 @@ video {grid-template-columns: repeat(7, minmax(0, 1fr));}-.grid-cols-3 {- grid-template-columns: repeat(3, minmax(0, 1fr));-}-.flex-col {flex-direction: column;}@@ -1147,6 +1171,10 @@ video {padding: 1.5rem;}+.p-8 {+ padding: 2rem;+}+.px-2 {padding-left: 0.5rem;padding-right: 0.5rem;@@ -1197,6 +1225,11 @@ video {padding-bottom: 1.5rem;}+.py-4 {+ padding-top: 1rem;+ padding-bottom: 1rem;+}+.pr-10 {padding-right: 2.5rem;}@@ -1254,6 +1287,11 @@ video {line-height: 1rem;}+.text-lg {+ font-size: 1.125rem;+ line-height: 1.75rem;+}+.font-bold {font-weight: 700;}@@ -1290,6 +1328,11 @@ video {letter-spacing: 0.05em;}+.text-blue-500 {+ --tw-text-opacity: 1;+ color: rgb(59 130 246 / var(--tw-text-opacity));+}+.text-blue-700 {--tw-text-opacity: 1;color: rgb(29 78 216 / var(--tw-text-opacity));@@ -1330,6 +1373,11 @@ video {color: rgb(22 101 52 / var(--tw-text-opacity));}+.text-primary-500 {+ --tw-text-opacity: 1;+ color: rgb(244 149 65 / var(--tw-text-opacity));+}+.text-primary-700 {--tw-text-opacity: 1;color: rgb(184 112 47 / var(--tw-text-opacity));@@ -1345,15 +1393,33 @@ video {color: rgb(255 255 255 / var(--tw-text-opacity));}-.text-blue-500 {+.text-gray-600 {--tw-text-opacity: 1;- color: rgb(59 130 246 / var(--tw-text-opacity));+ color: rgb(75 85 99 / var(--tw-text-opacity));+}++.text-red-500 {+ --tw-text-opacity: 1;+ color: rgb(239 68 68 / var(--tw-text-opacity));+}++.text-blue-600 {+ --tw-text-opacity: 1;+ color: rgb(37 99 235 / var(--tw-text-opacity));}.opacity-0 {opacity: 0;}+.opacity-25 {+ opacity: 0.25;+}++.opacity-75 {+ opacity: 0.75;+}+.shadow {--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);@@ -1372,6 +1438,12 @@ video {box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);}+.shadow-xl {+ --tw-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);+ --tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);+ box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);+}+.outline-0 {outline-width: 0px;}@@ -1466,6 +1538,11 @@ video {color: rgb(255 255 255 / var(--tw-text-opacity));}+.hover\:text-red-700:hover {+ --tw-text-opacity: 1;+ color: rgb(185 28 28 / var(--tw-text-opacity));+}+.hover\:underline:hover {text-decoration-line: underline;}@@ -1590,6 +1667,11 @@ video {--tw-bg-opacity: 0.8;}+.dark\:text-blue-400:is(.dark *) {+ --tw-text-opacity: 1;+ color: rgb(96 165 250 / var(--tw-text-opacity));+}+.dark\:text-blue-500:is(.dark *) {--tw-text-opacity: 1;color: rgb(59 130 246 / var(--tw-text-opacity));@@ -1635,11 +1717,6 @@ video {color: rgb(255 255 255 / var(--tw-text-opacity));}-.dark\:text-blue-400:is(.dark *) {- --tw-text-opacity: 1;- color: rgb(96 165 250 / var(--tw-text-opacity));-}-.dark\:placeholder-gray-400:is(.dark *)::-moz-placeholder {--tw-placeholder-opacity: 1;color: rgb(156 163 175 / var(--tw-placeholder-opacity));