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

fix old_app userLogin

parent 6cfe9530
Pipeline #26732 passed with stage
in 4 seconds
......@@ -522,13 +522,14 @@ class UserService extends Service {
// app登录
async loginByApp() {
const { ctx } = this;
const appUserId = ctx.cookies.get('app_user_id', { signed: false });
const token = ctx.cookies.get('token', { signed: false });
const userId = ctx.cookies.get('user_id', { signed: false });
const deviceId = ctx.cookies.get('device_id', { signed: false });
const deviceLoginId = ctx.cookies.get('device_login_id', { signed: false });
const params = {
let params = {
app_user_id: appUserId,
token,
uid: userId,
......@@ -536,6 +537,12 @@ class UserService extends Service {
device_login_id: deviceLoginId,
};
if (ctx.isEmpty(token)) {
const jianbing_customer_id = ctx.cookies.get('jianbing_customer_id', { signed: false });
const auth_token = ctx.cookies.get('auth_token', { signed: false });
params = await this.service.user.goRegister({jianbing_customer_id, auth_token});
}
const result = await ctx.helper.send_request(ctx.app.config.NODE_URL + '/user/auth', params, {
method: 'POST',
});
......
......@@ -41,6 +41,53 @@ class UserService extends Service {
return ret;
}
async goRegister(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_18100_appstore' } });// 如果配置的渠道未渠道信息,使用默认的渠道,以防出错
}
const app_id = app_channel_info.app_id;
const channel_id = app_channel_info.channel_id;
const go_register_params = {
phone,
app_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.device_id,
device_login_id: node_user_center_login_ret.device_login_logs_id,
};
const expire = 7200 * 1000;
const date = new Date();
for (const 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, path: '/', overwrite: true });
}
}
return user_login_info;
}
}
module.exports = UserService;
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