contact form working
This commit is contained in:
1 parent
609475271e
commit
847ed031db
6 files changed
+176
-124
No files matched your search
@@ -17,3 +17,4 @@ SMTP_USER=mailer@imk.mk
|
||||
SMTP_PASSWORD=76Avtostoperski76
|
||||
SMTP_FROM=mailer@imk.mk
|
||||
FRONTEND_URL=https://imk.mk
|
||||
ADMIN_EMAIL=petrovskidimitar@yandex.com
|
||||
@@ -49,7 +49,7 @@ export class AdminService {
|
||||
data: {
|
||||
...createUserDto,
|
||||
password: hashedPassword,
|
||||
isAdmin: true,
|
||||
isAdmin: createUserDto.isAdmin,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -97,6 +97,7 @@ export class AdminService {
|
||||
document.title,
|
||||
document.uploadedBy.name,
|
||||
);
|
||||
console.log('Document shared with user:', sharedWithUser.email);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { Controller, Post, Body } from '@nestjs/common';
|
||||
import { EmailService } from './email.service';
|
||||
import { MailerService } from '@nestjs-modules/mailer';
|
||||
// import { MailerService } from '@nestjs-modules/mailer';
|
||||
class ContactFormDto {
|
||||
name: string;
|
||||
email: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
@Controller('contact')
|
||||
@Controller('email')
|
||||
export class EmailController {
|
||||
constructor(private emailService: MailerService) {}
|
||||
constructor(private emailService: EmailService) {}
|
||||
|
||||
@Post()
|
||||
async sendContactEmail(@Body() contactData: {
|
||||
@@ -12,17 +17,20 @@ export class EmailController {
|
||||
email: string;
|
||||
message: string;
|
||||
}) {
|
||||
await this.emailService.sendMail({
|
||||
to: process.env.CONTACT_EMAIL,
|
||||
subject: `Contact Form: ${contactData.name}`,
|
||||
html: `
|
||||
<h1>New Contact Form Submission</h1>
|
||||
<p><strong>From:</strong> ${contactData.name}</p>
|
||||
<p><strong>Email:</strong> ${contactData.email}</p>
|
||||
<p><strong>Message:</strong></p>
|
||||
<p>${contactData.message}</p>
|
||||
`,
|
||||
});
|
||||
await this.emailService.sendContactEmail(
|
||||
contactData.name,
|
||||
contactData.email,
|
||||
contactData.message
|
||||
);
|
||||
return { message: 'Contact form submitted successfully' };
|
||||
}
|
||||
@Post('contact')
|
||||
async handleContactForm(@Body() contactData: ContactFormDto) {
|
||||
await this.emailService.sendContactEmail(
|
||||
contactData.name,
|
||||
contactData.email,
|
||||
contactData.message
|
||||
);
|
||||
return { message: 'Thank you for your message. We will contact you soon.' };
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
|
||||
import { MailerModule } from '@nestjs-modules/mailer';
|
||||
import { EmailService } from './email.service';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { EmailController } from './email.controller';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -24,6 +25,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
],
|
||||
controllers: [EmailController],
|
||||
providers: [EmailService],
|
||||
exports: [EmailService],
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, Post, Body } from '@nestjs/common';
|
||||
import { MailerService } from '@nestjs-modules/mailer';
|
||||
|
||||
@Injectable()
|
||||
@@ -13,7 +13,10 @@ export class EmailService {
|
||||
<h1>Welcome ${name}!</h1>
|
||||
<p>Your account has been created successfully.</p>
|
||||
<p>You can now login to access your documents.</p>
|
||||
<p>Please use the following link to reset your password: </p>
|
||||
<p>Best regards,<br>IMK Team</p>
|
||||
`,
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,4 +45,30 @@ export class EmailService {
|
||||
`,
|
||||
});
|
||||
}
|
||||
}
|
||||
async sendContactEmail(name: string, email: string, message: string) {
|
||||
// Send to admin
|
||||
await this.mailerService.sendMail({
|
||||
to: process.env.ADMIN_EMAIL,
|
||||
subject: `New Contact Form Submission from ${name}`,
|
||||
html: `
|
||||
<h2>New Contact Form Submission</h2>
|
||||
<p><strong>From:</strong> ${name}</p>
|
||||
<p><strong>Email:</strong> ${email}</p>
|
||||
<p><strong>Message:</strong></p>
|
||||
<p>${message}</p>
|
||||
`,
|
||||
});
|
||||
await this.mailerService.sendMail({
|
||||
to: email,
|
||||
subject: 'Thank you for contacting us',
|
||||
html: `
|
||||
<h2>Thank you for contacting us</h2>
|
||||
<p>Dear ${name},</p>
|
||||
<p>We have received your message and will get back to you soon.</p>
|
||||
<p>Your message:</p>
|
||||
<blockquote>${message}</blockquote>
|
||||
<p>Best regards,<br>IMK Team</p>
|
||||
`,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user