- Added Blog and BlogPost models with necessary fields and relationships. - Created blogRouter for handling blog-related API endpoints including CRUD operations. - Developed BlogService for business logic related to blogs and posts, including sharing functionality. - Implemented API client methods for frontend to interact with blog-related endpoints. - Added internationalization support for blog-related text in English and German. - Created Vue components for blog editing, listing, and viewing, including a rich text editor for post content. - Enhanced user experience with form validations and dynamic visibility settings based on user input.
71 lines
2.3 KiB
JavaScript
71 lines
2.3 KiB
JavaScript
import nodemailer from 'nodemailer';
|
|
import i18n from '../utils/i18n.js';
|
|
import UserParamValue from '../models/type/user_param_value.js';
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
host: process.env.SMTP_HOST,
|
|
port: process.env.SMTP_PORT,
|
|
secure: process.env.SMTP_SECURE === 'true',
|
|
auth: {
|
|
user: process.env.SMTP_USER,
|
|
pass: process.env.SMTP_PASSWORD
|
|
}
|
|
});
|
|
|
|
export const sendPasswordResetEmail = async (email, resetLink, language) => {
|
|
i18n.setLocale(language);
|
|
const mailOptions = {
|
|
from: process.env.SMTP_FROM,
|
|
to: email,
|
|
subject: i18n.__('password_reset_subject'),
|
|
text: i18n.__('password_reset_text', { resetLink })
|
|
};
|
|
|
|
await transporter.sendMail(mailOptions);
|
|
};
|
|
|
|
export const sendAccountActivationEmail = async (email, activationLink, username, resetToken, languageId) => {
|
|
const languageObject = await UserParamValue.findOne({
|
|
where: {
|
|
id: languageId
|
|
}
|
|
});
|
|
const language = languageObject.value;
|
|
i18n.setLocale(language);
|
|
const mailOptions = {
|
|
from: process.env.SMTP_FROM,
|
|
to: email,
|
|
subject: i18n.__('account_activation_subject'),
|
|
text: i18n.__('account_activation_text', { activationLink, username, resetToken }),
|
|
html: i18n.__('account_activation_html', { username, activationLink, resetToken })
|
|
};
|
|
|
|
await transporter.sendMail(mailOptions);
|
|
};
|
|
|
|
export const sendAnswerEmail = async (toEmail, answer, language) => {
|
|
i18n.setLocale(language);
|
|
const mailOptions = {
|
|
from: process.env.SMTP_FROM,
|
|
to: toEmail,
|
|
subject: 'yourPart',
|
|
text: answer,
|
|
html: `<p>${ answer }</p>`
|
|
};
|
|
|
|
await transporter.sendMail(mailOptions);
|
|
};
|
|
|
|
export const sendBlogShareEmail = async (toEmail, blogUrl, blogTitle, senderName) => {
|
|
const subject = `yourPart: ${senderName} hat einen Blog geteilt`;
|
|
const text = `${senderName} hat den Blog "${blogTitle}" mit dir geteilt. Du kannst ihn hier ansehen: ${blogUrl}`;
|
|
const html = `<p><strong>${senderName}</strong> hat den Blog "${blogTitle}" mit dir geteilt.</p><p>Hier ansehen: <a href="${blogUrl}">${blogUrl}</a></p>`;
|
|
const mailOptions = {
|
|
from: process.env.SMTP_FROM,
|
|
to: toEmail,
|
|
subject,
|
|
text,
|
|
html
|
|
};
|
|
await transporter.sendMail(mailOptions);
|
|
}; |