Explorar o código

增加注册添加用户

liuyu %!s(int64=5) %!d(string=hai) anos
pai
achega
e3ce484a80
Modificáronse 2 ficheiros con 21 adicións e 1 borrados
  1. 14 1
      app/service/user.js
  2. 7 0
      config/config.default.js

+ 14 - 1
app/service/user.js

@@ -24,7 +24,20 @@ class UserService extends CrudService {
     }
     const newdata = data;
     newdata.password = { secret: password };
-    return await this.model.create(newdata);
+    const res = await this.model.create(newdata);
+    if (res) {
+      const url = this.ctx.app.config.axios.auth.baseUrl;
+      const newdata = { name, phone: data.phone, passwd: password, uid: res.id, role: data.role };
+      await this.ctx.curl(url, {
+        method: 'post',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+        data: JSON.stringify(newdata),
+      });
+    }
+    return res;
   }
 
   async update({ id }, data) {

+ 7 - 0
config/config.default.js

@@ -30,6 +30,13 @@ module.exports = appInfo => {
     },
   };
 
+  // axios service config
+  config.axios = {
+    auth: { // 用户鉴权服务
+      baseUrl: 'http://localhost:9999/api/auth/user',
+    },
+  };
+
   config.mongoose = {
     url: 'mongodb://localhost:27017/platform',
     options: {