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

fix login

parent 73add341
Pipeline #22811 passed with stage
in 3 seconds
......@@ -30,6 +30,28 @@ module.exports = {
return decode_res;
},
// 校验 Token 非强制
async verify_token_sample(ctx) {
const bearerToken = ctx.request.header.authorization;
const token = ctx.isEmpty(bearerToken) ? '' : bearerToken.replace('Bearer ', '');
if (ctx.isEmpty(token)) {
return;
}
const decode_res = await ctx.service.jwt.decode_token(token);
if (ctx.isEmpty(decode_res)) {
return;
}
if (!ctx.isEmpty(decode_res.data) && !ctx.isEmpty(decode_res.data.user_uuid)) {
ctx.setUserUuid(decode_res.data.user_uuid);
}
if (!ctx.isEmpty(decode_res.data) && !ctx.isEmpty(decode_res.data.openid)) {
ctx.setOpenId(decode_res.data.openid);
}
return decode_res;
},
md5(str) {
if (!str) {
return '';
......
'use strict';
module.exports = () => {
module.exports = options => {
return async function auth(ctx, next) {
await ctx.helper.verify_token(ctx);
if (options.is_force > 0) {
await ctx.helper.verify_token(ctx);
} else {
await ctx.helper.verify_token_sample(ctx);
}
await next();
};
};
......@@ -3,40 +3,40 @@
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/course/v5');
// const miniAuth = app.middleware.miniAuthV5();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件
const auth = app.middleware.verifyAuth();
const auth = app.middleware.verifyAuth;
router.post('third', '/verification_code', 'course.v5.user.sendVerificationCode');// 发送验证码
router.post('third', '/login/phone', 'course.v5.user.loginByPhone');// 手机号登录
router.post('third', '/login/wechat', 'course.v5.user.loginByWX');// 微信登录
router.post('third', '/user/register_user', auth, 'course.v5.user.registerUserInfo');// 授权后注册用户
router.get('third', '/user/info', auth, 'course.v5.user.getUserInfo');// 获取用户信息
router.post('third', '/user/baby', auth, 'course.v5.user.addUserBaby');// 上传用户宝宝信息
router.post('third', '/user/register_user', auth({ is_force: 1 }), 'course.v5.user.registerUserInfo');// 授权后注册用户
router.get('third', '/user/info', auth({ is_force: 1 }), 'course.v5.user.getUserInfo');// 获取用户信息
router.post('third', '/user/baby', auth({ is_force: 1 }), 'course.v5.user.addUserBaby');// 上传用户宝宝信息
router.get('third', '/category/all', auth, 'course.v5.option.getCategoryList');// 获取分类列表
router.get('third', '/category/all', auth({ is_force: 1 }), 'course.v5.option.getCategoryList');// 获取分类列表
router.get('third', '/banner/all', 'course.v5.option.getBannerList');// 获取banner列表
router.get('third', '/options', 'course.v5.option.getOptions');// 获取配置项
router.post('third', '/wechat/qrcode', 'course.v5.wechat.getQRCode');// 获取二维码
router.post('third', '/wechat/unlimited_code', 'course.v5.wechat.getUnlimitedCode');// 获取小程序码
router.get('third', '/feedback/type', 'course.v5.option.getFeedbackTypeList');// 获取反馈分类
router.post('third', '/feedback', auth, 'course.v5.option.addFeedback');// 反馈
router.get('third', '/category/tip', auth, 'course.v5.option.getCategoryTip');// 获取分类提示(年龄不符合)
router.post('third', '/feedback', auth({ is_force: 1 }), 'course.v5.option.addFeedback');// 反馈
router.get('third', '/category/tip', auth({ is_force: 1 }), 'course.v5.option.getCategoryTip');// 获取分类提示(年龄不符合)
router.get('third', '/wechat/callbackAction', 'course.v5.wechat.check');
router.post('third', '/wechat/callbackAction', 'course.v5.wechat.callbackAction');
router.post('third', '/wechat/test', 'course.v5.wechat.test');
router.get('third', '/class/all', auth, 'course.v5.institution.getClassList');// 获取课程列表
router.get('third', '/class/:class_id', auth, 'course.v5.institution.getClassInfo');// 获取课程详情
router.get('third', '/class/all', auth({ is_force: 0 }), 'course.v5.institution.getClassList');// 获取课程列表
router.get('third', '/class/:class_id', auth({ is_force: 0 }), 'course.v5.institution.getClassInfo');// 获取课程详情
router.get('third', '/collection/class/all', auth, 'course.v5.institution.getCollectionClassList');// 获取收藏课程列表
router.post('third', '/collection/class/:class_id', auth, 'course.v5.institution.collectClass');// 收藏课程
router.delete('third', '/collection/class/:class_id', auth, 'course.v5.institution.delCollectClass');// 取消收藏课程
router.get('third', '/collection/class/all', auth({ is_force: 1 }), 'course.v5.institution.getCollectionClassList');// 获取收藏课程列表
router.post('third', '/collection/class/:class_id', auth({ is_force: 1 }), 'course.v5.institution.collectClass');// 收藏课程
router.delete('third', '/collection/class/:class_id', auth({ is_force: 1 }), 'course.v5.institution.delCollectClass');// 取消收藏课程
router.get('third', '/article', 'course.v5.institution.getArticleByCategory');// 获取科普文章
router.get('third', '/question/all', auth, 'course.v5.report.getQuestionList');// 获取问题列表
router.post('third', '/report', auth, 'course.v5.report.generateReport');// 生成报告
router.get('third', '/report/all', auth, 'course.v5.report.getReportList');// 获取报告列表
router.get('third', '/recommend/class/all', auth, 'course.v5.report.getAllReportRecommendClassList');// 获取所有报告推荐课程
router.get('third', '/report/:report_id', auth, 'course.v5.report.getReportById');// 获取报告详情
router.get('third', '/question/all', auth({ is_force: 1 }), 'course.v5.report.getQuestionList');// 获取问题列表
router.post('third', '/report', auth({ is_force: 1 }), 'course.v5.report.generateReport');// 生成报告
router.get('third', '/report/all', auth({ is_force: 1 }), 'course.v5.report.getReportList');// 获取报告列表
router.get('third', '/recommend/class/all', auth({ is_force: 1 }), 'course.v5.report.getAllReportRecommendClassList');// 获取所有报告推荐课程
router.get('third', '/report/:report_id', auth({ is_force: 1 }), 'course.v5.report.getReportById');// 获取报告详情
};
......@@ -48,8 +48,11 @@ class InstitutionSubService extends Service {
}
// 用户收藏的课程
const userCollection = await ctx.classModel.V5.CourseUserCollection.findAll({ where: { user_uuid: ctx.userUuid, is_deleted: 0, type: 3 }, raw: true });
const collectedIds = R.pluck('type_id', userCollection);
let collectedIds = [];
if (!ctx.isEmpty(ctx.userUuid)) {
const userCollection = await ctx.classModel.V5.CourseUserCollection.findAll({ where: { user_uuid: ctx.userUuid, is_deleted: 0, type: 3 }, raw: true });
collectedIds = R.pluck('type_id', userCollection);
}
for (const i in classList.rows) {
classList.rows[i].is_collected = collectedIds.includes(classList.rows[i].id) ? 1 : 0;
}
......@@ -103,7 +106,7 @@ class InstitutionSubService extends Service {
}
const isCollected = await ctx.classModel.V5.CourseUserCollection.findOne({ where: { user_uuid: ctx.userUuid, type: 3, type_id: id, is_deleted: 0 } });
const isCollected = ctx.isEmpty(ctx.userUuid) ? '' : await ctx.classModel.V5.CourseUserCollection.findOne({ where: { user_uuid: ctx.userUuid, type: 3, type_id: id, is_deleted: 0 } });
classInfo.is_collected = ctx.isEmpty(isCollected) ? 0 : 1;
// 额外字段
......
......@@ -137,13 +137,13 @@ class UserService extends Service {
phone: userInfo.phone,
};
await app.memcache.set(key, value, 7 * 24 * 3600);
const authToken = await this.service.jwt.apply({ user_uuid: userInfo.uuid, openid: userInfo.openid });
await app.memcache.set('course_auth_token_' + userInfo.uuid, authToken, 7 * 24 * 3600);
// const authToken = await this.service.jwt.apply({ user_uuid: userInfo.uuid, openid: userInfo.openid });
// await app.memcache.set('course_auth_token_' + userInfo.uuid, authToken, 7 * 24 * 3600);
const ret = {
user_uuid: userInfo.uuid,
openid: userInfo.openid,
bind_phone: ctx.isEmpty(userInfo.phone) ? 0 : 1,
auth_token: authToken,
// auth_token: authToken,
};
return ret;
......
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