Commit 7da8d129 authored by 任国军's avatar 任国军

add mini_auth_v3

parent 3ffae893
Pipeline #18029 passed with stage
in 9 seconds
'use strict';
module.exports = (options, app) => {
return async function(ctx, next) {
const uuid = ctx.headers.uuid;
const key = 'course_v3_user_session_' + uuid;
let auth_info = await ctx.app.memcache.get(key);
if (!auth_info) {
auth_info = await ctx.classModel.V3.CourseUser.findOne({ where: { uuid } });
if (ctx.isEmpty(auth_info)) {
ctx.failed('user not exist');
} else {
await ctx.app.memcache.set(key, { user_uuid: uuid, openid: auth_info.openid }, 86400 * 7);
}
}
const openid = auth_info.openid;
const user_uuid = auth_info.user_uuid;
const auth_token = ctx.headers.auth_token;
if (ctx.helper.md5(openid + uuid + 'jbwl') != auth_token) {
ctx.failed('login auth error');
}
// console.info('11111111111111111111111111111111');
// console.info(auth_info);
ctx.setUserUuid(user_uuid);
ctx.setOpenId(openid);
await next();
};
};
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module.exports = app => { module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/course/v3'); const router = app.router.namespace(app.config.projectRootPath + '/course/v3');
const loginAuth = app.middleware.loginAuth({ type: 'new' });// 登录中间件 const loginAuth = app.middleware.loginAuth({ type: 'new' });// 登录中间件
const miniAuth = app.middleware.miniAuthV2();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件 const miniAuth = app.middleware.miniAuthV3();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件
// 版本二 // 版本二
router.get('third', '/cats', 'course.v3.institution.getCats');// 分类 router.get('third', '/cats', 'course.v3.institution.getCats');// 分类
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment