feat: add emailcount of user

This commit is contained in:
prafull-opensignlabs
2024-03-31 12:42:08 +05:30
parent d588caf6d4
commit 5adaffc684
14 changed files with 126 additions and 102 deletions
@@ -1,4 +1,4 @@
import axios from 'axios'
import { updateMailCount } from '../../Utils.js';
async function sendMailOTPv1(request) {
try {
@@ -11,37 +11,40 @@ async function sendMailOTPv1(request) {
// console.log(JSON.stringify(request));
if (email) {
axios({
method: 'POST',
url: process.env.SERVER_URL + '/functions/sendmail',
headers: {
'Content-Type': 'application/json',
'X-Parse-Application-Id': process.env.APP_ID,
},
params: {
otp: code,
email: email,
TenantId: TenantId,
},
}).then(
function (httpResponse) {},
function (httpResponse) {
console.error('sms Request failed with response code ' + httpResponse.status);
return Promise.reject('sms Request failed with response code ' + httpResponse.status);
const recipient = request.params.email;
const otp = request.params.otp;
const mailsender = process.env.SMTP_ENABLE
? process.env.SMTP_USER_EMAIL
: process.env.MAILGUN_SENDER;
try {
await Parse.Cloud.sendEmail({
from: 'Opensign™' + ' <' + mailsender + '>',
recipient: recipient,
subject: 'Your OpenSign™ OTP',
text: 'This email is a test.',
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 style='background-color:red;padding:2px;font-family:system-ui; background-color:#47a3ad;'> <p style='font-size:20px;font-weight:400;color:white;padding-left:20px',>OTP Verification</p></div><div style='padding:20px'><p style='font-family:system-ui;font-size:14px'>Your OTP for OpenSign™ verification is:</p><p style=' text-decoration: none; font-weight: bolder; color:blue;font-size:45px;margin:20px'>" +
otp +
'</p></div> </div> </div></body></html>',
});
console.log('OTP sent');
if (request.params?.extUserId) {
await updateMailCount(request.params.extUserId);
}
);
} catch (err) {
console.log('error in send OTP mail', err);
}
const tempOtp = new Parse.Query('defaultdata_Otp');
tempOtp.equalTo('Email', email);
const resultOTP = await tempOtp.first({ useMasterKey: true });
console.log('resultOTP', resultOTP);
// console.log('resultOTP', resultOTP);
if (resultOTP !== undefined) {
const updateOtpQuery = new Parse.Query('defaultdata_Otp');
const updateOtp = await updateOtpQuery.get(resultOTP.id, {
useMasterKey: true,
});
updateOtp.set('OTP', code);
const updateRes = updateOtp.save(null, { useMasterKey: true });
updateOtp.save(null, { useMasterKey: true });
// console.log("update otp Res in tempSendOtp ", updateRes);
} else {
const otpClass = Parse.Object.extend('defaultdata_Otp');
@@ -49,17 +52,17 @@ async function sendMailOTPv1(request) {
newOtpQuery.set('OTP', code);
newOtpQuery.set('Email', email);
newOtpQuery.set('TenantId', TenantId);
const newRes = await newOtpQuery.save(null, { useMasterKey: true });
await newOtpQuery.save(null, { useMasterKey: true });
// console.log("new otp Res in tempSendOtp ", newRes);
}
return 'Otp send';
} else {
return Promise.reject('Please Enter valid email');
return 'Please Enter valid email';
}
} catch (err) {
console.log('err in sendMailOTPv1');
console.log(err);
return Promise.reject(err);
return err;
}
}
export default sendMailOTPv1;
@@ -1,27 +0,0 @@
async function SendMailv1(request) {
console.log('in SendMailv1');
try {
const recipient = request.params.email;
const otp = request.params.otp;
const res = await Parse.Cloud.sendEmail({
from: 'Test user' + ' <' + process.env.SMTP_ENABLE ? process.env.SMTP_USER_EMAIL : process.env.MAILGUN_SENDER + '>',
recipient: recipient,
subject: 'Your OpenSign™ OTP',
text: 'This email is a test.',
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 style='background-color:red;padding:2px;font-family:system-ui; background-color:#47a3ad;'> <p style='font-size:20px;font-weight:400;color:white;padding-left:20px',>OTP Verification</p></div><div style='padding:20px'><p style='font-family:system-ui;font-size:14px'>Your OTP for OpenSign™ verification is:</p><p style=' text-decoration: none; font-weight: bolder; color:blue;font-size:45px;margin:20px'>" +
otp +
'</p></div> </div> </div></body></html>',
// "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /></head><body style='text-align: center;'><div style='display:flex;flex-direction:column;justify-content:center;align-item:center;margin:40px'> <p style='font-weight: bolder; font-size: large;'>Hello,</p> <span>Your OTP for LegaDaft verification . </span> <p style=' text-decoration: none; font-weight: bolder; color:blue;font-size:45px'>76984</p><span>Thank You!</span> </div> </body></html>"
});
console.log('Res');
console.log(res);
return otp;
} catch (err) {
console.log('err in SendMailv1');
console.log(err);
return err;
}
}
export default SendMailv1;
+32 -29
View File
@@ -48,10 +48,12 @@ async function sendCompletedMail(e) {
var a = e.url,
t = e.sender,
s = e.pdfName,
a = {
r = e.receiver,
e = {
extUserId: e.extUserId,
url: a,
from: 'OpenSign™',
recipient: e.receiver,
recipient: r,
subject: `Document ${s} has been signed by all parties`,
pdfName: s,
html:
@@ -61,7 +63,7 @@ async function sendCompletedMail(e) {
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, {
await axios.post(serverUrl + '/functions/sendmailv3', e, {
headers: {
'Content-Type': 'application/json',
'X-Parse-Application-Id': APPID,
@@ -206,11 +208,11 @@ async function PDF(i) {
var P,
y,
v,
b,
U,
b,
I,
S = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
A = './exports/' + S;
x = './exports/' + S;
let s = e.length;
s = (
t
@@ -226,51 +228,52 @@ async function PDF(i) {
}),
(v = await y.save()),
Buffer.from(v))
: ((b = await PDFDocument.load(e)),
: ((U = await PDFDocument.load(e)),
pdflibAddPlaceholder({
pdfDoc: b,
pdfDoc: U,
reason: 'Digitally signed by OpenSign for ' + p + ' <' + m + '>',
location: 'location',
signatureLength: 15e3,
}),
(U = await b.save()),
Buffer.from(U))),
(b = await U.save()),
Buffer.from(b))),
(I = await new SignPDF(e, u).signPDF()),
fs.writeFileSync(A, I),
fs.writeFileSync(x, I),
I)
: (fs.writeFileSync(A, e), e)
: (fs.writeFileSync(x, e), e)
).length;
var w,
D,
x = await uploadFile(S, A);
if (x && x.imageUrl)
var A,
w,
D = await uploadFile(S, x);
if (D && D.imageUrl)
return (
(w = await updateDoc(
(A = await updateDoc(
i.params.docId,
x.imageUrl,
D.imageUrl,
r.data.results[0].objectId,
i.headers['x-real-ip'],
n.data,
o
)),
sendDoctoWebhook(n, x.imageUrl, 'signed', r?.data.results?.[0]),
saveFileUsage(s, x.imageUrl, d.data.objectId),
w &&
w.isCompleted &&
((D = {
url: x.imageUrl,
sendDoctoWebhook(n, D.imageUrl, 'signed', r?.data.results?.[0]),
saveFileUsage(s, D.imageUrl, d.data.objectId),
A &&
A.isCompleted &&
((w = {
url: D.imageUrl,
sender: { Mail: n.data.ExtUserPtr.Email, Name: 'OpenSign™' },
pdfName: n.data.Name,
receiver: n.data.ExtUserPtr.Email,
extUserId: n.data.ExtUserPtr.objectId,
}),
n.data.IsSendMail && !1 === n.data.IsSendMail
? console.log("don't send mail")
: sendCompletedMail(D),
sendDoctoWebhook(n, x.imageUrl, 'completed')),
fs.unlinkSync(A),
console.log('New Signed PDF created called: ' + A),
'success' === w.message
? { status: 'success', data: x.imageUrl }
: sendCompletedMail(w),
sendDoctoWebhook(n, D.imageUrl, 'completed')),
fs.unlinkSync(x),
console.log('New Signed PDF created called: ' + x),
'success' === A.message
? { status: 'success', data: D.imageUrl }
: { status: 'error', message: 'please provide required parameters!' }
);
}
@@ -3,8 +3,9 @@ import https from 'https';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
import { createTransport } from 'nodemailer';
import { updateMailCount } from '../../Utils.js';
async function sendmail(req) {
async function sendmailv3(req) {
try {
let transporterSMTP;
let mailgunClient;
@@ -77,6 +78,9 @@ async function sendmail(req) {
const res = await transporterSMTP.sendMail(messageParams);
console.log('Res ', res);
if (!res.err) {
if (req.params?.extUserId) {
await updateMailCount(req.params.extUserId);
}
return {
status: 'success',
};
@@ -85,6 +89,9 @@ async function sendmail(req) {
const res = await mailgunClient.messages.create(mailgunDomain, messageParams);
console.log('Res ', res);
if (res.status === 200) {
if (req.params?.extUserId) {
await updateMailCount(req.params.extUserId);
}
return {
status: 'success',
};
@@ -109,6 +116,9 @@ async function sendmail(req) {
const res = await transporterSMTP.sendMail(messageParams);
console.log('Res ', res);
if (!res.err) {
if (req.params?.extUserId) {
await updateMailCount(req.params.extUserId);
}
return {
status: 'success',
};
@@ -117,6 +127,9 @@ async function sendmail(req) {
const res = await mailgunClient.messages.create(mailgunDomain, messageParams);
console.log('Res ', res);
if (res.status === 200) {
if (req.params?.extUserId) {
await updateMailCount(req.params.extUserId);
}
return {
status: 'success',
};
@@ -124,11 +137,11 @@ async function sendmail(req) {
}
}
} catch (err) {
console.log('err ', err);
console.log('err in sendmailv3', err);
if (err) {
return { status: 'error' };
}
}
}
export default sendmail;
export default sendmailv3;