-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
registration email, handlebars templates
- Loading branch information
Showing
20 changed files
with
340 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,8 @@ DATABASE_USER=test | |
DATABASE_PASSWORD=test | ||
|
||
JWT_SECRET=1i03RjH85jL4HTk1XHXmhwJjM-8ZfDxzOaN1Hnjx4XzDm0RcH6xmnGBlO | ||
|
||
SMTP_HOST=smtp.gmail.com | ||
SMTP_PORT=465 | ||
SMTP_USERNAME=[email protected] | ||
SMTP_PASSWORD=zvbquyhagnjchutw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
{ | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src" | ||
} | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"assets": [ | ||
"**/*.hbs" | ||
], | ||
"watchAssets": true | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface MailOptions { | ||
to: string; | ||
subject: string; | ||
template: string; | ||
templateParams?: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule, ConfigService } from '@nestjs/config'; | ||
import { NotificationService } from './services/notification.service'; | ||
import { MailService } from './services/mail.service'; | ||
|
||
@Module({ | ||
imports: [ConfigModule], | ||
providers: [NotificationService, MailService, ConfigService], | ||
exports: [NotificationService] | ||
}) | ||
export class NotificationModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { MailService } from './mail.service'; | ||
|
||
describe('MailService', () => { | ||
let service: MailService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [MailService], | ||
}).compile(); | ||
|
||
service = module.get<MailService>(MailService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
import * as nodemailer from 'nodemailer'; | ||
import Mail from 'nodemailer/lib/mailer'; | ||
import { SentMessageInfo } from 'nodemailer/lib/smtp-transport'; | ||
import { MailOptions } from '../interfaces/mail-options.interface'; | ||
import { readFileSync } from 'fs'; | ||
|
||
import { compile } from 'handlebars'; | ||
|
||
@Injectable() | ||
export class MailService { | ||
|
||
transporter: Mail; | ||
|
||
constructor(configService: ConfigService) { | ||
this.transporter = nodemailer.createTransport({ | ||
host: configService.get("SMTP_HOST"), | ||
port: configService.get("SMTP_PORT"), | ||
secure: true, | ||
auth: { | ||
user: configService.get("SMTP_USERNAME"), | ||
pass: configService.get("SMTP_PASSWORD"), | ||
}, | ||
}); | ||
} | ||
|
||
send(options: MailOptions): Promise<SentMessageInfo> { | ||
return this.transporter.sendMail({ | ||
from: '"Plezanje.net" <[email protected]>', | ||
to: options.to, | ||
subject: options.subject, | ||
text: this.render("plain", options.template, options.templateParams), | ||
html: this.render("html", options.template, options.templateParams) | ||
}) | ||
} | ||
|
||
render(type: string, templateName: string, params: any = {}): string { | ||
const template = compile( | ||
readFileSync(__dirname + '/../templates/' + templateName + '.' + type + '.hbs').toString() | ||
) | ||
|
||
if (type == "plain") { | ||
return template(params); | ||
} | ||
|
||
const layout = compile( | ||
readFileSync(__dirname + '/../templates/layout.html.hbs').toString() | ||
) | ||
|
||
return layout({ | ||
content: template(params) | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { NotificationService } from './notification.service'; | ||
|
||
describe('NotificationService', () => { | ||
let service: NotificationService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [NotificationService], | ||
}).compile(); | ||
|
||
service = module.get<NotificationService>(NotificationService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { User } from 'src/users/entities/user.entity'; | ||
import { MailService } from './mail.service'; | ||
|
||
@Injectable() | ||
export class NotificationService { | ||
constructor(private readonly mailService: MailService) { } | ||
|
||
public accountConfirmation(user: User): void { | ||
this.mailService.send({ | ||
to: user.email, | ||
subject: 'Aktivacija računa', | ||
template: 'account-confirmation', | ||
templateParams: { | ||
user: user | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<h1>Aktivacija uporabniškega računa</h1> | ||
|
||
<p> | ||
Na portalu plezanje.net ste | ||
ustvarili nov račun, ki ga je pred uporabo | ||
potrebno še aktivirati. | ||
</p> | ||
<p> | ||
To naredite s klikom na spodnjo povezavo: | ||
</p> | ||
<p> | ||
<a | ||
href="http://localhost:4200/aktivacija/{{ user.id }}/{{ user.confirmationToken }}">https://www.plezanje.net/aktivacija/{{ user.id }}/{{ user.confirmationToken }}</a> | ||
</p> |
Oops, something went wrong.