Browse Source

登录兼容项企token登录

dev
巴林闲侠 2 years ago
parent
commit
eca00e0ba6
  1. 36
      api/app/lib/controllers/auth/index.js
  2. 3
      api/app/lib/routes/auth/index.js

36
api/app/lib/controllers/auth/index.js

@ -10,9 +10,18 @@ async function login (ctx, next) {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const params = ctx.request.body; const params = ctx.request.body;
const emisLoginRes = await ctx.app.fs.emisRequest.post('login', { let emisLoginRes = null
data: params 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) { if (!emisLoginRes) {
throw "无此用户,请使用正确的登录信息" 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) { async function logout (ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
@ -136,5 +125,4 @@ async function logout (ctx) {
module.exports = { module.exports = {
login, login,
logout, logout,
loginWithToken,
}; };

3
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 }; app.fs.api.logAttr['POST/login'] = { content: '登录', visible: true };
router.post('/login', auth.login); 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 }; app.fs.api.logAttr['PUT/logout'] = { content: '登出', visible: false };
router.put('/logout', auth.logout); router.put('/logout', auth.logout);
}; };
Loading…
Cancel
Save