diff --git a/README.md b/README.md index ae55069ab..272bb9306 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,11 @@ Welcome to OpenSign, an open-source document e-signing solution designed to prov - **Completion Certificate**: Generate secure completion certificate as soon as a document is signed by all participants. - **API Support**: Provides a robust API for integration into other software and services. + + + + + --- ### Installation diff --git a/apps/OpenSignServer/cloud/parsefunction/AuthLoginAsMail.js b/apps/OpenSignServer/cloud/parsefunction/AuthLoginAsMail.js index ee39b05bb..64e5fab0f 100644 --- a/apps/OpenSignServer/cloud/parsefunction/AuthLoginAsMail.js +++ b/apps/OpenSignServer/cloud/parsefunction/AuthLoginAsMail.js @@ -50,7 +50,7 @@ async function AuthLoginAsMail(request) { if (res.data) { resolve(res.data); } else { - reject('User not found!'); + reject('user not found!'); } }) .catch(err => { @@ -59,25 +59,7 @@ async function AuthLoginAsMail(request) { // user couldn't find lets sign up! }) .catch(() => { - let user = new Parse.User(); - user.set('username', email); - user.set('email', email); - user.set('password', '12345'); - user - .save() - .then(token => { - var error = token == '' ? true : false; - if (error) { - reject('result not found!'); - } else { - resolve(token); - } - }) - .catch(e => { - console.log('error in auth'); - reject('user already exists!'); - console.log(e); - }); + reject('user not found!'); }); }); } diff --git a/apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js b/apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js index 1134d8fae..188e0e3d4 100644 --- a/apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js +++ b/apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js @@ -1 +1,204 @@ -import SignPDF from"./SignPDF.min.cjs";import fs from"node:fs";import axios from"axios";import FormData from"form-data";import plainplaceholder from"./customSignPdf/plainplaceholder.min.js";import{plainAddPlaceholder}from"node-signpdf/dist/helpers/index.js";const serverUrl=process.env.SERVER_URL,APPID=process.env.APP_ID,masterKEY=process.env.MASTER_KEY;async function uploadFile(a){try{var e=new FormData,t=(e.append("file",fs.createReadStream(a)),{"content-type":"multipart/form-data","X-Parse-Application-Id":process.env.APP_ID}),s=process.env.SERVER_URL.slice(0,-4)+"/file_upload";return(await axios.post(s,e,{headers:t})).data}catch(e){console.log("err ",e),fs.unlinkSync(a)}}async function updateDoc(t,s,i,r,n,o){try{var d={UserPtr:{__type:"Pointer",className:o,objectId:i},SignedUrl:s,Activity:"Signed",ipAddress:r};let e;var l=(e=n.AuditTrail&&0"Signed"===e.Activity);let a=!1;!(n.Signers&&0

Document Copy

A copy of the document "+s+" Standard is attached to this email. Kindly download the document from the attachment.

This is an automated email from Open Sign. For any queries regarding this email, please contact the sender "+t.Mail+" directly. If you think this email is inappropriate or spam, you may file a complaint with Open Sign here.

"};await axios.post(serverUrl+"/functions/sendmailv3",a,{headers:{"Content-Type":"application/json","X-Parse-Application-Id":APPID,"X-Parse-Master-Key":masterKEY}})}async function sendCompletedMail(e){var a=e.url,t=e.sender,s=e.pdfName,a={url:a,from:"Open sign",recipient:e.receiver,subject:`Document ${s} has beeen signed by all parties`,pdfName:s,html:"

Document sign successfully

All parties have successfully signed the document"+s+". Kindly download the document from the attachment.

This is an automated email from Open Sign. For any queries regarding this email, please contact the sender "+t.Mail+" directly. If you think this email is inappropriate or spam, you may file a complaint with Open Sign here.

