|
|
@@ -35,21 +35,34 @@ module.exports = app => {
|
|
|
if (!isPasswordValid) {
|
|
|
throw '帐号或密码错误';
|
|
|
}
|
|
|
+ const paList = await this.ctx.service.projectAccount.getAllDataByCondition({ where: { wx_openid: projectAccount.openid } });
|
|
|
+ const pidList = this.ctx.app._.uniq(this.ctx.app._.map(paList, 'project_id'));
|
|
|
+ const pList = [];
|
|
|
+ for (const p of pidList) {
|
|
|
+ const project = await this.ctx.service.project.getDataById(p);
|
|
|
+ if (project) {
|
|
|
+ pList.push({ code: project.code, name: project.name });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (pList.length === 0) {
|
|
|
+ throw '该微信号未绑定任何项目';
|
|
|
+ }
|
|
|
+
|
|
|
const accessToken = jwt.sign(
|
|
|
- { accountId: projectAccount.id, type: 'access' },
|
|
|
+ { accountId: projectAccount.openid, type: 'access' },
|
|
|
weappConfig.jwtSecret,
|
|
|
{ expiresIn: weappConfig.accessTokenExpiresIn }
|
|
|
);
|
|
|
|
|
|
const refreshToken = jwt.sign(
|
|
|
- { accountId: projectAccount.id, type: 'refresh' },
|
|
|
+ { accountId: projectAccount.openid, type: 'refresh' },
|
|
|
weappConfig.jwtSecret,
|
|
|
{ expiresIn: weappConfig.refreshTokenExpiresIn }
|
|
|
);
|
|
|
// 3. 存入 Redis:pid 对应最新 refreshToken
|
|
|
- const key = `user:${projectAccount.id}:refresh_token`;
|
|
|
+ const key = `user:${projectAccount.openid}:refresh_token`;
|
|
|
await app.redis.set(key, refreshToken, 'EX', weappConfig.redisExpire);
|
|
|
- return { accessToken, refreshToken };
|
|
|
+ return { accessToken, refreshToken, pList };
|
|
|
}
|
|
|
|
|
|
// 微信快捷登录
|
|
|
@@ -65,7 +78,6 @@ module.exports = app => {
|
|
|
});
|
|
|
|
|
|
const { openid, errcode } = wxRes.data;
|
|
|
- console.log('openid', openid);
|
|
|
|
|
|
if (errcode || !openid) throw '微信授权登录失败';
|
|
|
|