Commit c785a91a authored by 李尚科's avatar 李尚科

device init add go_register 兼容老用户系统

parent 2c047410
Pipeline #8940 passed with stage
in 5 seconds
...@@ -88,6 +88,16 @@ module.exports = () => { ...@@ -88,6 +88,16 @@ module.exports = () => {
// deviceId = input_params.device_id; // deviceId = input_params.device_id;
// } // }
// 校验 // 校验
const jianbing_customer_id = ctx.cookies.get('jianbing_customer_id', { signed: false });
const auth_token = ctx.cookies.get('auth_token', { signed: false });
if ((!appUserId || !token || !userId || !device_id || !device_login_id) && jianbing_customer_id && auth_token) {
const user_login_info = await goRegister(ctx, { jianbing_customer_id, auth_token });
userId = user_login_info.user_id;
appUserId = user_login_info.app_user_id;
token = user_login_info.token;
deviceId = user_login_info.device_id;
deviceLoginId = user_login_info.device_login_id;
}
const params = { const params = {
app_user_id: appUserId, app_user_id: appUserId,
token, token,
...@@ -145,4 +155,53 @@ module.exports = () => { ...@@ -145,4 +155,53 @@ module.exports = () => {
await next(); await next();
}; };
};
async function goRegister(ctx, old_user_data = {}) {
// const { ctx } = this;
const { jianbing_customer_id, auth_token } = old_user_data;
if (!jianbing_customer_id || !auth_token) {
return {};
}
const phone_info = await ctx.service.user.get_phone_by_user_sid({ user_sid: jianbing_customer_id, token: auth_token });//获取用户手机号码
const phone = phone_info.phone;
const channel_alias = ctx.cookies.get('channel_alias', { signed: false });
let app_channel_info = await ctx.blockModel.AppChannel.one({ where: { alias: channel_alias } });//
if (!app_channel_info || !app_channel_info.app_id || !app_channel_info.channel_id) {
app_channel_info = await ctx.blockModel.AppChannel.one({ where: { alias: 'n_1_2' } });//如果配置的渠道未渠道信息,使用默认的渠道,以防出错
}
const app_id = app_channel_info.app_id;
const channel_id = app_channel_info.channel_id;
const go_register_params = {
phone: phone,
app_id: app_id,
channel_id: channel_id,
}
const result_go_register = await ctx.helper.send_request(ctx.app.config.NODE_URL + '/login/go_register', go_register_params, { method: 'POST' });//通过手机号直接注册新用户中心
const node_user_center_login_ret = result_go_register.data;
ctx.logger.info(JSON.stringify({ url: ctx.app.config.NODE_URL + '/login/go_register', middleware_go_register_params: go_register_params, middleware_result_go_register: result_go_register }));
if (!node_user_center_login_ret.token || !node_user_center_login_ret.uid || !node_user_center_login_ret.app_user_id) {
return {};
}
const user_login_info = {
user_id: node_user_center_login_ret.uid,
app_user_id: node_user_center_login_ret.app_user_id,
token: node_user_center_login_ret.token,
device_id: node_user_center_login_ret.deviceId,
device_login_id: node_user_center_login_ret.device_login_logs_id,
}
const expire = 7200 * 1000;
const date = new Date();
for (let key in user_login_info) {
const value = user_login_info[key];
const exist_value = ctx.cookies.get(key, { signed: false });
if (!exist_value) {
ctx.cookies.set(key, value, { httpOnly: false, signed: false, maxAge: expire, expires: date, path: '/' });
}
}
return user_login_info;
}
};
\ No newline at end of file
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