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