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:
@@ -31,11 +31,11 @@
|
||||
|
||||
@if (Prospect?.FsId != null && Prospect.FsId != 0)
|
||||
{
|
||||
<a href="@(CurrentUser.NetworkLink)/profile/@Prospect?.FsId" target="_blank">
|
||||
<small style="font-size: .9rem;">
|
||||
<i class="fa-solid fa-eye"></i> @Prospect?.FsId
|
||||
</small>
|
||||
</a>
|
||||
<a href="@(CurrentUser.NetworkLink)/profile/@Prospect?.FsId" target="_blank">
|
||||
<small style="font-size: .9rem;">
|
||||
<i class="fa-solid fa-eye"></i> @Prospect?.FsId
|
||||
</small>
|
||||
</a>
|
||||
}
|
||||
|
||||
</div>
|
||||
@@ -210,6 +210,14 @@
|
||||
</Button>
|
||||
}
|
||||
|
||||
<Button
|
||||
Color="Color.Info"
|
||||
Height="Height.Px(35)"
|
||||
title="Identitätsprüfung"
|
||||
Clicked="OpenVerificationDialogAsync"
|
||||
Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
|
||||
><i class="fa-solid fa-address-card"></i>
|
||||
</Button>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -87,6 +87,16 @@ namespace FoodsharingSiegen.Server.Controls
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method OpenVerificationDialogAsync
|
||||
|
||||
private async Task OpenVerificationDialogAsync()
|
||||
{
|
||||
if (Prospect == null) return;
|
||||
await VerificationSettingsDialog.ShowAsync(ModalService, Prospect, OnDataChanged);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method RemoveInteraction
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -27,6 +27,11 @@ namespace FoodsharingSiegen.Server.Data
|
||||
/// </summary>
|
||||
public DbSet<Prospect>? Prospects { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the uploaded verification images mapping.
|
||||
/// </summary>
|
||||
public DbSet<ProspectImage>? ProspectImages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the users (ab)
|
||||
/// </summary>
|
||||
|
||||
@@ -111,7 +111,10 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
{
|
||||
try
|
||||
{
|
||||
var prospectsQuery = Context.Prospects!.AsNoTracking().Include(x => x.Interactions.OrderBy(i => i.Date)).ThenInclude(x => x.User).OrderBy(x => x.Name).AsQueryable();
|
||||
var prospectsQuery = Context.Prospects!.AsNoTracking()
|
||||
.Include(x => x.Images)
|
||||
.Include(x => x.Interactions.OrderBy(i => i.Date)).ThenInclude(x => x.User)
|
||||
.OrderBy(x => x.Name).AsQueryable();
|
||||
|
||||
if(parameter.MustHaveInteractions != null && parameter.MustHaveInteractions.Any())
|
||||
prospectsQuery = prospectsQuery.Where(x => x.Interactions.Any(i => parameter.MustHaveInteractions.Contains(i.Type)));
|
||||
@@ -206,5 +209,138 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Image Upload Features
|
||||
|
||||
public async Task<OperationResult<Guid>> GenerateVerificationTokenAsync(Guid prospectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var prospect = await Context.Prospects!
|
||||
.Include(x => x.Interactions)
|
||||
.FirstOrDefaultAsync(x => x.Id == prospectId);
|
||||
|
||||
if (prospect == null) return new(new Exception("Prospect not found"));
|
||||
|
||||
if (prospect.Interactions.Any(x => x.Type == InteractionType.Verify))
|
||||
return new(new Exception("Die Identitätsprüfung wurde bereits abgeschlossen. Es kann kein neuer Token generiert werden."));
|
||||
|
||||
prospect.VerificationToken = Guid.NewGuid();
|
||||
prospect.Modified = DateTime.UtcNow;
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
return new(prospect.VerificationToken.Value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OperationResult<Prospect>> GetProspectByVerificationTokenAsync(Guid token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var prospect = await Context.Prospects!
|
||||
.Include(x => x.Interactions)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(x => x.VerificationToken == token);
|
||||
|
||||
if (prospect == null) return new(new Exception("Ungültiger oder abgelaufener Token."));
|
||||
|
||||
if (prospect.Interactions.Any(x => x.Type == InteractionType.Verify))
|
||||
return new(new Exception("Die Identitätsprüfung wurde bereits abgeschlossen. Ein Hochladen weiterer Bilder ist nicht mehr möglich."));
|
||||
|
||||
return new(prospect);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OperationResult> AddVerificationImageAsync(Guid prospectId, byte[] imageData, string contentType)
|
||||
{
|
||||
try
|
||||
{
|
||||
var prospect = await Context.Prospects!
|
||||
.Include(x => x.Interactions)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(x => x.Id == prospectId);
|
||||
|
||||
if (prospect == null) return new(new Exception("Foodsaver nicht gefunden."));
|
||||
|
||||
if (prospect.Interactions.Any(x => x.Type == InteractionType.Verify))
|
||||
return new(new Exception("Die Identitätsprüfung wurde bereits abgeschlossen. Ein Hochladen weiterer Bilder ist nicht mehr möglich."));
|
||||
|
||||
// Verify max 5 images
|
||||
var imgCount = await Context.ProspectImages!.CountAsync(x => x.ProspectId == prospectId);
|
||||
if (imgCount >= 5) return new(new Exception("Maximum 5 images allowed"));
|
||||
|
||||
var image = new ProspectImage
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
ProspectId = prospectId,
|
||||
ImageData = imageData,
|
||||
ContentType = contentType,
|
||||
Created = DateTime.UtcNow
|
||||
};
|
||||
|
||||
await Context.ProspectImages!.AddAsync(image);
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
return new();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OperationResult<List<ProspectImage>>> GetVerificationImagesAsync(Guid prospectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var images = await Context.ProspectImages!
|
||||
.AsNoTracking()
|
||||
.Where(x => x.ProspectId == prospectId)
|
||||
.OrderBy(x => x.Created)
|
||||
.ToListAsync();
|
||||
|
||||
return new(images);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OperationResult> DeleteVerificationImagesAsync(Guid prospectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var images = await Context.ProspectImages!.Where(x => x.ProspectId == prospectId).ToListAsync();
|
||||
if (images.Any())
|
||||
{
|
||||
Context.ProspectImages!.RemoveRange(images);
|
||||
|
||||
var prospect = await Context.Prospects!.FirstOrDefaultAsync(x => x.Id == prospectId);
|
||||
if (prospect != null)
|
||||
{
|
||||
prospect.VerificationToken = null; // Clear token when images are deleted
|
||||
}
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new(e);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
267
FoodsharingSiegen.Server/Migrations/20260420122950_AddImageVerification.Designer.cs
generated
Normal file
267
FoodsharingSiegen.Server/Migrations/20260420122950_AddImageVerification.Designer.cs
generated
Normal file
@@ -0,0 +1,267 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FoodsharingSiegen.Server.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FoodsharingSiegen.Server.Migrations
|
||||
{
|
||||
[DbContext(typeof(FsContext))]
|
||||
[Migration("20260420122950_AddImageVerification")]
|
||||
partial class AddImageVerification
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Audit", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Data1")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Data2")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid?>("UserID")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserID");
|
||||
|
||||
b.ToTable("Audits");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Interaction", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("Alert")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Feedback")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("FeedbackInfo")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Info1")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Info2")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("NotNeeded")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("ProspectID")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("UserID")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProspectID");
|
||||
|
||||
b.HasIndex("UserID");
|
||||
|
||||
b.ToTable("Interactions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Prospect", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("FsId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Memo")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("Modified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("RecordState")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid?>("VerificationToken")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("Warning")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Prospects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.ProspectImage", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<byte[]>("ImageData")
|
||||
.IsRequired()
|
||||
.HasColumnType("BLOB");
|
||||
|
||||
b.Property<Guid>("ProspectId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProspectId");
|
||||
|
||||
b.ToTable("ProspectImages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("EncryptedPassword")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("ForceLogout")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Groups")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Mail")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Memo")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Network")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ResetToken")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("ResetTokenExpiry")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("Verified")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Audit", b =>
|
||||
{
|
||||
b.HasOne("FoodsharingSiegen.Contracts.Entity.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserID");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Interaction", b =>
|
||||
{
|
||||
b.HasOne("FoodsharingSiegen.Contracts.Entity.Prospect", "Prospect")
|
||||
.WithMany("Interactions")
|
||||
.HasForeignKey("ProspectID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FoodsharingSiegen.Contracts.Entity.User", "User")
|
||||
.WithMany("Interactions")
|
||||
.HasForeignKey("UserID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Prospect");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.ProspectImage", b =>
|
||||
{
|
||||
b.HasOne("FoodsharingSiegen.Contracts.Entity.Prospect", "Prospect")
|
||||
.WithMany("Images")
|
||||
.HasForeignKey("ProspectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Prospect");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Prospect", b =>
|
||||
{
|
||||
b.Navigation("Images");
|
||||
|
||||
b.Navigation("Interactions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.User", b =>
|
||||
{
|
||||
b.Navigation("Interactions");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FoodsharingSiegen.Server.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddImageVerification : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "VerificationToken",
|
||||
table: "Prospects",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProspectImages",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
ProspectId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
ImageData = table.Column<byte[]>(type: "BLOB", nullable: false),
|
||||
ContentType = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
||||
Created = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProspectImages", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ProspectImages_Prospects_ProspectId",
|
||||
column: x => x.ProspectId,
|
||||
principalTable: "Prospects",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProspectImages_ProspectId",
|
||||
table: "ProspectImages",
|
||||
column: "ProspectId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProspectImages");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "VerificationToken",
|
||||
table: "Prospects");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,9 @@ namespace FoodsharingSiegen.Server.Migrations
|
||||
b.Property<int>("RecordState")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid?>("VerificationToken")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("Warning")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
@@ -126,6 +129,34 @@ namespace FoodsharingSiegen.Server.Migrations
|
||||
b.ToTable("Prospects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.ProspectImage", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<byte[]>("ImageData")
|
||||
.IsRequired()
|
||||
.HasColumnType("BLOB");
|
||||
|
||||
b.Property<Guid>("ProspectId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProspectId");
|
||||
|
||||
b.ToTable("ProspectImages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -205,8 +236,21 @@ namespace FoodsharingSiegen.Server.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.ProspectImage", b =>
|
||||
{
|
||||
b.HasOne("FoodsharingSiegen.Contracts.Entity.Prospect", "Prospect")
|
||||
.WithMany("Images")
|
||||
.HasForeignKey("ProspectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Prospect");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Prospect", b =>
|
||||
{
|
||||
b.Navigation("Images");
|
||||
|
||||
b.Navigation("Interactions");
|
||||
});
|
||||
|
||||
|
||||
95
FoodsharingSiegen.Server/Pages/UploadVerification.razor
Normal file
95
FoodsharingSiegen.Server/Pages/UploadVerification.razor
Normal file
@@ -0,0 +1,95 @@
|
||||
@page "/verify/{Token:guid}"
|
||||
@using FoodsharingSiegen.Contracts.Entity
|
||||
@using System.IO
|
||||
@layout LoginLayout
|
||||
|
||||
<div class="row min-vh-100 align-items-center justify-content-center p-0 p-md-5 m-0">
|
||||
<div class="col-12 col-md-10 col-lg-8 col-xl-5 login-form p-2">
|
||||
<div class="card shadow-sm border-0">
|
||||
<div class="card-body p-3 p-md-5">
|
||||
<div class="text-center mb-4">
|
||||
|
||||
<h5 class="mb-0 text-success d-block d-sm-none"><i class="fa-solid fa-address-card me-2"></i><br>Identitätsprüfung</h5>
|
||||
<h4 class="mb-0 text-success d-none d-sm-block"><i class="fa-solid fa-address-card me-2"></i>Identitätsprüfung</h4>
|
||||
|
||||
<p class="text-muted mt-2">@(AppSettings.Value.Terms.Title)</p>
|
||||
</div>
|
||||
|
||||
@if (_isLoading)
|
||||
{
|
||||
<div class="text-center my-5">
|
||||
<div class="spinner-border text-success" role="status">
|
||||
<span class="visually-hidden">Laden...</span>
|
||||
</div>
|
||||
<p class="mt-3 text-muted">Lade Daten...</p>
|
||||
</div>
|
||||
}
|
||||
else if (_prospect == null)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<i class="fa-solid fa-triangle-exclamation me-2"></i> @(_message ?? "Der Link ist ungültig oder abgelaufen. Bitte fordere einen neuen Link an.")
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="alert alert-info mb-4">
|
||||
<strong>Hinweis:</strong> Dies ist die Upload-Seite für den Foodsaver <b>@_prospect.FsId</b>.
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<h5 class="fw-bold">Anleitung:</h5>
|
||||
<ul class="text-muted">
|
||||
<li>Lade hier die Vorder- und Rückseite deines Personalausweises oder Reisepasses hoch.</li>
|
||||
<li>Dein Name und Adresse müssen gut und lesbar erkennbar sein.</li>
|
||||
<li>Wir nutzen diese Bilder ausschließlich zur Identitätsprüfung.</li>
|
||||
<li>Ausschließlich die Botschafter haben Zugriff auf diese Bilder.</li>
|
||||
<li>Die Bilder werden nach der Überprüfung sofort und unwiderruflich von uns gelöscht.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="mb-4 text-center">
|
||||
<span class="badge bg-secondary mb-2 text-wrap">Es können noch bis zu @(5 - _uploadedCount) Bilder hochgeladen werden</span>
|
||||
|
||||
@if (_uploadedCount >= 5)
|
||||
{
|
||||
<div class="alert alert-warning py-2 mb-0">Du hast die maximale Anzahl von 5 Bildern erreicht.</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<InputFile id="fileInput" OnChange="OnInputFileChange" class="d-none" accept="image/*" />
|
||||
<label for="fileInput" class="btn btn-outline-success w-100">
|
||||
<i class="fa-solid fa-images me-2"></i>Bild auswählen
|
||||
</label>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (_isUploading)
|
||||
{
|
||||
<div class="text-center my-3">
|
||||
<div class="spinner-border text-primary spinner-border-sm" role="status">
|
||||
<span class="visually-hidden">Laden...</span>
|
||||
</div>
|
||||
<span class="ms-2">Bilder werden hochgeladen und verarbeitet...</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(_message))
|
||||
{
|
||||
<div class="alert alert-@(_isSuccess ? "success" : "danger") alert-dismissible fade show" role="alert">
|
||||
@_message
|
||||
<button type="button" class="btn-close" @onclick="() => _message = null"></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (_uploadedCount > 0)
|
||||
{
|
||||
<div class="alert alert-success text-center">
|
||||
<i class="fa-solid fa-check-circle fa-2x mb-2"></i><br/>
|
||||
Vielen Dank für den Upload. Du kannst diese Seite nun schließen.
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
141
FoodsharingSiegen.Server/Pages/UploadVerification.razor.cs
Normal file
141
FoodsharingSiegen.Server/Pages/UploadVerification.razor.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Contracts.Model;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using FoodsharingSiegen.Shared.Helper;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FoodsharingSiegen.Server.Pages
|
||||
{
|
||||
public partial class UploadVerification : ComponentBase
|
||||
{
|
||||
[Inject]
|
||||
public ProspectService ProspectService { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
public IOptions<AppSettings> AppSettings { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public Guid Token { get; set; }
|
||||
|
||||
private bool _isLoading = true;
|
||||
private Prospect? _prospect;
|
||||
|
||||
private int _uploadedCount = 0;
|
||||
private bool _isUploading = false;
|
||||
|
||||
private string? _message;
|
||||
private bool _isSuccess;
|
||||
|
||||
private const int MaxAllowedFiles = 5;
|
||||
private const long MaxFileSize = 10 * 1024 * 1024; // 10 MB
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isLoading = true;
|
||||
|
||||
try
|
||||
{
|
||||
var result = await ProspectService.GetProspectByVerificationTokenAsync(Token);
|
||||
|
||||
if (result.Success && result.Data != null)
|
||||
{
|
||||
_prospect = result.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
_prospect = null;
|
||||
_message = result.Exception?.Message ?? "Ein Fehler ist aufgetreten.";
|
||||
_isSuccess = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_message = $"Fehler: {ex.Message}";
|
||||
_isSuccess = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnInputFileChange(InputFileChangeEventArgs e)
|
||||
{
|
||||
if (_prospect == null) return;
|
||||
|
||||
_message = null;
|
||||
|
||||
var files = e.GetMultipleFiles(MaxAllowedFiles);
|
||||
|
||||
if (_uploadedCount + files.Count > MaxAllowedFiles)
|
||||
{
|
||||
_message = $"Es sind maximal {MaxAllowedFiles} Bilder erlaubt.";
|
||||
_isSuccess = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_isUploading = true;
|
||||
|
||||
int successCount = 0;
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (file.Size > MaxFileSize)
|
||||
{
|
||||
_message = $"Bild '{file.Name}' überschreitet die erlaubte Größe von 10 MB.";
|
||||
_isSuccess = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Resize the image to a max dimension of 1000 pixels (longest edge) to save DB space
|
||||
var resizedImageFile = await file.RequestImageFileAsync(file.ContentType, 1000, 1000);
|
||||
|
||||
using var stream = resizedImageFile.OpenReadStream(MaxFileSize);
|
||||
using var memoryStream = new MemoryStream();
|
||||
|
||||
await stream.CopyToAsync(memoryStream);
|
||||
|
||||
byte[] imageData = memoryStream.ToArray();
|
||||
|
||||
var saveResult = await ProspectService.AddVerificationImageAsync(_prospect.Id, imageData, resizedImageFile.ContentType);
|
||||
|
||||
if (saveResult.Success)
|
||||
{
|
||||
successCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_message = $"Fehler beim Speichern von {file.Name}: {saveResult.Exception?.Message}";
|
||||
_isSuccess = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_message = $"Fehler bei {file.Name}: {ex.Message}";
|
||||
_isSuccess = false;
|
||||
}
|
||||
}
|
||||
|
||||
_isUploading = false;
|
||||
|
||||
if (successCount > 0)
|
||||
{
|
||||
_message = $"{successCount} Bild(er) erfolgreich hinzugefügt.";
|
||||
_isSuccess = true;
|
||||
_uploadedCount += successCount;
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user