mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-21 23:22:35 +02:00
feat: handle undefine username/password for SMTP
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
export default async function getSignature(request) {
|
||||
const { userId } = request.params;
|
||||
if (!userId) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Missing userId parameter.');
|
||||
}
|
||||
if (userId !== request.user?.id) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
|
||||
}
|
||||
try {
|
||||
const query = new Parse.Query('contracts_Signature');
|
||||
query.equalTo('UserId', { __type: 'Pointer', className: '_User', objectId: userId });
|
||||
const result = await query.first({ useMasterKey: true });
|
||||
return result;
|
||||
} catch (err) {
|
||||
console.error('Error fetching signature:', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
export default async function manageSign(request) {
|
||||
const { signature, userId, initials, id, title } = request.params;
|
||||
|
||||
if (!userId) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Missing userId parameter.');
|
||||
}
|
||||
if (userId !== request.user?.id) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
|
||||
}
|
||||
const userPtr = { __type: 'Pointer', className: '_User', objectId: userId };
|
||||
try {
|
||||
const signatureCls = new Parse.Object('contracts_Signature');
|
||||
if (id) {
|
||||
signatureCls.id = id;
|
||||
}
|
||||
signatureCls.set('Initials', initials ? initials : '');
|
||||
signatureCls.set('ImageURL', signature ? signature : '');
|
||||
signatureCls.set('SignatureName', title ? title : '');
|
||||
if (userPtr) {
|
||||
signatureCls.set('UserId', userPtr);
|
||||
}
|
||||
const signRes = await signatureCls.save(null, { useMasterKey: true });
|
||||
return signRes;
|
||||
} catch (err) {
|
||||
console.error('Error saving signature:', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
export default async function saveSignature(request) {
|
||||
const { signature, userId, initials, id, title } = request.params;
|
||||
|
||||
if (!userId) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Missing userId parameter.');
|
||||
}
|
||||
if (userId !== request.user?.id) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
|
||||
}
|
||||
const userPtr = { __type: 'Pointer', className: '_User', objectId: userId };
|
||||
try {
|
||||
const signatureCls = new Parse.Object('contracts_Signature');
|
||||
if (id) {
|
||||
signatureCls.id = id;
|
||||
}
|
||||
if (initials) {
|
||||
signatureCls.set('Initials', initials);
|
||||
}
|
||||
if (signature) {
|
||||
signatureCls.set('ImageURL', signature);
|
||||
}
|
||||
if (title) {
|
||||
signatureCls.set('SignatureName', title);
|
||||
}
|
||||
if (userPtr) {
|
||||
signatureCls.set('UserId', userPtr);
|
||||
}
|
||||
const signRes = await signatureCls.save(null, { useMasterKey: true });
|
||||
return signRes;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -12,15 +12,23 @@ async function sendMailProvider(req, plan, monthchange) {
|
||||
let mailgunClient;
|
||||
let mailgunDomain;
|
||||
if (smtpenable) {
|
||||
transporterSMTP = createTransport({
|
||||
let transporterConfig = {
|
||||
host: process.env.SMTP_HOST,
|
||||
port: process.env.SMTP_PORT || 465,
|
||||
secure: smtpsecure,
|
||||
auth: {
|
||||
};
|
||||
|
||||
// ✅ Add auth only if BOTH username & password exist
|
||||
const smtpUser = process.env.SMTP_USERNAME;
|
||||
const smtpPass = process.env.SMTP_PASS;
|
||||
|
||||
if (smtpUser && smtpPass) {
|
||||
transporterConfig.auth = {
|
||||
user: process.env.SMTP_USERNAME ? process.env.SMTP_USERNAME : process.env.SMTP_USER_EMAIL,
|
||||
pass: process.env.SMTP_PASS,
|
||||
},
|
||||
});
|
||||
pass: smtpPass,
|
||||
};
|
||||
}
|
||||
transporterSMTP = createTransport(transporterConfig);
|
||||
} else {
|
||||
if (mailgunApiKey) {
|
||||
const mailgun = new Mailgun(formData);
|
||||
@@ -185,7 +193,7 @@ async function sendMailProvider(req, plan, monthchange) {
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in sendmailv3', err);
|
||||
console.log(`Error in sendmailv3: ${err}`);
|
||||
if (fs.existsSync(testPdf)) {
|
||||
try {
|
||||
fs.unlinkSync(testPdf);
|
||||
@@ -236,7 +244,7 @@ async function sendMailProvider(req, plan, monthchange) {
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in sendmailv3', err);
|
||||
console.log(`Error in sendmailv3: ${err}`);
|
||||
if (err) {
|
||||
return { status: 'error' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user