Commit a0640356 authored by 任国军's avatar 任国军

add mini_auth_v2

parent 0f5e011a
Pipeline #17496 passed with stage
in 9 seconds
...@@ -27,7 +27,7 @@ class UserController extends Controller { ...@@ -27,7 +27,7 @@ class UserController extends Controller {
console.info(user); console.info(user);
//存储缓存标识 //存储缓存标识
const user_uuid = user.uuid; const user_uuid = user.uuid;
const key = 'course_user_session_' + user_uuid; const key = 'course_v2_user_session_' + user_uuid;
await app.memcache.set(key, { user_uuid, openid }, 86400 * 180); await app.memcache.set(key, { user_uuid, openid }, 86400 * 180);
const auth_token = ctx.helper.md5(openid + user_uuid + 'jbwl'); const auth_token = ctx.helper.md5(openid + user_uuid + 'jbwl');
ctx.set('uuid', key); ctx.set('uuid', key);
......
'use strict';
module.exports = (options, app) => {
return async function(ctx, next) {
const uuid = ctx.headers.uuid;
const key = 'course_v2_user_session_' + uuid;
let auth_info = await ctx.app.memcache.get(key);
if (!auth_info) {
auth_info = await ctx.classModel.V2.CourseUser.findOne({where: {uuid}});
if (ctx.isEmpty(auth_info)) {
ctx.failed('user not exist');
}
}
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/v2'); const router = app.router.namespace(app.config.projectRootPath + '/course/v2');
const loginAuth = app.middleware.loginAuth({ type: 'new' });// 登录中间件 const loginAuth = app.middleware.loginAuth({ type: 'new' });// 登录中间件
const miniAuth = app.middleware.miniAuth();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件 const miniAuth = app.middleware.miniAuthV2();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件
// 版本二 // 版本二
router.get('third', '/cats', 'course.v2.institution.getCats');// 分类 router.get('third', '/cats', 'course.v2.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