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 { ProjectModel } from "@schema/ProjectSchema";
|
||||||
import { UserModel } from "@schema/UserSchema";
|
import { UserModel } from "@schema/UserSchema";
|
||||||
import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema";
|
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) {
|
export async function checkLimitsForEmail(projectCounts: TProjectCount) {
|
||||||
|
|
||||||
@@ -13,7 +22,7 @@ export async function checkLimitsForEmail(projectCounts: TProjectCount) {
|
|||||||
if (!project) return;
|
if (!project) return;
|
||||||
const owner = await UserModel.findById(project.owner);
|
const owner = await UserModel.findById(project.owner);
|
||||||
if (!owner) return;
|
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 });
|
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_ORG: process.env.AI_ORG,
|
||||||
AI_PROJECT: process.env.AI_PROJECT,
|
AI_PROJECT: process.env.AI_PROJECT,
|
||||||
AI_KEY: process.env.AI_KEY,
|
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,
|
AUTH_JWT_SECRET: process.env.AUTH_JWT_SECRET,
|
||||||
GOOGLE_AUTH_CLIENT_ID: process.env.GOOGLE_AUTH_CLIENT_ID,
|
GOOGLE_AUTH_CLIENT_ID: process.env.GOOGLE_AUTH_CLIENT_ID,
|
||||||
GOOGLE_AUTH_CLIENT_SECRET: process.env.GOOGLE_AUTH_CLIENT_SECRET,
|
GOOGLE_AUTH_CLIENT_SECRET: process.env.GOOGLE_AUTH_CLIENT_SECRET,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { OAuth2Client } from 'google-auth-library';
|
import { OAuth2Client } from 'google-auth-library';
|
||||||
import { createUserJwt } from '~/server/AuthManager';
|
import { createUserJwt } from '~/server/AuthManager';
|
||||||
import { UserModel } from '@schema/UserSchema';
|
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()
|
const { GOOGLE_AUTH_CLIENT_SECRET, GOOGLE_AUTH_CLIENT_ID } = useRuntimeConfig()
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ export default defineEventHandler(async event => {
|
|||||||
const savedUser = await newUser.save();
|
const savedUser = await newUser.save();
|
||||||
|
|
||||||
setImmediate(() => {
|
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 }) }
|
return { error: false, access_token: createUserJwt({ email: savedUser.email, name: savedUser.name }) }
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { Redis } from "~/server/services/CacheService";
|
import { Redis } from "~/server/services/CacheService";
|
||||||
|
import EmailService from '@services/EmailService';
|
||||||
|
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
let connection: mongoose.Mongoose;
|
let connection: mongoose.Mongoose;
|
||||||
|
|
||||||
@@ -7,6 +9,14 @@ export default async () => {
|
|||||||
|
|
||||||
console.log('[SERVER] Initializing');
|
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) {
|
if (!connection || connection.connection.readyState == mongoose.ConnectionStates.disconnected) {
|
||||||
console.log('[DATABASE] Connecting');
|
console.log('[DATABASE] Connecting');
|
||||||
connection = await mongoose.connect(config.MONGO_CONNECTION_STRING);
|
connection = await mongoose.connect(config.MONGO_CONNECTION_STRING);
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
import nodemailer from 'nodemailer';
|
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 = `
|
const TemplateEmail50 = `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -228,9 +222,21 @@ const TemplateEmailWelcome = `
|
|||||||
</html>
|
</html>
|
||||||
`
|
`
|
||||||
|
|
||||||
export async function sendLimitEmail50(target: string) {
|
|
||||||
|
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 }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendLimitEmail50(target: string) {
|
||||||
try {
|
try {
|
||||||
await transport.sendMail({
|
if (!this.transport) return console.error('Transport not created');
|
||||||
|
await this.transport.sendMail({
|
||||||
from: 'helplitlyx@gmail.com',
|
from: 'helplitlyx@gmail.com',
|
||||||
to: target,
|
to: target,
|
||||||
subject: 'Project limit 50%',
|
subject: 'Project limit 50%',
|
||||||
@@ -241,11 +247,12 @@ export async function sendLimitEmail50(target: string) {
|
|||||||
console.error('ERROR SENDING EMAIL', ex);
|
console.error('ERROR SENDING EMAIL', ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendWelcomeEmail(target: string) {
|
async sendWelcomeEmail(target: string) {
|
||||||
try {
|
try {
|
||||||
await transport.sendMail({
|
if (!this.transport) return console.error('Transport not created');
|
||||||
|
await this.transport.sendMail({
|
||||||
from: 'helplitlyx@gmail.com',
|
from: 'helplitlyx@gmail.com',
|
||||||
to: target,
|
to: target,
|
||||||
subject: 'Welcome to Litlyx',
|
subject: 'Welcome to Litlyx',
|
||||||
@@ -256,4 +263,9 @@ export async function sendWelcomeEmail(target: string) {
|
|||||||
console.error('ERROR SENDING EMAIL', ex);
|
console.error('ERROR SENDING EMAIL', ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const instance = new EmailService();
|
||||||
|
export default instance;
|
||||||
Reference in New Issue
Block a user