This commit is contained in:
Jonathan Jenne 2023-11-20 16:42:11 +01:00
parent 624266a971
commit 56688d2690
18 changed files with 305 additions and 59 deletions

View File

@ -19,4 +19,20 @@ Public Class EmailData
End Get End Get
End Property End Property
Public Sub New(pEnvelope As Envelope, pReceiver As EnvelopeReceiver)
EmailAdress = pReceiver.Email
EmailSubject = pEnvelope.Subject
Message = pEnvelope.Message
ReferenceID = pEnvelope.Id
ReferenceString = pEnvelope.Uuid
ReceiverName = pReceiver.Name
SenderAdress = pEnvelope.User.Email
SenderName = pEnvelope.User.FullName
End Sub
Public Sub New()
End Sub
End Class End Class

View File

@ -28,7 +28,7 @@ Public Class EmailTemplate
_DocumentSignedBodyTemplate = New List(Of String) From { _DocumentSignedBodyTemplate = New List(Of String) From {
"Guten Tag, <NAME_RECEIVER>", "Guten Tag, <NAME_RECEIVER>",
"", "",
"Ihre Unterschrift auf dem Dokument <DOCUMENT_TITLE> wurde verarbeitet.", "Ihre Unterschrift auf dem Dokument <DOCUMENT_TITLE> wurde gespeichert.",
"", "",
"Mit freundlichen Grüßen", "Mit freundlichen Grüßen",
"<NAME_SENDER>" "<NAME_SENDER>"

View File

@ -6,8 +6,8 @@
Public Property Status As Constants.EnvelopeStatus Public Property Status As Constants.EnvelopeStatus
Public Property Uuid As String = Guid.NewGuid.ToString() Public Property Uuid As String = Guid.NewGuid.ToString()
Public Property Subject As String Public Property Subject As String = My.Resources.Envelope.You_received_a_document_to_sign_
Public Property Message As String Public Property Message As String = My.Resources.Envelope.Please_read_and_sign_this_document
Public Property AddedWhen As Date Public Property AddedWhen As Date
Public Property User As New User() Public Property User As New User()

View File

@ -11,6 +11,16 @@ Public Class HistoryModel
Select Case pActionType Select Case pActionType
Case Constants.EnvelopeHistoryActionType.Created Case Constants.EnvelopeHistoryActionType.Created
Return "Umschlag erfolgreich erstellt" Return "Umschlag erfolgreich erstellt"
Case Constants.EnvelopeHistoryActionType.Sent
Return "Umschlag an Empfänger versendet"
Case Constants.EnvelopeHistoryActionType.Seen
Return "Umschlag von Empfänger geöffnet"
Case Constants.EnvelopeHistoryActionType.Signed
Return "Umschlag von Empfänger signiert"
Case Else Case Else
Return pActionType.ToString() Return pActionType.ToString()
End Select End Select

View File

@ -174,6 +174,9 @@
<data name="Only one file is allowed" xml:space="preserve"> <data name="Only one file is allowed" xml:space="preserve">
<value>Only one file is allowed!</value> <value>Only one file is allowed!</value>
</data> </data>
<data name="Please read and sign this document" xml:space="preserve">
<value>Please read and sign this document.</value>
</data>
<data name="Recipient could not be deleted" xml:space="preserve"> <data name="Recipient could not be deleted" xml:space="preserve">
<value>Recipient could not be deleted!</value> <value>Recipient could not be deleted!</value>
</data> </data>
@ -183,4 +186,7 @@
<data name="The envelope could not be deleted" xml:space="preserve"> <data name="The envelope could not be deleted" xml:space="preserve">
<value>The envelope could not be deleted!</value> <value>The envelope could not be deleted!</value>
</data> </data>
<data name="You received a document to sign:" xml:space="preserve">
<value>You received a document to sign:</value>
</data>
</root> </root>

View File

@ -174,6 +174,9 @@
<data name="Only one file is allowed" xml:space="preserve"> <data name="Only one file is allowed" xml:space="preserve">
<value>Es ist nur eine Datei zulässig!</value> <value>Es ist nur eine Datei zulässig!</value>
</data> </data>
<data name="Please read and sign this document" xml:space="preserve">
<value>Bitte lesen und unterzeichnen Sie dieses Dokument.</value>
</data>
<data name="Recipient could not be deleted" xml:space="preserve"> <data name="Recipient could not be deleted" xml:space="preserve">
<value>Empfänger konnte nicht gelöscht werden!</value> <value>Empfänger konnte nicht gelöscht werden!</value>
</data> </data>
@ -183,4 +186,7 @@
<data name="The envelope could not be deleted" xml:space="preserve"> <data name="The envelope could not be deleted" xml:space="preserve">
<value>Der Umschlag konnte nicht gelöscht werden!</value> <value>Der Umschlag konnte nicht gelöscht werden!</value>
</data> </data>
<data name="You received a document to sign:" xml:space="preserve">
<value>Sie haben ein Dokument zu signieren erhalten:</value>
</data>
</root> </root>

View File

@ -235,6 +235,15 @@ Namespace My.Resources
End Get End Get
End Property End Property
'''<summary>
''' Sucht eine lokalisierte Zeichenfolge, die Bitte lesen und unterzeichnen Sie dieses Dokument. ähnelt.
'''</summary>
Public Shared ReadOnly Property Please_read_and_sign_this_document() As String
Get
Return ResourceManager.GetString("Please read and sign this document", resourceCulture)
End Get
End Property
'''<summary> '''<summary>
''' Sucht eine lokalisierte Zeichenfolge, die Empfänger konnte nicht gelöscht werden! ähnelt. ''' Sucht eine lokalisierte Zeichenfolge, die Empfänger konnte nicht gelöscht werden! ähnelt.
'''</summary> '''</summary>
@ -261,5 +270,14 @@ Namespace My.Resources
Return ResourceManager.GetString("The envelope could not be deleted", resourceCulture) Return ResourceManager.GetString("The envelope could not be deleted", resourceCulture)
End Get End Get
End Property End Property
'''<summary>
''' Sucht eine lokalisierte Zeichenfolge, die Sie haben ein Dokument zu signieren erhalten: ähnelt.
'''</summary>
Public Shared ReadOnly Property You_received_a_document_to_sign_() As String
Get
Return ResourceManager.GetString("You received a document to sign:", resourceCulture)
End Get
End Property
End Class End Class
End Namespace End Namespace

View File

@ -33,16 +33,8 @@ Public Class EnvelopeEditorController
Public Function SendEnvelope() As Boolean Public Function SendEnvelope() As Boolean
For Each receiverItem As EnvelopeReceiver In Envelope.Receivers For Each receiverItem As EnvelopeReceiver In Envelope.Receivers
Dim oEmailData As New EmailData With Dim oEmailData As New EmailData(Envelope, receiverItem) With
{ {
.EmailAdress = receiverItem.Email,
.EmailSubject = Envelope.Subject,
.Message = Envelope.Message,
.ReferenceID = Envelope.Id,
.ReferenceString = Envelope.Uuid,
.ReceiverName = receiverItem.Name,
.SenderAdress = Envelope.User.Email,
.SenderName = Envelope.User.FullName,
.SignatureLink = Helpers.GetEnvelopeURL(State.DbConfig.SignatureHost, Envelope.Uuid, receiverItem.Signature) .SignatureLink = Helpers.GetEnvelopeURL(State.DbConfig.SignatureHost, Envelope.Uuid, receiverItem.Signature)
} }
@ -58,9 +50,22 @@ Public Class EnvelopeEditorController
If EnvelopeModel.Send(Envelope) Then If EnvelopeModel.Send(Envelope) Then
'TODO: Send email to History
Return True Dim newHistoryEntry As New EnvelopeHistoryEntry With {
.EnvelopeId = Envelope.Id,
.ActionType = EnvelopeHistoryActionType.Sent,
.UserReference = Envelope.User.Email
}
If HistoryModel.Insert(newHistoryEntry) Then
'TODO: Send email to History
Return True
Else
Logger.Warn("History Entry could not be created!")
Return False
End If
Else Else
Logger.Warn("Envelope could not be updated!")
Return False Return False
End If End If
End Function End Function

View File

@ -63,8 +63,6 @@ Partial Public Class frmEnvelopeEditor
Controller = New EnvelopeEditorController(State, Envelope) Controller = New EnvelopeEditorController(State, Envelope)
Documents = New BindingList(Of EnvelopeDocument)(Controller.Envelope.Documents) Documents = New BindingList(Of EnvelopeDocument)(Controller.Envelope.Documents)
Receivers = New BindingList(Of EnvelopeReceiver)(Controller.Envelope.Receivers) Receivers = New BindingList(Of EnvelopeReceiver)(Controller.Envelope.Receivers)
txtMessage.EditValue = Controller.Envelope.Message
txtSubject.EditValue = Controller.Envelope.Subject
For Each docItem As EnvelopeDocument In Documents For Each docItem As EnvelopeDocument In Documents
If docItem.Thumbnail Is Nothing Then If docItem.Thumbnail Is Nothing Then
@ -78,6 +76,9 @@ Partial Public Class frmEnvelopeEditor
End If End If
End If End If
txtMessage.EditValue = Controller.Envelope.Message
txtSubject.EditValue = Controller.Envelope.Subject
GridDocuments.DataSource = Documents GridDocuments.DataSource = Documents
GridReceivers.DataSource = Receivers GridReceivers.DataSource = Receivers
End Sub End Sub

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -7,10 +7,12 @@ namespace EnvelopeGenerator.Web.Controllers
public class EnvelopeController : BaseController public class EnvelopeController : BaseController
{ {
private readonly EnvelopeService envelopeService; private readonly EnvelopeService envelopeService;
private readonly EmailService emailService;
public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging) public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope, EmailService email) : base(database, logging)
{ {
envelopeService = envelope; envelopeService = envelope;
emailService = email;
} }
[HttpGet] [HttpGet]
@ -58,6 +60,10 @@ namespace EnvelopeGenerator.Web.Controllers
Status = Common.Constants.DocumentStatus.Signed Status = Common.Constants.DocumentStatus.Signed
}); });
envelopeService.InsertHistoryEntrySigned(response);
SendSignedEmail(response);
return Ok(); return Ok();
} }
catch (Exception e) catch (Exception e)
@ -65,5 +71,18 @@ namespace EnvelopeGenerator.Web.Controllers
return ErrorResponse(e); return ErrorResponse(e);
} }
} }
public bool SendSignedEmail(EnvelopeResponse response)
{
EmailTemplate template = new();
EmailData emailData = new(response.Envelope, response.Receiver)
{
SignatureLink = "",
};
template.FillDocumentSignedEmailBody(emailData);
return emailService.SendEmail(emailData);
}
} }
} }

