Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
c785a91a
Commit
c785a91a
authored
Jun 14, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
device init add go_register 兼容老用户系统
parent
2c047410
Pipeline
#8940
passed with stage
in 5 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
1 deletion
+61
-1
device_init.js
app/middleware/device_init.js
+61
-1
No files found.
app/middleware/device_init.js
View file @
c785a91a
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment