From 207bc8bcbdcb0c41f4669a10eb3ede6d8a2607e1 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 9 Sep 2025 18:11:14 +0200 Subject: [PATCH] convert csrfToken to get method --- .../Dto/DocumentReceiverElementDto.cs | 10 ++++++++++ EnvelopeGenerator.Web/wwwroot/js/annotation.js | 2 +- EnvelopeGenerator.Web/wwwroot/js/network.js | 6 ++++-- EnvelopeGenerator.Web/wwwroot/js/network.min.js | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/EnvelopeGenerator.Application/Dto/DocumentReceiverElementDto.cs b/EnvelopeGenerator.Application/Dto/DocumentReceiverElementDto.cs index 91d34b91..01e6c13f 100644 --- a/EnvelopeGenerator.Application/Dto/DocumentReceiverElementDto.cs +++ b/EnvelopeGenerator.Application/Dto/DocumentReceiverElementDto.cs @@ -82,4 +82,14 @@ public class DocumentReceiverElementDto /// Gets or sets the timestamp when the element was last changed, if applicable. /// public DateTime? ChangedWhen { get; set; } + + /// + /// Gets or sets the top position of the element (in layout terms). + /// + public double Top => Y; + + /// + /// Gets or sets the left position of the element (in layout terms). + /// + public double Left => X; } \ No newline at end of file diff --git a/EnvelopeGenerator.Web/wwwroot/js/annotation.js b/EnvelopeGenerator.Web/wwwroot/js/annotation.js index c247a4c4..c5ddf54f 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/annotation.js +++ b/EnvelopeGenerator.Web/wwwroot/js/annotation.js @@ -3,7 +3,7 @@ async function createAnnotations(document, instance) { const signatures = []; for(var element of document.elements) { - const annotParams = await getAnnotationParams(element.x, element.y); + const annotParams = await getAnnotationParams(element.left, element.top); const page = element.page - 1 //background diff --git a/EnvelopeGenerator.Web/wwwroot/js/network.js b/EnvelopeGenerator.Web/wwwroot/js/network.js index a531e7e1..1900ce79 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/network.js +++ b/EnvelopeGenerator.Web/wwwroot/js/network.js @@ -1,7 +1,9 @@ /** * Fetches CSRF Token from page */ -const csrfToken = { 'X-XSRF-TOKEN': document.getElementsByName('__RequestVerificationToken')[0].value }; +function getCsrfToken() { + return { 'X-XSRF-TOKEN': document.getElementsByName('__RequestVerificationToken')[0].value } +} /** * Save signature data to server @@ -9,7 +11,7 @@ const csrfToken = { 'X-XSRF-TOKEN': document.getElementsByName('__RequestVerific * @param {any} annotations */ function postEnvelope(annotations) { - const token = csrfToken + const token = getCsrfToken() const options = { credentials: 'include', method: 'POST', diff --git a/EnvelopeGenerator.Web/wwwroot/js/network.min.js b/EnvelopeGenerator.Web/wwwroot/js/network.min.js index 7355643d..0ee0a772 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/network.min.js +++ b/EnvelopeGenerator.Web/wwwroot/js/network.min.js @@ -1 +1 @@ -function postEnvelope(n){const t=csrfToken,i={credentials:"include",method:"POST",headers:{...t,"Content-Type":"application/json; charset=utf-8"},body:JSON.stringify(n)};return fetch(`/api/envelope`,i)}async function setLangAsync(n,t){document.getElementById("selectedFlag").className="fi "+t+" me-2";await fetch(`/api/localization/lang/${n}`,{method:"POST",headers:{"Content-Type":"application/json"}})}async function setLanguage(n){const t=await fetch("/api/localization/lang",{method:"GET",headers:{"Content-Type":"application/json"}}).then(n=>n.json()).then(t=>t.includes(n)).catch(()=>!1);if(t)return await fetch(`/api/localization/lang/${n}`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{if(n.redirected)window.location.href=n.url;else if(!n.ok)return Promise.reject("Failed to set language")})}async function logout(){return await fetch(`/auth/logout`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{n.ok&&(window.location.href="/")})}async function getAnnotationParams(n=0,t=0,i=72){var f,r;const u=await fetch(`${window.location.origin}/api/Config/Annotations`,{credentials:"include",method:"GET"}).then(n=>n.json());for(f in u)r=u[f],r.width*=i,r.height*=i,r.left+=n-.7,r.left*=i,r.top+=t-.5,r.top*=i;return u}const csrfToken={"X-XSRF-TOKEN":document.getElementsByName("__RequestVerificationToken")[0].value}; \ No newline at end of file +function getCsrfToken(){return{"X-XSRF-TOKEN":document.getElementsByName("__RequestVerificationToken")[0].value}}function postEnvelope(n){const t=getCsrfToken(),i={credentials:"include",method:"POST",headers:{...t,"Content-Type":"application/json; charset=utf-8"},body:JSON.stringify(n)};return fetch(`/api/envelope`,i)}async function setLangAsync(n,t){document.getElementById("selectedFlag").className="fi "+t+" me-2";await fetch(`/api/localization/lang/${n}`,{method:"POST",headers:{"Content-Type":"application/json"}})}async function setLanguage(n){const t=await fetch("/api/localization/lang",{method:"GET",headers:{"Content-Type":"application/json"}}).then(n=>n.json()).then(t=>t.includes(n)).catch(()=>!1);if(t)return await fetch(`/api/localization/lang/${n}`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{if(n.redirected)window.location.href=n.url;else if(!n.ok)return Promise.reject("Failed to set language")})}async function logout(){return await fetch(`/auth/logout`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{n.ok&&(window.location.href="/")})}async function getAnnotationParams(n=0,t=0,i=72){var f,r;const u=await fetch(`${window.location.origin}/api/Config/Annotations`,{credentials:"include",method:"GET"}).then(n=>n.json());for(f in u)r=u[f],r.width*=i,r.height*=i,r.left+=n-.7,r.left*=i,r.top+=t-.5,r.top*=i;return u} \ No newline at end of file