View File

@ -7,7 +7,7 @@ namespace EnvelopeGenerator.Web.Controllers
{ {
public class ActionObject public class ActionObject
{ {
public string? ActionType { get; set; } public int ActionType { get; set; }
} }
public class HistoryController : BaseController public class HistoryController : BaseController
@ -25,18 +25,12 @@ namespace EnvelopeGenerator.Web.Controllers
{ {
try try
{ {
logger.Info("EnvelopeController/Get"); logger.Info("HistoryController/Post");
// Validate Envelope Key and load envelope // Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey); envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey); EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
EnvelopeHistoryActionType actionType = (EnvelopeHistoryActionType)action.ActionType;
string actionTypeString = action.ActionType;
if (!Enum.TryParse<EnvelopeHistoryActionType>(actionTypeString, out var actionType))
{
return BadRequest();
};
envelopeService.InsertHistoryEntry(new EnvelopeHistoryEntry() envelopeService.InsertHistoryEntry(new EnvelopeHistoryEntry()
{ {

View File

@ -11,6 +11,7 @@ namespace EnvelopeGenerator.Web
// Add base services // Add base services
builder.Services.AddSingleton<LoggingService>(); builder.Services.AddSingleton<LoggingService>();
builder.Services.AddTransient<DatabaseService>(); builder.Services.AddTransient<DatabaseService>();
builder.Services.AddTransient<EmailService>();
// Add higher order services // Add higher order services
builder.Services.AddSingleton<EnvelopeService>(); builder.Services.AddSingleton<EnvelopeService>();

View File

@ -15,6 +15,8 @@ namespace EnvelopeGenerator.Web.Services
public ElementModel elementModel; public ElementModel elementModel;
public HistoryModel historyModel; public HistoryModel historyModel;
public DocumentStatusModel documentStatusModel; public DocumentStatusModel documentStatusModel;
public EmailModel emailModel;
public ConfigModel configModel;
public ModelContainer(State state) public ModelContainer(State state)
{ {
@ -24,6 +26,8 @@ namespace EnvelopeGenerator.Web.Services
elementModel = new(state); elementModel = new(state);
historyModel = new(state); historyModel = new(state);
documentStatusModel = new(state); documentStatusModel = new(state);
emailModel = new(state);
configModel = new(state);
} }
} }
public readonly ModelContainer? Models; public readonly ModelContainer? Models;
@ -39,7 +43,16 @@ namespace EnvelopeGenerator.Web.Services
{ {
logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString); logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
// There is a circular dependency between state and models
// All models need a state object, including the config Model
// The state object needs to be filled with the DbConfig property,
// which is obtained by the config Model.
// So first, the config model is initialized with an incomplete state object,
// then all the other models with the DbConfig property filled.
var state = GetState(); var state = GetState();
var configModel = new ConfigModel(state);
state.DbConfig = configModel.LoadConfiguration();
Models = new(state); Models = new(state);
} }
else else

View File

@ -0,0 +1,38 @@
using EnvelopeGenerator.Common;
namespace EnvelopeGenerator.Web.Services
{
public class EmailService : BaseService
{
private ReceiverModel receiverModel;
private EnvelopeModel envelopeModel;
private HistoryModel historyModel;
private DocumentModel documentModel;
private DocumentStatusModel documentStatusModel;
private EmailModel emailModel;
public EmailService(IConfiguration Config, LoggingService Logging, DatabaseService database) : base(Config, Logging)
{
logger = Logging.LogConfig.GetLogger();
if (database.Models == null)
{
throw new ArgumentNullException("Models not loaded.");
}
receiverModel = database.Models.receiverModel;
envelopeModel = database.Models.envelopeModel;
historyModel = database.Models.historyModel;
documentModel = database.Models.documentModel;
documentStatusModel = database.Models.documentStatusModel;
emailModel = database.Models.emailModel;
}
public bool SendEmail(EmailData emailData)
{
return emailModel.Insert(emailData);
}
}
}

View File

@ -101,23 +101,9 @@
return annotation return annotation
} }
async createFrameAnnotation(annotation, receiver) { createImageAnnotation(boundingBox, pageIndex, imageAttachmentId) {
const left = annotation.boundingBox.left - 25
const top = annotation.boundingBox.top - 25
const width = 150
const height = 75
const imageUrl = await this.Annotation.createAnnotationFrameBlob(
receiver.name,
width,
height
)
const request = await fetch(imageUrl)
const blob = await request.blob()
const imageAttachmentId = await this.Instance.createAttachment(blob)
const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({ const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({
pageIndex: annotation.pageIndex, pageIndex: pageIndex,
isSignature: false, isSignature: false,
readOnly: true, readOnly: true,
locked: true, locked: true,
@ -125,13 +111,9 @@
contentType: 'image/png', contentType: 'image/png',
imageAttachmentId, imageAttachmentId,
description: 'FRAME', description: 'FRAME',
boundingBox: new PSPDFKit.Geometry.Rect({ boundingBox: boundingBox,
left: left, });
top: top, return frameAnnotation
width: width,
height: height,
}),
})
} }
async createAnnotationFrameBlob(receiverName, width, height) { async createAnnotationFrameBlob(receiverName, width, height) {

View File

@ -93,10 +93,26 @@ class App {
const isSignature = !!annotation.isSignature const isSignature = !!annotation.isSignature
if (isFormField === false && isSignature === true) { if (isFormField === false && isSignature === true) {
await this.Annotation.createFrameAnnotation(
annotation, const left = annotation.boundingBox.left - 25;
this.currentReceiver const top = annotation.boundingBox.top - 25;
) const width = 150;
const height = 75;
const imageUrl = await this.Annotation.createAnnotationFrameBlob(this.currentReceiver.name, width, height);
const request = await fetch(imageUrl);
const blob = await request.blob();
const imageAttachmentId = await this.Instance.createAttachment(blob);
const frameAnnotation = this.Annotation.createImageAnnotation(new PSPDFKit.Geometry.Rect({
left: left,
top: top,
width: width,
height: height,
}), annotation.pageIndex, imageAttachmentId)
this.Instance.create(frameAnnotation);
} }
} }
@ -119,8 +135,8 @@ class App {
result = await this.handleFinish(null) result = await this.handleFinish(null)
if (result == true) { if (result == true) {
// TODO: Redirect to success page // Redirect to success page after saving to database
alert('Dokument erfolgreich signiert!') window.location.href = `/EnvelopeKey/${this.envelopeKey}/Success`
} else { } else {
alert('Fehler beim Abschließen des Dokuments!') alert('Fehler beim Abschließen des Dokuments!')
} }
@ -147,12 +163,11 @@ class App {
JSON.stringify(json) JSON.stringify(json)
) )
console.log(postEnvelopeResult)
if (postEnvelopeResult === false) { if (postEnvelopeResult === false) {
return false return false
} }
// Redirect to success page after saving to database
window.location.href = `/EnvelopeKey/${this.envelopeKey}/Success`
} catch (e) { } catch (e) {
console.error(e) console.error(e)
return false return false

View File

@ -39,6 +39,8 @@
actionType: actionType, actionType: actionType,
} }
console.log(data)
const options = { const options = {
credentials: 'include', credentials: 'include',
method: 'POST', method: 'POST',