new system for creating campaigns from the main site dashboard
This commit is contained in:
@@ -386,6 +386,29 @@ class EmailService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async sendEmailVerification(recipientEmail, verificationUrl, userName) {
|
||||
try {
|
||||
const templateVariables = {
|
||||
USER_NAME: userName || 'there',
|
||||
VERIFICATION_URL: verificationUrl
|
||||
};
|
||||
|
||||
const emailOptions = {
|
||||
to: recipientEmail,
|
||||
from: {
|
||||
email: process.env.SMTP_FROM_EMAIL,
|
||||
name: process.env.SMTP_FROM_NAME
|
||||
},
|
||||
subject: 'Verify Your Email to Create Your Campaign'
|
||||
};
|
||||
|
||||
return await this.sendTemplatedEmail('email-verification', templateVariables, emailOptions);
|
||||
} catch (error) {
|
||||
console.error('Failed to send email verification:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new EmailService();
|
||||
@@ -28,7 +28,8 @@ class NocoDBService {
|
||||
users: process.env.NOCODB_TABLE_USERS,
|
||||
calls: process.env.NOCODB_TABLE_CALLS,
|
||||
representativeResponses: process.env.NOCODB_TABLE_REPRESENTATIVE_RESPONSES,
|
||||
responseUpvotes: process.env.NOCODB_TABLE_RESPONSE_UPVOTES
|
||||
responseUpvotes: process.env.NOCODB_TABLE_RESPONSE_UPVOTES,
|
||||
emailVerifications: process.env.NOCODB_TABLE_EMAIL_VERIFICATIONS
|
||||
};
|
||||
|
||||
// Validate that all table IDs are set
|
||||
@@ -877,6 +878,83 @@ class NocoDBService {
|
||||
created_at: data.CreatedAt || data.created_at
|
||||
};
|
||||
}
|
||||
|
||||
// Email verification methods
|
||||
async createEmailVerification(verificationData) {
|
||||
if (!this.tableIds.emailVerifications) {
|
||||
throw new Error('Email verifications table not configured');
|
||||
}
|
||||
|
||||
const data = {
|
||||
'Token': verificationData.token,
|
||||
'Email': verificationData.email,
|
||||
'Temp Campaign Data': verificationData.temp_campaign_data,
|
||||
'Created At': verificationData.created_at,
|
||||
'Expires At': verificationData.expires_at,
|
||||
'Used': verificationData.used || false
|
||||
};
|
||||
|
||||
return await this.create(this.tableIds.emailVerifications, data);
|
||||
}
|
||||
|
||||
async getEmailVerificationByToken(token) {
|
||||
if (!this.tableIds.emailVerifications) {
|
||||
throw new Error('Email verifications table not configured');
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await this.getAll(this.tableIds.emailVerifications, {
|
||||
where: `(Token,eq,${token})`,
|
||||
limit: 1
|
||||
});
|
||||
|
||||
return response.list?.[0] || null;
|
||||
} catch (error) {
|
||||
console.error('Error in getEmailVerificationByToken:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async updateEmailVerification(verificationId, updateData) {
|
||||
if (!this.tableIds.emailVerifications) {
|
||||
throw new Error('Email verifications table not configured');
|
||||
}
|
||||
|
||||
const data = {};
|
||||
if (updateData.used !== undefined) {
|
||||
data['Used'] = updateData.used;
|
||||
}
|
||||
|
||||
return await this.update(this.tableIds.emailVerifications, verificationId, data);
|
||||
}
|
||||
|
||||
async deleteExpiredEmailVerifications() {
|
||||
if (!this.tableIds.emailVerifications) {
|
||||
throw new Error('Email verifications table not configured');
|
||||
}
|
||||
|
||||
try {
|
||||
const now = new Date().toISOString();
|
||||
const response = await this.getAll(this.tableIds.emailVerifications, {
|
||||
where: `(Expires At,lt,${now})`
|
||||
});
|
||||
|
||||
if (response.list && response.list.length > 0) {
|
||||
for (const verification of response.list) {
|
||||
const id = verification.ID || verification.Id || verification.id;
|
||||
if (id) {
|
||||
await this.client.delete(`${this.getTableUrl(this.tableIds.emailVerifications)}/${id}`);
|
||||
}
|
||||
}
|
||||
return { success: true, deletedCount: response.list.length };
|
||||
}
|
||||
|
||||
return { success: true, deletedCount: 0 };
|
||||
} catch (error) {
|
||||
console.error('Error deleting expired email verifications:', error.message);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new NocoDBService();
|
||||
|
||||
Reference in New Issue
Block a user