Browse Source

密码不加密;用户忘记密码

lrf 3 weeks ago
parent
commit
76d718cc70

+ 9 - 9
src/controller/system/admin.controller.ts

@@ -10,8 +10,8 @@ import {
 import { AdminService } from '../../service/system/admin.service';
 import { AdminService } from '../../service/system/admin.service';
 import { RF } from '../../response/CustomerResponse';
 import { RF } from '../../response/CustomerResponse';
 import { Page, Query } from '../../decorator/page.decorator';
 import { Page, Query } from '../../decorator/page.decorator';
-import * as bcrypt from 'bcryptjs';
-import { get } from 'lodash';
+// import * as bcrypt from 'bcryptjs';
+// import { get } from 'lodash';
 
 
 @Controller('/admin')
 @Controller('/admin')
 export class AdminController {
 export class AdminController {
@@ -21,13 +21,13 @@ export class AdminController {
   @Post('/')
   @Post('/')
   async create(@Body() body) {
   async create(@Body() body) {
     await this.service.checkInDB(body);
     await this.service.checkInDB(body);
-    // 处理密码
-    const passowrd = get(body, 'password');
-    if (passowrd) {
-      const salt = bcrypt.genSaltSync(10);
-      const hash = bcrypt.hashSync(passowrd, salt);
-      Object.assign(body, { password: hash });
-    }
+    // 处理密码,不加密
+    // const passowrd = get(body, 'password');
+    // if (passowrd) {
+    //   const salt = bcrypt.genSaltSync(10);
+    //   const hash = bcrypt.hashSync(passowrd, salt);
+    //   Object.assign(body, { password: hash });
+    // }
     const data = await this.service.create(body);
     const data = await this.service.create(body);
     return RF.success(data);
     return RF.success(data);
   }
   }

+ 9 - 9
src/controller/system/user.controller.ts

@@ -10,8 +10,8 @@ import {
 import { UserService } from '../../service/system/user.service';
 import { UserService } from '../../service/system/user.service';
 import { RF } from '../../response/CustomerResponse';
 import { RF } from '../../response/CustomerResponse';
 import { Page, Query } from '../../decorator/page.decorator';
 import { Page, Query } from '../../decorator/page.decorator';
-import { get } from 'lodash';
-import * as bcrypt from 'bcryptjs';
+// import { get } from 'lodash';
+// import * as bcrypt from 'bcryptjs';
 
 
 @Controller('/user')
 @Controller('/user')
 export class UserController {
 export class UserController {
@@ -21,13 +21,13 @@ export class UserController {
   @Post('/')
   @Post('/')
   async create(@Body() body) {
   async create(@Body() body) {
     await this.service.checkInDB(body);
     await this.service.checkInDB(body);
-    // 处理密码
-    const passowrd = get(body, 'password');
-    if (passowrd) {
-      const salt = bcrypt.genSaltSync(10);
-      const hash = bcrypt.hashSync(passowrd, salt);
-      Object.assign(body, { password: hash });
-    }
+    // 处理密码,不加密
+    // const passowrd = get(body, 'password');
+    // if (passowrd) {
+    //   const salt = bcrypt.genSaltSync(10);
+    //   const hash = bcrypt.hashSync(passowrd, salt);
+    //   Object.assign(body, { password: hash });
+    // }
     const data = await this.service.create(body);
     const data = await this.service.create(body);
     return RF.success(data);
     return RF.success(data);
   }
   }

+ 17 - 2
src/service/frame/Login.service.ts

@@ -18,6 +18,17 @@ export class LoginService {
   adminModel: Repository<Admin>;
   adminModel: Repository<Admin>;
   @InjectEntityModel(User)
   @InjectEntityModel(User)
   userModel: Repository<User>;
   userModel: Repository<User>;
+
+  /**
+   * 用户忘记密码
+   * @param data 账号和新密码
+   */
+  async forgetPwd(data) {
+    // TODO: 需要验证手机验证码
+    const username = get(data, 'username')
+    const password = get(data, 'password')
+    return await this.userModel.update({ username }, { password })
+  }
   /**
   /**
    * 账密登录
    * 账密登录
    * @param data 用户名和密码
    * @param data 用户名和密码
@@ -31,7 +42,9 @@ export class LoginService {
     const user = await model.createQueryBuilder('t').where('t.account = :account', { account: data.account }).addSelect('t.password').getOne();
     const user = await model.createQueryBuilder('t').where('t.account = :account', { account: data.account }).addSelect('t.password').getOne();
     if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND);
     if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND);
     await this.checkAccountCanLogin(user, type);
     await this.checkAccountCanLogin(user, type);
-    const result = bcrypt.compareSync(data.password, user.password);
+    // 密码不加密,不需要处理
+    // const result = bcrypt.compareSync(data.password, user.password);
+    const result = data.password === user.password
     if (!result) throw new ServiceError(ErrorCode.BAD_PASSWORD);
     if (!result) throw new ServiceError(ErrorCode.BAD_PASSWORD);
     return user;
     return user;
   }
   }
@@ -40,7 +53,9 @@ export class LoginService {
     const user = await this.adminModel.createQueryBuilder('t').where('t.account = :account', { account: data.account }).addSelect('t.password').getOne();
     const user = await this.adminModel.createQueryBuilder('t').where('t.account = :account', { account: data.account }).addSelect('t.password').getOne();
     if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND);
     if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND);
     await this.checkAccountCanLogin(user, LoginType.Admin);
     await this.checkAccountCanLogin(user, LoginType.Admin);
-    const result = bcrypt.compareSync(data.password, user.password);
+    // 密码不加密,不需要处理
+    // const result = bcrypt.compareSync(data.password, user.password);
+    const result = data.password === user.password
     if (!result) throw new ServiceError(ErrorCode.BAD_PASSWORD);
     if (!result) throw new ServiceError(ErrorCode.BAD_PASSWORD);
     return user;
     return user;
   }
   }