"};await axios.post(serverUrl+"/functions/sendmailv3",a,{headers:{"Content-Type":"application/json","X-Parse-Application-Id":APPID,"X-Parse-Master-Key":masterKEY}})}async function PDF(s,i){try{var r=s.params.sign,e=s.params.docId,n=await axios.get(serverUrl+"/classes/contracts_Document/"+e+"?include=ExtUserPtr",{headers:{"Content-Type":"application/json","X-Parse-Application-Id":APPID,"X-Parse-Session-Token":s.headers.sessiontoken}}),o=await axios.get(serverUrl+"/users/me",{headers:{"X-Parse-Application-Id":APPID,"X-Parse-Session-Token":s.headers.sessiontoken}});if(!o.data||!o.data.objectId)return{status:"error",message:"this user not allowed!"};{var d=JSON.stringify({UserId:{__type:"Pointer",className:"_User",objectId:o.data.objectId}});let a,t;var l=await axios.get(serverUrl+"/classes/contracts_Users?where="+d,{headers:{"X-Parse-Application-Id":APPID,"X-Parse-Session-Token":s.headers.sessiontoken}}),p=(t=l.data&&0",location:"test location",signatureLength:1e4,sign:r}):plainAddPlaceholder({pdfBuffer:e,reason:"Digitally signed by Open sign for "+p+" <"+c+">",location:"test location",signatureLength:1e4});var g=await new SignPDF(e,m).signPDF(),u=`./exports/exported_file_${Math.floor(5e3*Math.random())}.pdf`,f=(fs.writeFileSync(u,g),await uploadFile(u));if(f&&f.imageUrl){const i=await updateDoc(s.params.docId,f.imageUrl,a.data.results[0].objectId,s.headers["x-real-ip"],n.data,t);return sendMail({url:f.imageUrl,sender:{Mail:n.data.ExtUserPtr.Email,Name:n.data.ExtUserPtr.Name},pdfName:n.data.Name,receiver:c}),i&&i.isCompleted&&sendCompletedMail({url:f.imageUrl,sender:{Mail:n.data.ExtUserPtr.Email,Name:"Open sign"},pdfName:n.data.Name,receiver:n.data.ExtUserPtr.Email}),fs.unlinkSync(u),console.log("New Signed PDF created called: "+u),"success"===i.message?{status:"success",data:f.imageUrl}:{status:"error",message:"please provide required parameters!"}}}}}catch(e){return console.log("Err ",e),"ERR_BAD_REQUEST"===e.code?{status:"error",message:"Invalid session token!"}:{status:"error",message:"Encrypted files are currently not supported!"}}}export default PDF; \ No newline at end of file +import SignPDF from "./SignPDF.min.cjs"; +import fs from "node:fs"; +import axios from "axios"; +import FormData from "form-data"; +import plainplaceholder from "./customSignPdf/plainplaceholder.min.js"; +import { + plainAddPlaceholder +} from "node-signpdf/dist/helpers/index.js"; +const serverUrl = process.env.SERVER_URL, + APPID = process.env.APP_ID, + masterKEY = process.env.MASTER_KEY; +async function uploadFile(a) { + try { + var e = new FormData, + t = (e.append("file", fs.createReadStream(a)), { + "content-type": "multipart/form-data", + "X-Parse-Application-Id": process.env.APP_ID + }), + s = process.env.SERVER_URL.slice(0, -4) + "/file_upload"; + return (await axios.post(s, e, { + headers: t + })).data + } catch (e) { + console.log("err ", e), fs.unlinkSync(a) + } +} +async function updateDoc(t, s, i, r, n, o) { + try { + var d = { + UserPtr: { + __type: "Pointer", + className: o, + objectId: i + }, + SignedUrl: s, + Activity: "Signed", + ipAddress: r + }; + let e; + var l = (e = n.AuditTrail && 0 < n.AuditTrail.length ? [...n.AuditTrail, d] : [d]).filter(e => "Signed" === e.Activity); + let a = !1; + !(n.Signers && 0 < n.Signers.length && l.length !== n.Signers.length || !(a = !0)); + var p = { + SignedUrl: s, + AuditTrail: e, + IsCompleted: a + }; + await axios.put(serverUrl + "/classes/contracts_Document/" + t, p, { + headers: { + "Content-Type": "application/json", + "X-Parse-Application-Id": APPID, + "X-Parse-Master-Key": masterKEY + } + }); + return { + isCompleted: a, + message: "success" + } + } catch (e) { + return console.log("update doc err ", e), "err" + } +} +async function sendMail(e) { + var a = e.url, + t = e.sender, + s = e.pdfName, + a = { + url: a, + from: "OpenSign™", + recipient: e.receiver, + subject: t.Name + " has signed the doc - " + s, + pdfName: s, + html: "

Document Copy

A copy of the document " + s + " Standard is attached to this email. Kindly download the document from the attachment.

This is an automated email from Open Sign. For any queries regarding this email, please contact the sender " + t.Mail + " directly. If you think this email is inappropriate or spam, you may file a complaint with Open Sign here.

" + }; + await axios.post(serverUrl + "/functions/sendmailv3", a, { + headers: { + "Content-Type": "application/json", + "X-Parse-Application-Id": APPID, + "X-Parse-Master-Key": masterKEY + } + }) +} +async function sendCompletedMail(e) { + var a = e.url, + t = e.sender, + s = e.pdfName, + a = { + url: a, + from: "Open sign", + recipient: e.receiver, + subject: `Document ${s} has been signed by all parties`, + pdfName: s, + html: "

Document signed successfully

All parties have successfully signed the document " + s + ". Kindly download the document from the attachment.

This is an automated email from Open Sign. For any queries regarding this email, please contact the sender " + t.Mail + " directly. If you think this email is inappropriate or spam, you may file a complaint with Open Sign here.

" + }; + await axios.post(serverUrl + "/functions/sendmailv3", a, { + headers: { + "Content-Type": "application/json", + "X-Parse-Application-Id": APPID, + "X-Parse-Master-Key": masterKEY + } + }) +} +async function PDF(s, i) { + try { + var r = s.params.sign, + e = s.params.docId, + n = await axios.get(serverUrl + "/classes/contracts_Document/" + e + "?include=ExtUserPtr", { + headers: { + "Content-Type": "application/json", + "X-Parse-Application-Id": APPID, + "X-Parse-Session-Token": s.headers.sessiontoken + } + }), + o = await axios.get(serverUrl + "/users/me", { + headers: { + "X-Parse-Application-Id": APPID, + "X-Parse-Session-Token": s.headers.sessiontoken + } + }); + if (!o.data || !o.data.objectId) return { + status: "error", + message: "this user not allowed!" + }; { + var d = JSON.stringify({ + UserId: { + __type: "Pointer", + className: "_User", + objectId: o.data.objectId + } + }); + let a, t; + var l = await axios.get(serverUrl + "/classes/contracts_Users?where=" + d, { + headers: { + "X-Parse-Application-Id": APPID, + "X-Parse-Session-Token": s.headers.sessiontoken + } + }), + p = (t = l.data && 0 < l.data.results.length ? (a = l, "contracts_Users") : (a = await axios.get(serverUrl + "/classes/contracts_Contactbook?where=" + d, { + headers: { + "X-Parse-Application-Id": APPID, + "X-Parse-Session-Token": s.headers.sessiontoken + } + }), "contracts_Contactbook"), a.data.results[0].Name), + c = a.data.results[0].Email; + if (!s.params.pdfFile) return { + status: "error", + message: "pdf file not present!" + }; { + let e = Buffer.from(s.params.pdfFile, "base64"); + var m = fs.readFileSync("pdfFile/emudhra-test-class2.pfx"); + e = r ? plainplaceholder({ + pdfBuffer: e, + reason: "Digitally signed by Open sign for " + p + " <" + c + ">", + location: "test location", + signatureLength: 1e4, + sign: r + }) : plainAddPlaceholder({ + pdfBuffer: e, + reason: "Digitally signed by Open sign for " + p + " <" + c + ">", + location: "test location", + signatureLength: 1e4 + }); + var g = await new SignPDF(e, m).signPDF(), + u = `./exports/exported_file_${Math.floor(5e3 * Math.random())}.pdf`, + f = (fs.writeFileSync(u, g), await uploadFile(u)); + if (f && f.imageUrl) { + const i = await updateDoc(s.params.docId, f.imageUrl, a.data.results[0].objectId, s.headers["x-real-ip"], n.data, t); + return sendMail({ + url: f.imageUrl, + sender: { + Mail: n.data.ExtUserPtr.Email, + Name: n.data.ExtUserPtr.Name + }, + pdfName: n.data.Name, + receiver: c + }), i && i.isCompleted && sendCompletedMail({ + url: f.imageUrl, + sender: { + Mail: n.data.ExtUserPtr.Email, + Name: "Open sign" + }, + pdfName: n.data.Name, + receiver: n.data.ExtUserPtr.Email + }), fs.unlinkSync(u), console.log("New Signed PDF created called: " + u), "success" === i.message ? { + status: "success", + data: f.imageUrl + } : { + status: "error", + message: "please provide required parameters!" + } + } + } + } + } catch (e) { + return console.log("Err ", e), "ERR_BAD_REQUEST" === e.code ? { + status: "error", + message: "Invalid session token!" + } : { + status: "error", + message: "Encrypted files are currently not supported!" + } + } +} +export default PDF; \ No newline at end of file