瀏覽代碼

修改查询与登录错误

asd123a20 1 年之前
父節點
當前提交
c2779fd235
共有 2 個文件被更改,包括 7 次插入6 次删除
  1. 4 3
      service-cms/app/service/content.js
  2. 3 3
      service-login/app/controller/pwdlogin.js

+ 4 - 3
service-cms/app/service/content.js

@@ -100,11 +100,12 @@ class ContentService extends Service {
       throw error;
     }
   }
-  async search({ search }) {
+  async search({ search, skip, limit }) {
     try {
       const list = await this.model.find();
-      const res = list.filter(e => (e.content.includes(search) || e.title.includes(search)));
-      return { errcode: 0, errmsg: '', data: res };
+      const data = list.filter(e => (e.content.includes(search) || e.title.includes(search)));
+      const res = data.slice(Number(skip) * Number(limit), (Number(skip) + 1) * Number(limit));
+      return { errcode: 0, errmsg: '', data: res, total: data.length };
     } catch (error) {
       throw error;
     }

+ 3 - 3
service-login/app/controller/pwdlogin.js

@@ -40,14 +40,14 @@ class LoginController extends Controller {
       return;
     }
     const res = await this.model.findOne({ userName });
-    // 密码
-    const pwd = sm3(`${password}:${res.salt}`);
     if (!res) {
       this.ctx.body = { errcode: -1001, errmsg: '用户不存在', data: '' };
       return;
     }
+    // 密码
+    const pwd = sm3(`${password}:${res.salt}`);
     if (res.password !== pwd) {
-      this.ctx.body = { errcode: -1001, errmsg: '密码错误', data: { pwd, password: res.password, salt: res.salt } };
+      this.ctx.body = { errcode: -1001, errmsg: '密码错误', data: '' };
       return;
     }
     const token = jsonwebtoken.sign({ ...res }, jwt.secret, { expiresIn: jwt.expiresIn, issuer: jwt.issuer });