Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. email.service.ts
  2.  
  3. import { SendMailOptions } from 'nodemailer';
  4.  
  5. export interface IEmailService {
  6.   [name: string]: (options: SendMailOptions, templateOptions: object) => Promise<any>;
  7. }
  8.  
  9. export const IEmailService = Symbol('IEmailService');
  10. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  11.  
  12. public async register(name: string, email: string, password: string): Promise<boolean> {
  13.     const user = await this.userMapper.findOne({ email });
  14.     const role = await this.roleMapper.findOne({ name: 'user' });
  15.  
  16.     if (user) {
  17.       return false; // already exists
  18.     }
  19.  
  20.     const passwordHash = await hash(password, 10);
  21.     const code = randomBytes(4).toString('hex');
  22.  
  23.     const newUser = new this.userMapper({
  24.       activationCode: code,
  25.       active: false,
  26.       email,
  27.       name,
  28.       password: passwordHash,
  29.       role: role.id
  30.     });
  31.  
  32.     await newUser.save();
  33.     await this.emailService.activate({ to: newUser.email }, { name: newUser.name, code: newUser.activationCode });
  34.     return true;
  35.   }
  36.  
  37. functia this.emailService.activate arunca un html
  38. <!DOCTYPE html>
  39. <html>
  40.  
  41. <head>
  42.   <meta charset="UTF-8">
  43.   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  44.   <meta name="viewport" content="width=device-width,initial-scale=1">
  45.   <title>title</title>
  46.   <meta name="author" content="name">
  47.   <meta name="description" content="description here">
  48.   <meta name="keywords" content="keywords,here">
  49. </head>
  50.  
  51. <body>
  52.   Name: {{name}}
  53.   <p/> Code: {{code}}
  54. </body>
  55.  
  56. </html>
  57.  
  58. PE CARE EU IL VAD IN LOGS ITI DAU UN Print screen pe mess
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement