From eca00e0ba6d7ab5efb00e9ee160d39857d7279d2 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 30 Nov 2022 13:41:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=85=BC=E5=AE=B9=E9=A1=B9?= =?UTF-8?q?=E4=BC=81token=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/auth/index.js | 36 +++++++++------------------ api/app/lib/routes/auth/index.js | 3 --- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/api/app/lib/controllers/auth/index.js b/api/app/lib/controllers/auth/index.js index 3d7887b..3ce02bb 100644 --- a/api/app/lib/controllers/auth/index.js +++ b/api/app/lib/controllers/auth/index.js @@ -10,9 +10,18 @@ async function login (ctx, next) { const models = ctx.fs.dc.models; const params = ctx.request.body; - const emisLoginRes = await ctx.app.fs.emisRequest.post('login', { - data: params - }) + let emisLoginRes = null + if (params.username && params.password) { + emisLoginRes = await ctx.app.fs.emisRequest.post('login', { + data: { ...params, code: 'POMS' } + }) + } else if (params.token) { + emisLoginRes = await ctx.app.fs.emisRequest.get('user-info', { + query: { + token: params.token, code: 'POMS' + } + }) + } if (!emisLoginRes) { throw "无此用户,请使用正确的登录信息" @@ -93,26 +102,6 @@ async function login (ctx, next) { } } -async function loginWithToken (ctx) { - try { - const { models } = ctx.fs.dc; - const { token } = ctx.request.body - - const emisLoginRes = await ctx.app.fs.emisRequest.get('user-info', { - query: { token, code: 'POMS' } - }) - - ctx.status = 200; - ctx.body = {} - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } -} - async function logout (ctx) { try { const models = ctx.fs.dc.models; @@ -136,5 +125,4 @@ async function logout (ctx) { module.exports = { login, logout, - loginWithToken, }; \ No newline at end of file diff --git a/api/app/lib/routes/auth/index.js b/api/app/lib/routes/auth/index.js index db2b20c..c4df619 100644 --- a/api/app/lib/routes/auth/index.js +++ b/api/app/lib/routes/auth/index.js @@ -6,9 +6,6 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['POST/login'] = { content: '登录', visible: true }; router.post('/login', auth.login); - app.fs.api.logAttr['POST/login/with_token'] = { content: '使用项企token登录', visible: true }; - router.post('/login/with_token', auth.loginWithToken); - app.fs.api.logAttr['PUT/logout'] = { content: '登出', visible: false }; router.put('/logout', auth.logout); }; \ No newline at end of file