Implement identity verification feature with image upload and token management
All checks were successful
Build And Push Dev Docker Image / docker (push) Successful in 2m2s
All checks were successful
Build And Push Dev Docker Image / docker (push) Successful in 2m2s
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
@using Blazorise
|
||||
@inherits FsBase
|
||||
|
||||
<div class="mt-1 mb-3">
|
||||
<div class="d-grid gap-3">
|
||||
@if (ShowLinkPanel)
|
||||
{
|
||||
<div class="border p-3 rounded">
|
||||
<p class="mb-2 text-muted">Kopiere diesen Link und teile ihn mit <strong>@Prospect?.Name</strong>:</p>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" value="@LinkUrl" readonly />
|
||||
<Button Color="Color.Secondary" Clicked="CopyLink"><i class="fa-solid fa-copy"></i></Button>
|
||||
</div>
|
||||
</div>
|
||||
<Button Color="Color.Light" Clicked="@(() => ModalService.Hide())">Schließen</Button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<Button Color="Color.Info" Clicked="@GenerateLinkAsync">
|
||||
<i class="fa-solid fa-link me-2"></i> Upload-Link erstellen / anzeigen
|
||||
</Button>
|
||||
|
||||
<Button Color="Color.Success" Clicked="@ViewImagesAsync" Disabled="@(ImageCount == 0)">
|
||||
<i class="fa-solid fa-images me-2"></i> Hochgeladene Bilder ansehen (@ImageCount)
|
||||
</Button>
|
||||
|
||||
<Button Color="Color.Danger" Clicked="@DeleteImagesAsync" Disabled="@(ImageCount == 0)">
|
||||
<i class="fa-solid fa-trash-can me-2"></i> Alle Bilder löschen
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,109 @@
|
||||
using Blazorise;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Server.BaseClasses;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace FoodsharingSiegen.Server.Dialogs
|
||||
{
|
||||
public partial class VerificationSettingsDialog : FsBase
|
||||
{
|
||||
[Inject]
|
||||
public ProspectService ProspectService { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
public NavigationManager NavigationManager { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
public IJSRuntime JS { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public Prospect? Prospect { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<Task>? OnDataChanged { get; set; }
|
||||
|
||||
private int ImageCount { get; set; } = 0;
|
||||
private bool ShowLinkPanel { get; set; } = false;
|
||||
private string LinkUrl { get; set; } = string.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (Prospect != null)
|
||||
{
|
||||
var result = await ProspectService.GetVerificationImagesAsync(Prospect.Id);
|
||||
if (result.Success && result.Data != null)
|
||||
{
|
||||
ImageCount = result.Data.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ShowAsync(IModalService modalService, Prospect? prospect, Func<Task>? onDataChanged)
|
||||
{
|
||||
var title = "Identitätsprüfung Einstellungen";
|
||||
var action = new Action<ModalProviderParameterBuilder<VerificationSettingsDialog>>(b =>
|
||||
{
|
||||
b.Add(nameof(Prospect), prospect);
|
||||
b.Add(nameof(OnDataChanged), onDataChanged);
|
||||
});
|
||||
|
||||
await modalService.Show(title, action, new ModalInstanceOptions { Size = ModalSize.Large });
|
||||
}
|
||||
|
||||
private async Task GenerateLinkAsync()
|
||||
{
|
||||
if (Prospect == null) return;
|
||||
|
||||
Guid token = Prospect.VerificationToken ?? Guid.Empty;
|
||||
|
||||
if (token == Guid.Empty)
|
||||
{
|
||||
var result = await ProspectService.GenerateVerificationTokenAsync(Prospect.Id);
|
||||
if (result.Success)
|
||||
{
|
||||
token = result.Data;
|
||||
if (OnDataChanged != null) await OnDataChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Notification.Error(result.Exception?.Message ?? "Ein Fehler ist aufgetreten.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LinkUrl = NavigationManager.BaseUri + "verify/" + token.ToString();
|
||||
ShowLinkPanel = true;
|
||||
}
|
||||
|
||||
private async Task CopyLink()
|
||||
{
|
||||
await JS.InvokeVoidAsync("navigator.clipboard.writeText", LinkUrl);
|
||||
}
|
||||
|
||||
private async Task ViewImagesAsync()
|
||||
{
|
||||
await ModalService.Hide();
|
||||
if (Prospect != null)
|
||||
{
|
||||
await ViewImagesDialog.ShowAsync(ModalService, Prospect);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteImagesAsync()
|
||||
{
|
||||
if (Prospect == null) return;
|
||||
|
||||
await ConfirmDialog.ShowAsync(ModalService, "Bilder Löschen", "Sollen alle Identitätsprüfungsbilder dieses Users unwiderruflich gelöscht werden?", async () =>
|
||||
{
|
||||
var result = await ProspectService.DeleteVerificationImagesAsync(Prospect.Id);
|
||||
if (result.Success)
|
||||
{
|
||||
ImageCount = 0;
|
||||
StateHasChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
44
FoodsharingSiegen.Server/Dialogs/ViewImagesDialog.razor
Normal file
44
FoodsharingSiegen.Server/Dialogs/ViewImagesDialog.razor
Normal file
@@ -0,0 +1,44 @@
|
||||
@using Blazorise
|
||||
@inherits FsBase
|
||||
|
||||
@if (SelectedImageIndex.HasValue)
|
||||
{
|
||||
<div class="text-center position-relative">
|
||||
<Button Color="Color.Secondary" Class="position-absolute start-0 top-0 m-2 z-3 text-white bg-dark border-0 rounded-circle w-40px h-40px fs-4 lh-1" Clicked="() => SelectedImageIndex = null">
|
||||
<i class="fa-solid fa-close"></i>
|
||||
</Button>
|
||||
<img src="@(_images[SelectedImageIndex.Value])" class="img-fluid rounded" style="max-height: 80vh;" />
|
||||
<div class="d-flex justify-content-between position-absolute top-50 start-0 w-100">
|
||||
<Button Color="Color.Dark" Class="rounded-circle" Disabled="@(SelectedImageIndex.Value == 0)" Clicked="() => SelectedImageIndex--"><i class="fa-solid fa-chevron-left"></i></Button>
|
||||
<Button Color="Color.Dark" Class="rounded-circle" Disabled="@(SelectedImageIndex.Value == _images.Count - 1)" Clicked="() => SelectedImageIndex++"><i class="fa-solid fa-chevron-right"></i></Button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (_isLoading)
|
||||
{
|
||||
<div class="text-center my-3"><div class="spinner-border text-success"></div></div>
|
||||
}
|
||||
else if (_images.Any())
|
||||
{
|
||||
<div class="row row-cols-1 row-cols-md-3 g-2">
|
||||
@for (int i = 0; i < _images.Count; i++)
|
||||
{
|
||||
var index = i;
|
||||
<div class="col">
|
||||
<div class="card h-100 shadow-sm" style="cursor:pointer;" @onclick="() => SelectedImageIndex = index">
|
||||
<img src="@(_images[index])" class="card-img-top mh-100 object-fit-cover" style="height: 200px" />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="alert alert-info">Keine Bilder vorhanden.</div>
|
||||
}
|
||||
<div class="mt-3 text-end">
|
||||
<Button Color="Color.Secondary" Clicked="@(() => ModalService.Hide())">Schließen</Button>
|
||||
</div>
|
||||
}
|
||||
50
FoodsharingSiegen.Server/Dialogs/ViewImagesDialog.razor.cs
Normal file
50
FoodsharingSiegen.Server/Dialogs/ViewImagesDialog.razor.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Blazorise;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Server.BaseClasses;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace FoodsharingSiegen.Server.Dialogs
|
||||
{
|
||||
public partial class ViewImagesDialog : FsBase
|
||||
{
|
||||
[Inject]
|
||||
public ProspectService ProspectService { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public Prospect? Prospect { get; set; }
|
||||
|
||||
private bool _isLoading = true;
|
||||
private List<string> _images = new();
|
||||
private int? SelectedImageIndex { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (Prospect != null)
|
||||
{
|
||||
var result = await ProspectService.GetVerificationImagesAsync(Prospect.Id);
|
||||
if (result.Success && result.Data != null)
|
||||
{
|
||||
foreach (var image in result.Data)
|
||||
{
|
||||
var base64 = Convert.ToBase64String(image.ImageData);
|
||||
var imgSrc = $"data:{image.ContentType};base64,{base64}";
|
||||
_images.Add(imgSrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
_isLoading = false;
|
||||
}
|
||||
|
||||
public static async Task ShowAsync(IModalService modalService, Prospect prospect)
|
||||
{
|
||||
var title = $"Bilder für {prospect.Name}";
|
||||
var action = new Action<ModalProviderParameterBuilder<ViewImagesDialog>>(b =>
|
||||
{
|
||||
b.Add(nameof(Prospect), prospect);
|
||||
});
|
||||
|
||||
await modalService.Show(title, action, new ModalInstanceOptions { Size = ModalSize.ExtraLarge });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user