Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- email.service.ts
- import { SendMailOptions } from 'nodemailer';
- export interface IEmailService {
- [name: string]: (options: SendMailOptions, templateOptions: object) => Promise<any>;
- }
- export const IEmailService = Symbol('IEmailService');
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
- public async register(name: string, email: string, password: string): Promise<boolean> {
- const user = await this.userMapper.findOne({ email });
- const role = await this.roleMapper.findOne({ name: 'user' });
- if (user) {
- return false; // already exists
- }
- const passwordHash = await hash(password, 10);
- const code = randomBytes(4).toString('hex');
- const newUser = new this.userMapper({
- activationCode: code,
- active: false,
- email,
- name,
- password: passwordHash,
- role: role.id
- });
- await newUser.save();
- await this.emailService.activate({ to: newUser.email }, { name: newUser.name, code: newUser.activationCode });
- return true;
- }
- functia this.emailService.activate arunca un html
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <title>title</title>
- <meta name="author" content="name">
- <meta name="description" content="description here">
- <meta name="keywords" content="keywords,here">
- </head>
- <body>
- Name: {{name}}
- <p/> Code: {{code}}
- </body>
- </html>
- PE CARE EU IL VAD IN LOGS ITI DAU UN Print screen pe mess
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement