mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-20 06:35:54 +02:00
fix: not able to subscribed free plan & stop sending individual mail
This commit is contained in:
@@ -13,7 +13,18 @@ export default async function SubscribeFree(request) {
|
||||
const extUpdate = new Parse.Object('contracts_Users');
|
||||
extUpdate.id = extUser.id;
|
||||
extUpdate.set('Plan', { plan_code: 'freeplan' });
|
||||
const updatePlan = await extUpdate.save(null, { useMasterKey: true });
|
||||
await extUpdate.save(null, { useMasterKey: true });
|
||||
return { status: 'success', result: 'subscribed!' };
|
||||
} catch (err) {
|
||||
console.log('err ', err);
|
||||
return { status: 'error', result: err.message };
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const extUpdate = new Parse.Object('contracts_Users');
|
||||
extUpdate.id = extUser.id;
|
||||
extUpdate.set('Plan', { plan_code: 'freeplan' });
|
||||
await extUpdate.save(null, { useMasterKey: true });
|
||||
return { status: 'success', result: 'subscribed!' };
|
||||
} catch (err) {
|
||||
console.log('err ', err);
|
||||
|
||||
+54
-89
@@ -17,20 +17,20 @@ async function uploadFile(e, a) {
|
||||
console.log('Err ', e), fs.unlinkSync(a);
|
||||
}
|
||||
}
|
||||
async function updateDoc(t, s, r, i, o, n) {
|
||||
async function updateDoc(t, s, r, o, i, n) {
|
||||
try {
|
||||
var d = {
|
||||
UserPtr: { __type: 'Pointer', className: n, objectId: r },
|
||||
SignedUrl: s,
|
||||
Activity: 'Signed',
|
||||
ipAddress: i,
|
||||
ipAddress: o,
|
||||
};
|
||||
let e;
|
||||
var l = (e = o.AuditTrail && 0 < o.AuditTrail.length ? [...o.AuditTrail, d] : [d]).filter(
|
||||
var l = (e = i.AuditTrail && 0 < i.AuditTrail.length ? [...i.AuditTrail, d] : [d]).filter(
|
||||
e => 'Signed' === e.Activity
|
||||
);
|
||||
let a = !1;
|
||||
!((o.Signers && 0 < o.Signers.length && l.length !== o.Signers.length) || !(a = !0));
|
||||
!((i.Signers && 0 < i.Signers.length && l.length !== i.Signers.length) || !(a = !0));
|
||||
var c = { SignedUrl: s, AuditTrail: e, IsCompleted: a };
|
||||
await axios.put(serverUrl + '/classes/contracts_Document/' + t, c, {
|
||||
headers: {
|
||||
@@ -44,31 +44,6 @@ async function updateDoc(t, s, r, i, o, n) {
|
||||
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: 'You have signed the doc - ' + s,
|
||||
pdfName: s,
|
||||
html:
|
||||
"<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /></head><body> <div style='background-color:#f5f5f5;padding:20px'> <div style='box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;background-color:white;'> <div><img src=https://qikinnovation.ams3.digitaloceanspaces.com/logo.png height='50' style='padding:20px'/> </div><div style='padding:2px;font-family:system-ui; background-color: #47a3ad;'> <p style='font-size:20px;font-weight:400;color:white;padding-left:20px',> Document Copy</p></div><div><p style='padding:20px;font-family:system-ui;font-size:14px'>A copy of the document " +
|
||||
s +
|
||||
' Standard is attached to this email. Kindly download the document from the attachment.</p></div> </div><div><p>This is an automated email from OpenSign™. 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 OpenSign™ <a href=www.opensignlabs.com target=_blank>here</a>.</p></div></div></body></html>',
|
||||
};
|
||||
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,
|
||||
@@ -152,10 +127,10 @@ async function sendDoctoWebhook(t, e, a, s) {
|
||||
}
|
||||
}));
|
||||
}
|
||||
async function PDF(o) {
|
||||
async function PDF(i) {
|
||||
try {
|
||||
var e = o.params.docId,
|
||||
a = o.params.userId,
|
||||
var e = i.params.docId,
|
||||
a = i.params.userId,
|
||||
n = await axios.get(
|
||||
serverUrl + '/classes/contracts_Document/' + e + '?include=ExtUserPtr,Signers',
|
||||
{
|
||||
@@ -169,7 +144,7 @@ async function PDF(o) {
|
||||
d = await axios.get(serverUrl + '/users/me', {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': APPID,
|
||||
'X-Parse-Session-Token': o.headers.sessiontoken,
|
||||
'X-Parse-Session-Token': i.headers.sessiontoken,
|
||||
},
|
||||
});
|
||||
if (!d.data || !d.data.objectId) return { status: 'error', message: 'This user not allowed!' };
|
||||
@@ -178,12 +153,12 @@ async function PDF(o) {
|
||||
s,
|
||||
l,
|
||||
c = JSON.stringify({ objectId: a });
|
||||
let r, i;
|
||||
i = a
|
||||
let r, o;
|
||||
o = a
|
||||
? (t = await axios.get(serverUrl + '/classes/contracts_Contactbook?where=' + c, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': APPID,
|
||||
'X-Parse-Session-Token': o.headers.sessiontoken,
|
||||
'X-Parse-Session-Token': i.headers.sessiontoken,
|
||||
},
|
||||
})).data && 0 < t.data.results.length
|
||||
? ((r = t), 'contracts_Contactbook')
|
||||
@@ -201,56 +176,56 @@ async function PDF(o) {
|
||||
: ((r = await axios.get(serverUrl + '/classes/contracts_Contactbook?where=' + s, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': APPID,
|
||||
'X-Parse-Session-Token': o.headers.sessiontoken,
|
||||
'X-Parse-Session-Token': i.headers.sessiontoken,
|
||||
},
|
||||
})),
|
||||
'contracts_Contactbook'));
|
||||
var p = r.data.results[0].Name,
|
||||
m = r.data.results[0].Email;
|
||||
if (!o.params.pdfFile) return { status: 'error', message: 'pdf file not present!' };
|
||||
if (!i.params.pdfFile) return { status: 'error', message: 'pdf file not present!' };
|
||||
{
|
||||
let e = Buffer.from(o.params.pdfFile, 'base64');
|
||||
let e = Buffer.from(i.params.pdfFile, 'base64');
|
||||
var g = process.env.PFX_BASE64,
|
||||
h = Buffer.from(g, 'base64'),
|
||||
u = {
|
||||
UserPtr: { __type: 'Pointer', className: i, objectId: r.data.results[0].objectId },
|
||||
u = Buffer.from(g, 'base64'),
|
||||
h = {
|
||||
UserPtr: { __type: 'Pointer', className: o, objectId: r.data.results[0].objectId },
|
||||
SignedUrl: '',
|
||||
Activity: 'Signed',
|
||||
ipAddress: o.headers['x-real-ip'],
|
||||
ipAddress: i.headers['x-real-ip'],
|
||||
};
|
||||
let a;
|
||||
var f = (a =
|
||||
n.data.AuditTrail && 0 < n.data.AuditTrail.length
|
||||
? [...n.data.AuditTrail, u]
|
||||
: [u]).filter(e => 'Signed' === e.Activity);
|
||||
? [...n.data.AuditTrail, h]
|
||||
: [h]).filter(e => 'Signed' === e.Activity);
|
||||
let t = !1;
|
||||
!(
|
||||
(n.data.Signers && 0 < n.data.Signers.length && f.length !== n.data.Signers.length) ||
|
||||
!(t = !0)
|
||||
);
|
||||
var y,
|
||||
var P,
|
||||
y,
|
||||
v,
|
||||
P,
|
||||
b,
|
||||
U,
|
||||
x,
|
||||
w = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
|
||||
I = './exports/' + w;
|
||||
I,
|
||||
S = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
|
||||
A = './exports/' + S;
|
||||
let s = e.length;
|
||||
s = (
|
||||
t
|
||||
? ((y = n.data.Signers?.map(e => e.Name + ' <' + e.Email + '>')),
|
||||
? ((P = n.data.Signers?.map(e => e.Name + ' <' + e.Email + '>')),
|
||||
(e =
|
||||
y && 0 < y.length
|
||||
? ((v = await PDFDocument.load(e)),
|
||||
P && 0 < P.length
|
||||
? ((y = await PDFDocument.load(e)),
|
||||
pdflibAddPlaceholder({
|
||||
pdfDoc: v,
|
||||
reason: 'Digitally signed by OpenSign for ' + y?.join(', '),
|
||||
pdfDoc: y,
|
||||
reason: 'Digitally signed by OpenSign for ' + P?.join(', '),
|
||||
location: 'location',
|
||||
signatureLength: 15e3,
|
||||
}),
|
||||
(P = await v.save()),
|
||||
Buffer.from(P))
|
||||
(v = await y.save()),
|
||||
Buffer.from(v))
|
||||
: ((b = await PDFDocument.load(e)),
|
||||
pdflibAddPlaceholder({
|
||||
pdfDoc: b,
|
||||
@@ -260,40 +235,30 @@ async function PDF(o) {
|
||||
}),
|
||||
(U = await b.save()),
|
||||
Buffer.from(U))),
|
||||
(x = await new SignPDF(e, h).signPDF()),
|
||||
fs.writeFileSync(I, x),
|
||||
x)
|
||||
: (fs.writeFileSync(I, e), e)
|
||||
(I = await new SignPDF(e, u).signPDF()),
|
||||
fs.writeFileSync(A, I),
|
||||
I)
|
||||
: (fs.writeFileSync(A, e), e)
|
||||
).length;
|
||||
var S,
|
||||
A,
|
||||
var w,
|
||||
D,
|
||||
E = await uploadFile(w, I);
|
||||
if (E && E.imageUrl)
|
||||
x = await uploadFile(S, A);
|
||||
if (x && x.imageUrl)
|
||||
return (
|
||||
(S = await updateDoc(
|
||||
o.params.docId,
|
||||
E.imageUrl,
|
||||
(w = await updateDoc(
|
||||
i.params.docId,
|
||||
x.imageUrl,
|
||||
r.data.results[0].objectId,
|
||||
o.headers['x-real-ip'],
|
||||
i.headers['x-real-ip'],
|
||||
n.data,
|
||||
i
|
||||
o
|
||||
)),
|
||||
(A = {
|
||||
url: E.imageUrl,
|
||||
sender: { Mail: n.data.ExtUserPtr.Email, Name: n.data.ExtUserPtr.Name },
|
||||
pdfName: n.data.Name,
|
||||
receiver: m,
|
||||
}),
|
||||
n.data.IsSendMail && !1 === n.data.IsSendMail
|
||||
? console.log("don't send mail")
|
||||
: sendMail(A),
|
||||
sendDoctoWebhook(n, E.imageUrl, 'signed', r?.data.results?.[0]),
|
||||
saveFileUsage(s, E.imageUrl, d.data.objectId),
|
||||
S &&
|
||||
S.isCompleted &&
|
||||
sendDoctoWebhook(n, x.imageUrl, 'signed', r?.data.results?.[0]),
|
||||
saveFileUsage(s, x.imageUrl, d.data.objectId),
|
||||
w &&
|
||||
w.isCompleted &&
|
||||
((D = {
|
||||
url: E.imageUrl,
|
||||
url: x.imageUrl,
|
||||
sender: { Mail: n.data.ExtUserPtr.Email, Name: 'OpenSign™' },
|
||||
pdfName: n.data.Name,
|
||||
receiver: n.data.ExtUserPtr.Email,
|
||||
@@ -301,11 +266,11 @@ async function PDF(o) {
|
||||
n.data.IsSendMail && !1 === n.data.IsSendMail
|
||||
? console.log("don't send mail")
|
||||
: sendCompletedMail(D),
|
||||
sendDoctoWebhook(n, E.imageUrl, 'completed')),
|
||||
fs.unlinkSync(I),
|
||||
console.log('New Signed PDF created called: ' + I),
|
||||
'success' === S.message
|
||||
? { status: 'success', data: E.imageUrl }
|
||||
sendDoctoWebhook(n, x.imageUrl, 'completed')),
|
||||
fs.unlinkSync(A),
|
||||
console.log('New Signed PDF created called: ' + A),
|
||||
'success' === w.message
|
||||
? { status: 'success', data: x.imageUrl }
|
||||
: { status: 'error', message: 'please provide required parameters!' }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user