lrf преди 1 месец
родител
ревизия
d7da73e82f
променени са 5 файла, в които са добавени 62 реда и са изтрити 1 реда
  1. 14 0
      package-lock.json
  2. 1 0
      package.json
  3. 13 1
      src/config/config.default.ts
  4. 4 0
      src/service/login.service.ts
  5. 30 0
      src/service/thirdParty/email.service.ts

+ 14 - 0
package-lock.json

@@ -30,6 +30,7 @@
         "dayjs": "^1.11.11",
         "exceljs": "^4.4.0",
         "lodash": "^4.17.21",
+        "nodemailer": "^6.9.15",
         "pg": "^8.11.5",
         "typeorm": "^0.3.20"
       },
@@ -7229,6 +7230,14 @@
       "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
       "dev": true
     },
+    "node_modules/nodemailer": {
+      "version": "6.9.15",
+      "resolved": "https://registry.npmmirror.com/nodemailer/-/nodemailer-6.9.15.tgz",
+      "integrity": "sha512-AHf04ySLC6CIfuRtRiEYtGEXgRfa6INgWGluDhnxTZhHSKvrBu7lc1VVchQ0d8nPc4cFaZoPq8vkyNoZr0TpGQ==",
+      "engines": {
+        "node": ">=6.0.0"
+      }
+    },
     "node_modules/normalize-package-data": {
       "version": "3.0.3",
       "resolved": "https://registry.npmmirror.com/normalize-package-data/-/normalize-package-data-3.0.3.tgz",
@@ -15385,6 +15394,11 @@
       "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
       "dev": true
     },
+    "nodemailer": {
+      "version": "6.9.15",
+      "resolved": "https://registry.npmmirror.com/nodemailer/-/nodemailer-6.9.15.tgz",
+      "integrity": "sha512-AHf04ySLC6CIfuRtRiEYtGEXgRfa6INgWGluDhnxTZhHSKvrBu7lc1VVchQ0d8nPc4cFaZoPq8vkyNoZr0TpGQ=="
+    },
     "normalize-package-data": {
       "version": "3.0.3",
       "resolved": "https://registry.npmmirror.com/normalize-package-data/-/normalize-package-data-3.0.3.tgz",

+ 1 - 0
package.json

@@ -25,6 +25,7 @@
     "dayjs": "^1.11.11",
     "exceljs": "^4.4.0",
     "lodash": "^4.17.21",
+    "nodemailer": "^6.9.15",
     "pg": "^8.11.5",
     "typeorm": "^0.3.20"
   },

+ 13 - 1
src/config/config.default.ts

@@ -22,11 +22,23 @@ export default {
   },
   showDBSub: false,
   loginSmsSign: 'LoginSmsSign',
-  pwdSmsSign:'PasswordSmsSign',
+  pwdSmsSign: 'PasswordSmsSign',
   aliyunSms: {
     template: 'SMS_275370127', //模板code
     sign: '吉林省华欣数字科技股份', //签名
     AccessKey_ID: 'LTAI5tDGzajxW6oDiTBvKB53',
     AccessKey_Secret: 'woGAW31X6PuzaE2O1fawwFCxfWMsfw',
   },
+  email: {
+    config: {
+      host: 'smtp.163.com',
+      port: 465,
+      secure: true,
+      auth: {
+        user: 'myhope1977@163.com', // 邮箱账号
+        pass: 'RZGYKLOQUTRCNLEO', // 邮箱stmp授权码
+      },
+    },
+    from: '福瑞科技', // 发件人名称
+  },
 } as MidwayConfig;

+ 4 - 0
src/service/login.service.ts

@@ -12,6 +12,7 @@ import { Admin } from '../entity/system/admin.entity';
 import * as bcrypt from 'bcryptjs';
 import { User } from '../entity/system/user.entity';
 import { AliyunSmsService } from './thirdParty/aliyunSms.service';
+import { EmailService } from './thirdParty/email.service';
 
 @Provide()
 export class LoginService {
@@ -37,6 +38,8 @@ export class LoginService {
 
   @Inject()
   smsService: AliyunSmsService;
+  @Inject()
+  emailService: EmailService;
 
   @InjectEntityModel(Admin)
   adminModel: Repository<Admin>;
@@ -69,6 +72,7 @@ export class LoginService {
     await this.redisService.set(redisKey, code, 'EX', this.timeLimit);
     if (type === 'email') {
       // TODO: 发邮箱
+      await this.emailService.sendPwdCode(to, code);
     } else if (type === 'phone') {
       // 发短信
       await this.smsService.send(to, code);

+ 30 - 0
src/service/thirdParty/email.service.ts

@@ -0,0 +1,30 @@
+import { Config, Init, Provide } from '@midwayjs/core';
+import * as nodemailer from 'nodemailer';
+@Provide()
+export class EmailService {
+  @Config('email')
+  emailSetting;
+
+  client;
+  @Init()
+  init() {
+    const config = this.emailSetting.config;
+    this.client = nodemailer.createTransport(config);
+  }
+
+  sendPwdCode(email, code) {
+    const sender = this.emailSetting.from;
+    const senderEmail = this.emailSetting.config.auth.user;
+    const text = `[${sender}] 您的验证码为: ${code}, 请勿泄露于他人!`;
+    const mailContext = {
+      from: `"${sender}" <${senderEmail}>`,
+      to: email,
+      subject: `找回密码`,
+      text,
+    };
+    this.client.sendMail(mailContext, (error, info) => {
+      // if (error) console.log(error);
+      // else console.log(info);
+    });
+  }
+}