lrf 2 سال پیش
والد
کامیت
02bad8fe0b
3فایلهای تغییر یافته به همراه16 افزوده شده و 1 حذف شده
  1. 3 0
      app/controller/user/config/.user.js
  2. 12 0
      app/service/user/user.js
  3. 1 1
      app/z_router/user/user.js

+ 3 - 0
app/controller/user/config/.user.js

@@ -59,4 +59,7 @@ module.exports = {
   toBindPhone: {
     requestBody: ['!id', '!phone'],
   },
+  checkBindPhone: {
+    requestBody: ['!code', '!id', '!phone'],
+  },
 };

+ 12 - 0
app/service/user/user.js

@@ -121,6 +121,18 @@ class UserService extends CrudService {
     const url = `${this.smsServiceUrl}/sendMessage`;
     await this.httpUtil.cpost(url, data);
   }
+
+  async checkBindPhone({ code, id, phone }) {
+    const redisData = await this.redis.get(`${this.bindPhoneKey}${id}`);
+    if (!redisData) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '验证码已超时');
+    const arr = redisData.split(this.conenctCode);
+    const rphone = _.head(arr);
+    const rCode = _.last(arr);
+    if (code !== rCode) throw new BusinessError(ErrorCode.DATA_INVALID, '验证码错误');
+    if (phone !== rphone) throw new BusinessError(ErrorCode.DATA_INVALID, '要绑定的邮箱与接收验证码的邮箱不是同一个邮箱');
+    await this.model.updateOne({ _id: id }, { phone });
+    await this.redis.del(`${this.bindPhoneKey}${id}`);
+  }
 }
 
 module.exports = UserService;

+ 1 - 1
app/z_router/user/user.js

@@ -7,7 +7,7 @@ const rkey = 'user';
 const ckey = 'user.user';
 const keyZh = '用户';
 const routes = [
-  // { method: 'get', path: `${rkey}/getUserInfo`, controller: `${ckey}.getUserInfo`, name: `${ckey}GetUserInfo`, zh: `${keyZh}换取用户信息` },
+  { method: 'post', path: `${rkey}/checkBindPhone`, controller: `${ckey}.checkBindPhone`, name: `${ckey}checkBindPhone`, zh: `${keyZh}校验绑定手机验证码` },
   { method: 'post', path: `${rkey}/toBindPhone`, controller: `${ckey}.toBindPhone`, name: `${ckey}toBindPhone`, zh: `${keyZh}发送绑定手机验证码` },
   { method: 'post', path: `${rkey}/toBindEmail`, controller: `${ckey}.toBindEmail`, name: `${ckey}toBindEmail`, zh: `${keyZh}发送绑定邮箱验证码` },
   { method: 'post', path: `${rkey}/checkBindEmail`, controller: `${ckey}.checkBindEmail`, name: `${ckey}checkBindEmail`, zh: `${keyZh}校验绑定邮箱` },