瀏覽代碼

用户登陆

lrf 2 年之前
父節點
當前提交
558009beb0
共有 3 個文件被更改,包括 14 次插入1 次删除
  1. 4 1
      app/controller/config/.user.js
  2. 9 0
      app/service/user.js
  3. 1 0
      app/z_router/user.js

+ 4 - 1
app/controller/config/.user.js

@@ -39,6 +39,9 @@ module.exports = {
     },
     },
   },
   },
   bindJudge: {
   bindJudge: {
-    requestBody: ['openid', 'user_id', 'type', 'parent_id'],
+    requestBody: ['!openid', 'user_id', 'type', 'parent_id'],
+  },
+  login: {
+    requestBody: ['!openid'],
   },
   },
 };
 };

+ 9 - 0
app/service/user.js

@@ -10,6 +10,15 @@ class UserService extends CrudService {
     super(ctx, 'user');
     super(ctx, 'user');
     this.model = this.ctx.model.Race.User;
     this.model = this.ctx.model.Race.User;
   }
   }
+
+  async login({ openid }) {
+    const num = await this.model.count({ openid });
+    if (num <= 0) return null;
+    const list = await this.query({ openid });
+    return _.head(list);
+  }
+
+
   async beforeCreate(body) {
   async beforeCreate(body) {
     const { openid, user_id } = body;
     const { openid, user_id } = body;
     const num = await this.model.count({ openid, user_id });
     const num = await this.model.count({ openid, user_id });

+ 1 - 0
app/z_router/user.js

@@ -7,6 +7,7 @@ const rkey = 'user';
 const ckey = 'user';
 const ckey = 'user';
 const keyZh = '比赛用户';
 const keyZh = '比赛用户';
 const routes = [
 const routes = [
+  { method: 'post', path: `${rkey}/login`, controller: `${ckey}.login`, name: `${ckey}login`, zh: `${keyZh}-登陆` },
   { method: 'post', path: `${rkey}/bindJudge`, controller: `${ckey}.bindJudge`, name: `${ckey}bindJudge`, zh: `${keyZh}-绑定裁判` },
   { method: 'post', path: `${rkey}/bindJudge`, controller: `${ckey}.bindJudge`, name: `${ckey}bindJudge`, zh: `${keyZh}-绑定裁判` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },