mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
fix email env
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
steps
|
||||
@@ -2,7 +2,16 @@ import { TProjectCount } from "@schema/ProjectsCounts";
|
||||
import { ProjectModel } from "@schema/ProjectSchema";
|
||||
import { UserModel } from "@schema/UserSchema";
|
||||
import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema";
|
||||
import { sendLimitEmail50 } from '@services/EmailService';
|
||||
import EmailService from '@services/EmailService';
|
||||
import { requireEnv } from "../../shared/utilts/requireEnv";
|
||||
|
||||
|
||||
EmailService.createTransport(
|
||||
requireEnv('EMAIL_SERVICE'),
|
||||
requireEnv('EMAIL_HOST'),
|
||||
requireEnv('EMAIL_USER'),
|
||||
requireEnv('EMAIL_PASS'),
|
||||
);
|
||||
|
||||
export async function checkLimitsForEmail(projectCounts: TProjectCount) {
|
||||
|
||||
@@ -13,7 +22,7 @@ export async function checkLimitsForEmail(projectCounts: TProjectCount) {
|
||||
if (!project) return;
|
||||
const owner = await UserModel.findById(project.owner);
|
||||
if (!owner) return;
|
||||
await sendLimitEmail50(owner.email);
|
||||
await EmailService.sendLimitEmail50(owner.email);
|
||||
await LimitNotifyModel.updateOne({ project_id: projectCounts._id }, { limit1: true, limit2: false, limit3: false }, { upsert: true });
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ export default defineNuxtConfig({
|
||||
AI_ORG: process.env.AI_ORG,
|
||||
AI_PROJECT: process.env.AI_PROJECT,
|
||||
AI_KEY: process.env.AI_KEY,
|
||||
EMAIL_SERVICE: process.env.EMAIL_SERVICE,
|
||||
EMAIL_HOST: process.env.EMAIL_HOST,
|
||||
EMAIL_USER: process.env.EMAIL_USER,
|
||||
EMAIL_PASS: process.env.EMAIL_PASS,
|
||||
AUTH_JWT_SECRET: process.env.AUTH_JWT_SECRET,
|
||||
GOOGLE_AUTH_CLIENT_ID: process.env.GOOGLE_AUTH_CLIENT_ID,
|
||||
GOOGLE_AUTH_CLIENT_SECRET: process.env.GOOGLE_AUTH_CLIENT_SECRET,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
import { createUserJwt } from '~/server/AuthManager';
|
||||
import { UserModel } from '@schema/UserSchema';
|
||||
import { sendWelcomeEmail } from '@services/EmailService';
|
||||
import EmailService from '@services/EmailService';
|
||||
|
||||
const { GOOGLE_AUTH_CLIENT_SECRET, GOOGLE_AUTH_CLIENT_ID } = useRuntimeConfig()
|
||||
|
||||
@@ -47,7 +47,7 @@ export default defineEventHandler(async event => {
|
||||
const savedUser = await newUser.save();
|
||||
|
||||
setImmediate(() => {
|
||||
if (payload.email) sendWelcomeEmail(payload.email);
|
||||
if (payload.email) EmailService.sendWelcomeEmail(payload.email);
|
||||
});
|
||||
|
||||
return { error: false, access_token: createUserJwt({ email: savedUser.email, name: savedUser.name }) }
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import mongoose from "mongoose";
|
||||
import { Redis } from "~/server/services/CacheService";
|
||||
import EmailService from '@services/EmailService';
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
let connection: mongoose.Mongoose;
|
||||
|
||||
@@ -7,6 +9,14 @@ export default async () => {
|
||||
|
||||
console.log('[SERVER] Initializing');
|
||||
|
||||
EmailService.createTransport(
|
||||
config.EMAIL_SERVICE,
|
||||
config.EMAIL_HOST,
|
||||
config.EMAIL_USER,
|
||||
config.EMAIL_PASS,
|
||||
);
|
||||
|
||||
|
||||
if (!connection || connection.connection.readyState == mongoose.ConnectionStates.disconnected) {
|
||||
console.log('[DATABASE] Connecting');
|
||||
connection = await mongoose.connect(config.MONGO_CONNECTION_STRING);
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
import { requireEnv } from '../utilts/requireEnv';
|
||||
import type SMTPTransport from 'nodemailer/lib/smtp-transport';
|
||||
|
||||
|
||||
|
||||
const transport = nodemailer.createTransport({
|
||||
service: requireEnv('EMAIL_SERVICE'),
|
||||
host: requireEnv('EMAIL_HOST'),
|
||||
auth: {
|
||||
user: requireEnv('EMAIL_USER'),
|
||||
pass: requireEnv('EMAIL_PASS')
|
||||
}
|
||||
});
|
||||
|
||||
const TemplateEmail50 = `
|
||||
<!DOCTYPE html>
|
||||
@@ -228,32 +222,50 @@ const TemplateEmailWelcome = `
|
||||
</html>
|
||||
`
|
||||
|
||||
export async function sendLimitEmail50(target: string) {
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from: 'helplitlyx@gmail.com',
|
||||
to: target,
|
||||
subject: 'Project limit 50%',
|
||||
html: TemplateEmail50
|
||||
|
||||
class EmailService {
|
||||
|
||||
private transport: nodemailer.Transporter<SMTPTransport.SentMessageInfo>;
|
||||
|
||||
createTransport(service: string, host: string, user: string, pass: string) {
|
||||
this.transport = nodemailer.createTransport({
|
||||
service, host, auth: { user, pass }
|
||||
});
|
||||
return true;
|
||||
} catch (ex) {
|
||||
console.error('ERROR SENDING EMAIL', ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
async sendLimitEmail50(target: string) {
|
||||
try {
|
||||
if (!this.transport) return console.error('Transport not created');
|
||||
await this.transport.sendMail({
|
||||
from: 'helplitlyx@gmail.com',
|
||||
to: target,
|
||||
subject: 'Project limit 50%',
|
||||
html: TemplateEmail50
|
||||
});
|
||||
return true;
|
||||
} catch (ex) {
|
||||
console.error('ERROR SENDING EMAIL', ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async sendWelcomeEmail(target: string) {
|
||||
try {
|
||||
if (!this.transport) return console.error('Transport not created');
|
||||
await this.transport.sendMail({
|
||||
from: 'helplitlyx@gmail.com',
|
||||
to: target,
|
||||
subject: 'Welcome to Litlyx',
|
||||
html: TemplateEmailWelcome
|
||||
});
|
||||
return true;
|
||||
} catch (ex) {
|
||||
console.error('ERROR SENDING EMAIL', ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function sendWelcomeEmail(target: string) {
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from: 'helplitlyx@gmail.com',
|
||||
to: target,
|
||||
subject: 'Welcome to Litlyx',
|
||||
html: TemplateEmailWelcome
|
||||
});
|
||||
return true;
|
||||
} catch (ex) {
|
||||
console.error('ERROR SENDING EMAIL', ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const instance = new EmailService();
|
||||
export default instance;
|
||||
Reference in New Issue
Block a user