Add signature overlay and submission functionality
Enhanced `SenderPdfImageEditor` to render signature overlays with dynamic positioning and metadata display. Introduced `SenderPdfSignatureOverlay` record to represent signature data. Updated `ReceiverPage` to integrate signature capture and submission, including a confirmation popup and error handling. Removed legacy signature caching logic. Added new state variables and computed properties to manage signature overlays and submission state. Marked legacy `ReceiverSignedPage` route as obsolete. Improved styling in `envelope-viewer.css` for signature overlays.
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
@using DevExpress.Blazor
|
||||
@using System.Security.Claims
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Microsoft.Extensions.Caching.Memory
|
||||
@using MediatR
|
||||
@using EnvelopeGenerator.Server.Extensions
|
||||
@inject NavigationManager Navigation
|
||||
@@ -23,8 +22,8 @@
|
||||
@inject EnvelopeGenerator.Server.Services.EnvelopeReceiverAuthorizationService ReceiverAuthorizationService
|
||||
@inject EnvelopeGenerator.Server.Services.EnvelopeReceiverPageDataService PageDataService
|
||||
@inject AnnotationService AnnotationService
|
||||
@inject SignatureService SignatureService
|
||||
@inject AppVersionService AppVersion
|
||||
@inject IMemoryCache MemoryCache
|
||||
@inject ILogger<ReceiverPage> Logger
|
||||
@inject IMediator Mediator
|
||||
@inject IPdfPageImageRenderer PdfPageImageRenderer
|
||||
@@ -125,12 +124,23 @@
|
||||
{
|
||||
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change pdf-toolbar__btn--signature-change-active"
|
||||
@onclick="OpenSignaturePopup"
|
||||
title="Unterschreiben"
|
||||
title="@(_capturedSignature is null ? "Unterschreiben" : "Unterschrift andern")"
|
||||
style="flex-shrink: 0;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z" />
|
||||
</svg>
|
||||
<span class="pdf-toolbar__btn-text">Unterschreiben</span>
|
||||
<span class="pdf-toolbar__btn-text">@(_capturedSignature is null ? "Unterschreiben" : "Unterschrift andern")</span>
|
||||
</button>
|
||||
|
||||
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change pdf-toolbar__btn--signature-change-active"
|
||||
@onclick="OpenSubmitConfirmPopup"
|
||||
disabled="@(_capturedSignature is null || _isSubmittingSignature)"
|
||||
title="Abschließen"
|
||||
style="flex-shrink: 0;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z" />
|
||||
</svg>
|
||||
<span class="pdf-toolbar__btn-text">Abschließen</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
@@ -195,12 +205,65 @@
|
||||
Pages="@_pagePreviews"
|
||||
PdfDataUrl="@PdfDataUrl"
|
||||
PdfFileName="@PdfFileName"
|
||||
Fields="@FieldOverlays"
|
||||
Fields="@VisibleFieldOverlays"
|
||||
SignatureOverlays="@SignedOverlays"
|
||||
ShowFieldRemoveButton="false" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DxPopup @bind-Visible="_submitConfirmVisible"
|
||||
HeaderText="Unterschrift bestätigen"
|
||||
Width="440px"
|
||||
MaxWidth="95vw"
|
||||
ShowFooter="true"
|
||||
CloseOnOutsideClick="false"
|
||||
ShowCloseButton="false"
|
||||
CloseOnEscape="false">
|
||||
<BodyContentTemplate>
|
||||
<div style="display: flex; align-items: flex-start; gap: 1rem; padding: 0.5rem 0;">
|
||||
<div style="flex-shrink: 0; width: 40px; height: 40px; background: #d1fae5; border-radius: 50%; display: flex; align-items: center; justify-content: center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="#065f46" viewBox="0 0 16 16">
|
||||
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p style="margin: 0 0 0.4rem; font-weight: 600; color: #1f2937; font-size: 0.95rem;">
|
||||
Möchten Sie das Dokument verbindlich unterschreiben?
|
||||
</p>
|
||||
<p style="margin: 0; color: #6b7280; font-size: 0.85rem; line-height: 1.5;">
|
||||
Diese Aktion kann nicht rückgängig gemacht werden. Mit der Bestätigung erklären Sie, das oben angezeigte Dokument elektronisch unterzeichnet zu haben.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@if (!string.IsNullOrWhiteSpace(_submitErrorMessage))
|
||||
{
|
||||
<div class="alert alert-danger mb-0" role="alert" style="font-size: 0.85rem;">
|
||||
@_submitErrorMessage
|
||||
</div>
|
||||
}
|
||||
</BodyContentTemplate>
|
||||
<FooterContentTemplate>
|
||||
<div class="d-flex gap-2 justify-content-end w-100" style="padding: 0.5rem 0;">
|
||||
<button class="btn btn-outline-secondary"
|
||||
@onclick="() => _submitConfirmVisible = false"
|
||||
style="border-radius: 6px; padding: 0.5rem 1.25rem; font-weight: 500;">
|
||||
Abbrechen
|
||||
</button>
|
||||
<button class="btn btn-primary"
|
||||
@onclick="SubmitAndLogoutAsync"
|
||||
disabled="@_isSubmittingSignature"
|
||||
style="background: linear-gradient(135deg, #059669 0%, #047857 100%); border: none; border-radius: 6px; padding: 0.5rem 1.5rem; font-weight: 600; box-shadow: 0 2px 4px rgba(5, 150, 105, 0.3);">
|
||||
@if (_isSubmittingSignature)
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm me-1" role="status"></span>
|
||||
}
|
||||
Abschließen
|
||||
</button>
|
||||
</div>
|
||||
</FooterContentTemplate>
|
||||
</DxPopup>
|
||||
|
||||
@* Signature Popup *@
|
||||
<DxPopup @bind-Visible="_signaturePopupVisible"
|
||||
HeaderText="Unterschrift erstellen"
|
||||
@@ -391,6 +454,23 @@
|
||||
.Select((s, i) => new SenderPdfFieldOverlay(i, s.Page, s.X, s.Y, "UNTERSCHRIFT", "#4F46E5"))
|
||||
.ToList();
|
||||
|
||||
IReadOnlyList<SenderPdfFieldOverlay> VisibleFieldOverlays => _capturedSignature is null
|
||||
? FieldOverlays
|
||||
: Array.Empty<SenderPdfFieldOverlay>();
|
||||
|
||||
IReadOnlyList<SenderPdfSignatureOverlay> SignedOverlays => _capturedSignature is null
|
||||
? Array.Empty<SenderPdfSignatureOverlay>()
|
||||
: _signatures.Select(s => new SenderPdfSignatureOverlay(
|
||||
s.Page,
|
||||
s.X,
|
||||
s.Y,
|
||||
_capturedSignature.DataUrl,
|
||||
_capturedSignature.FullName,
|
||||
_capturedSignature.Position,
|
||||
_capturedSignature.Place,
|
||||
_capturedSignatureDateText ?? DateTime.Now.ToString("dd.MM.yyyy")))
|
||||
.ToList();
|
||||
|
||||
string? PdfDataUrl => _displayPdfBytes is { Length: > 0 }
|
||||
? $"data:application/pdf;base64,{Convert.ToBase64String(_displayPdfBytes)}"
|
||||
: null;
|
||||
@@ -408,6 +488,10 @@
|
||||
string _signerPosition = string.Empty;
|
||||
string _signaturePlace = string.Empty;
|
||||
bool _isLoggingOut = false;
|
||||
bool _isSubmittingSignature = false;
|
||||
bool _submitConfirmVisible = false;
|
||||
string? _submitErrorMessage;
|
||||
string? _capturedSignatureDateText;
|
||||
|
||||
// ----- Share popup state -----
|
||||
bool _sharePopupVisible = false;
|
||||
@@ -572,33 +656,9 @@
|
||||
.ToList();
|
||||
_pageCount = _pagePreviews.Count > 0 ? _pagePreviews.Count : 1;
|
||||
|
||||
// Try to restore cached signature
|
||||
try
|
||||
{
|
||||
var cachedSignature = await PageDataService.GetCachedSignatureAsync(_receiverUser);
|
||||
if (cachedSignature is not null)
|
||||
{
|
||||
_capturedSignature = cachedSignature;
|
||||
_signerFullName = cachedSignature.FullName;
|
||||
_signerPosition = cachedSignature.Position;
|
||||
_signaturePlace = cachedSignature.Place;
|
||||
_signaturePopupVisible = false;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_activeSignatureTab = SignatureTabDraw;
|
||||
_signaturePopupVisible = false;
|
||||
_popupValidationMessage = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Failed to load cached signature for {EnvelopeKey}", EnvelopeKey);
|
||||
_activeSignatureTab = SignatureTabDraw;
|
||||
_signaturePopupVisible = false;
|
||||
_popupValidationMessage = null;
|
||||
}
|
||||
_activeSignatureTab = SignatureTabDraw;
|
||||
_signaturePopupVisible = false;
|
||||
_popupValidationMessage = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -629,6 +689,15 @@
|
||||
_popupValidationMessage = null;
|
||||
}
|
||||
|
||||
void OpenSubmitConfirmPopup()
|
||||
{
|
||||
if (_capturedSignature is null || _isSubmittingSignature)
|
||||
return;
|
||||
|
||||
_submitErrorMessage = null;
|
||||
_submitConfirmVisible = true;
|
||||
}
|
||||
|
||||
async Task OnPopupShownAsync()
|
||||
{
|
||||
await InitializeActiveSignatureTabAsync();
|
||||
@@ -716,22 +785,50 @@
|
||||
Position = _signerPosition.Trim(),
|
||||
Place = _signaturePlace.Trim(),
|
||||
};
|
||||
_capturedSignatureDateText = DateTime.Now.ToString("dd.MM.yyyy");
|
||||
_signaturePopupVisible = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
// Store signature in IMemoryCache with a Guid key (1 minute TTL)
|
||||
var sid = Guid.NewGuid().ToString("N");
|
||||
MemoryCache.Set(
|
||||
sid,
|
||||
_capturedSignature,
|
||||
TimeSpan.FromMinutes(1));
|
||||
async Task SubmitAndLogoutAsync()
|
||||
{
|
||||
if (_isSubmittingSignature)
|
||||
return;
|
||||
|
||||
Logger.LogInformation(
|
||||
"Signature cached with sid={Sid} for envelope {EnvelopeKey}", sid, EnvelopeKey);
|
||||
if (string.IsNullOrWhiteSpace(EnvelopeKey) || _capturedSignature is null)
|
||||
return;
|
||||
|
||||
// Navigate — forceLoad:true for clean circuit teardown
|
||||
Navigation.NavigateTo(
|
||||
$"/envelope/{Uri.EscapeDataString(EnvelopeKey!)}/signed?sid={sid}",
|
||||
forceLoad: true);
|
||||
_isSubmittingSignature = true;
|
||||
_submitConfirmVisible = false;
|
||||
_submitErrorMessage = null;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
try
|
||||
{
|
||||
if (_signatures.Count == 0)
|
||||
throw new InvalidOperationException("No signature fields found for receiver.");
|
||||
|
||||
var payload = _signatures.Select(field => new SignatureSubmitDto
|
||||
{
|
||||
Id = field.Id,
|
||||
DataUrl = _capturedSignature.DataUrl,
|
||||
FullName = _capturedSignature.FullName,
|
||||
Position = string.IsNullOrWhiteSpace(_capturedSignature.Position) ? null : _capturedSignature.Position,
|
||||
Place = _capturedSignature.Place
|
||||
}).ToList();
|
||||
|
||||
await SignatureService.SubmitAsync(EnvelopeKey, payload);
|
||||
|
||||
await AuthService.LogoutEnvelopeReceiverAsync(EnvelopeKey);
|
||||
Navigation.NavigateTo("/envelope/signed-result", forceLoad: true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Failed to finalize signature for {EnvelopeKey}", EnvelopeKey);
|
||||
_submitErrorMessage = "Die Unterschrift konnte nicht abgeschlossen werden. Bitte versuchen Sie es erneut.";
|
||||
_isSubmittingSignature = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRejectPopup()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
@page "/envelope/{EnvelopeKey}/signed"
|
||||
@rendermode InteractiveServer
|
||||
@attribute [Obsolete("Legacy receiver signed preview route. Signing is finalized inline in /envelope/{EnvelopeKey}.")]
|
||||
@using EnvelopeGenerator.Application.Common.Dto
|
||||
@using EnvelopeGenerator.Application.Common.Interfaces.Doc
|
||||
@using EnvelopeGenerator.Server.Client.Components.PdfEditor
|
||||
|
||||
Reference in New Issue
Block a user