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
ec7f4d10
Commit
ec7f4d10
authored
Jun 30, 2020
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add appLogin
parent
0e662e6e
Pipeline
#25682
passed with stage
in 4 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
0 deletions
+125
-0
user.js
app/controller/course/v5/user.js
+9
-0
context.js
app/extend/context.js
+9
-0
verify_auth.js
app/middleware/verify_auth.js
+36
-0
course_v5.js
app/router/course_v5.js
+1
-0
user.js
app/service/course/v5/user.js
+70
-0
No files found.
app/controller/course/v5/user.js
View file @
ec7f4d10
...
@@ -132,6 +132,15 @@ class UserController extends Controller {
...
@@ -132,6 +132,15 @@ class UserController extends Controller {
const
ret
=
await
service
.
course
.
v5
.
user
.
redeemClass
(
params
);
const
ret
=
await
service
.
course
.
v5
.
user
.
redeemClass
(
params
);
ctx
.
success
(
ret
);
ctx
.
success
(
ret
);
}
}
// app登录
async
loginByApp
()
{
const
{
ctx
,
service
}
=
this
;
const
ret
=
await
service
.
course
.
v5
.
user
.
loginByApp
();
ctx
.
success
(
ret
);
}
}
}
module
.
exports
=
UserController
;
module
.
exports
=
UserController
;
app/extend/context.js
View file @
ec7f4d10
...
@@ -14,6 +14,7 @@ const USERID = Symbol('Context#userId');
...
@@ -14,6 +14,7 @@ const USERID = Symbol('Context#userId');
const
OLDCOOKIE
=
Symbol
(
'Context#oldCookie'
);
const
OLDCOOKIE
=
Symbol
(
'Context#oldCookie'
);
const
USERUUID
=
Symbol
(
'Context#userUuid'
);
const
USERUUID
=
Symbol
(
'Context#userUuid'
);
const
OPENID
=
Symbol
(
'Context#openId'
);
const
OPENID
=
Symbol
(
'Context#openId'
);
const
TYPE
=
Symbol
(
'Context#type'
);
module
.
exports
=
{
module
.
exports
=
{
failed
(
message
)
{
failed
(
message
)
{
...
@@ -178,6 +179,10 @@ module.exports = {
...
@@ -178,6 +179,10 @@ module.exports = {
return
this
[
OPENID
];
return
this
[
OPENID
];
},
},
get
type
()
{
return
this
[
TYPE
];
},
setAppUserId
(
app_user_id
)
{
setAppUserId
(
app_user_id
)
{
this
[
APPUSERID
]
=
app_user_id
;
this
[
APPUSERID
]
=
app_user_id
;
},
},
...
@@ -217,4 +222,8 @@ module.exports = {
...
@@ -217,4 +222,8 @@ module.exports = {
setOpenId
(
openId
)
{
setOpenId
(
openId
)
{
this
[
OPENID
]
=
openId
;
this
[
OPENID
]
=
openId
;
},
},
setType
(
type
)
{
this
[
TYPE
]
=
type
;
},
};
};
app/middleware/verify_auth.js
View file @
ec7f4d10
...
@@ -7,6 +7,42 @@ module.exports = options => {
...
@@ -7,6 +7,42 @@ module.exports = options => {
}
else
{
}
else
{
await
ctx
.
helper
.
verify_token_sample
(
ctx
);
await
ctx
.
helper
.
verify_token_sample
(
ctx
);
}
}
// 判断header中的type
const
type
=
ctx
.
request
.
header
.
type
;
ctx
.
logger
.
info
(
'course_headers: '
+
JSON
.
stringify
(
ctx
.
request
.
header
));
if
(
!
ctx
.
isEmpty
(
type
)
&&
type
!==
'h5'
&&
type
!==
'miniProgram'
&&
!
ctx
.
isEmpty
(
ctx
.
userUuid
))
{
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
=
{
app_user_id
:
appUserId
,
token
,
uid
:
userId
,
device_id
:
deviceId
,
device_login_id
:
deviceLoginId
,
};
const
result
=
await
ctx
.
helper
.
send_request
(
ctx
.
app
.
config
.
NODE_URL
+
'/user/auth'
,
params
,
{
method
:
'POST'
,
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
url
:
ctx
.
app
.
config
.
NODE_URL
+
'/user/auth'
,
request_header
:
ctx
.
request
.
header
,
user_auth_params
:
params
,
user_auth_result
:
result
}));
if
(
result
.
status
!==
201
||
ctx
.
isEmpty
(
result
.
data
))
{
this
.
throw
(
401
,
'token已失效'
);
return
;
}
const
phone
=
ctx
.
isEmpty
(
result
.
data
.
data
.
passport
)
?
''
:
result
.
data
.
data
.
passport
;
const
user
=
await
ctx
.
classModel
.
V5
.
CourseUser
.
findOne
({
where
:
{
uuid
:
ctx
.
userUuid
,
is_deleted
:
0
}
});
if
(
ctx
.
isEmpty
(
user
)
||
user
.
phone
!==
phone
)
{
this
.
throw
(
401
,
'token校验不一致'
);
}
}
await
next
();
await
next
();
};
};
};
};
app/router/course_v5.js
View file @
ec7f4d10
...
@@ -9,6 +9,7 @@ module.exports = app => {
...
@@ -9,6 +9,7 @@ module.exports = app => {
router
.
post
(
'third'
,
'/verification_code'
,
'course.v5.user.sendVerificationCode'
);
// 发送验证码
router
.
post
(
'third'
,
'/verification_code'
,
'course.v5.user.sendVerificationCode'
);
// 发送验证码
router
.
post
(
'third'
,
'/login/phone'
,
'course.v5.user.loginByPhone'
);
// 手机号登录
router
.
post
(
'third'
,
'/login/phone'
,
'course.v5.user.loginByPhone'
);
// 手机号登录
router
.
post
(
'third'
,
'/login/wechat'
,
'course.v5.user.loginByWX'
);
// 微信登录
router
.
post
(
'third'
,
'/login/wechat'
,
'course.v5.user.loginByWX'
);
// 微信登录
router
.
post
(
'third'
,
'/login/app'
,
'course.v5.user.loginByApp'
);
// app授权登录
router
.
post
(
'third'
,
'/user/register_user'
,
auth
({
is_force
:
0
}),
'course.v5.user.registerUserInfo'
);
// 授权后注册用户
router
.
post
(
'third'
,
'/user/register_user'
,
auth
({
is_force
:
0
}),
'course.v5.user.registerUserInfo'
);
// 授权后注册用户
router
.
get
(
'third'
,
'/user/info'
,
auth
({
is_force
:
1
}),
'course.v5.user.getUserInfo'
);
// 获取用户信息
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
.
post
(
'third'
,
'/user/baby'
,
auth
({
is_force
:
1
}),
'course.v5.user.addUserBaby'
);
// 上传用户宝宝信息
...
...
app/service/course/v5/user.js
View file @
ec7f4d10
...
@@ -511,6 +511,76 @@ class UserService extends Service {
...
@@ -511,6 +511,76 @@ class UserService extends Service {
return
{
class_id
:
codeInfo
.
class_id
,
result
:
true
,
url
:
classInfo
.
button_url
};
return
{
class_id
:
codeInfo
.
class_id
,
result
:
true
,
url
:
classInfo
.
button_url
};
}
}
// 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
=
{
app_user_id
:
appUserId
,
token
,
uid
:
userId
,
device_id
:
deviceId
,
device_login_id
:
deviceLoginId
,
};
const
result
=
await
ctx
.
helper
.
send_request
(
ctx
.
app
.
config
.
NODE_URL
+
'/user/auth'
,
params
,
{
method
:
'POST'
,
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
url
:
ctx
.
app
.
config
.
NODE_URL
+
'/user/auth'
,
request_header
:
ctx
.
request
.
header
,
user_auth_params
:
params
,
user_auth_result
:
result
}));
if
(
result
.
status
!==
201
||
ctx
.
isEmpty
(
result
.
data
))
{
ctx
.
throw
(
401
,
'token已失效'
);
return
;
}
const
phone
=
ctx
.
isEmpty
(
result
.
data
.
data
.
passport
)
?
''
:
result
.
data
.
data
.
passport
;
if
(
ctx
.
isEmpty
(
phone
))
{
ctx
.
failed
(
'phone异常'
);
}
// 判断用户是否存在
let
userInfo
=
await
ctx
.
classModel
.
V5
.
CourseUser
.
findOne
({
where
:
{
phone
,
is_deleted
:
0
}
});
if
(
ctx
.
isEmpty
(
userInfo
))
{
const
uuid
=
uuidV4
();
await
ctx
.
classModel
.
V5
.
CourseUser
.
findOrCreate
({
where
:
{
phone
,
is_deleted
:
0
},
defaults
:
{
uuid
,
phone
}
});
userInfo
=
await
ctx
.
classModel
.
V5
.
CourseUser
.
findOne
({
where
:
{
phone
,
is_deleted
:
0
}
});
}
const
data
=
{
app_id
:
result
.
data
.
data
.
app_id
,
app_type_id
:
result
.
data
.
data
.
app_type_id
,
user_id
:
result
.
data
.
data
.
user_id
,
app_user_id
:
result
.
data
.
data
.
app_user_id
,
};
await
ctx
.
classModel
.
V5
.
CourseUser
.
update
(
data
,
{
where
:
{
id
:
userInfo
.
id
}
});
const
key
=
'course_v5_user_session_'
+
userInfo
.
uuid
;
const
value
=
{
user_uuid
:
userInfo
.
uuid
,
openid
:
userInfo
.
openid
,
session_key
:
''
,
phone
,
};
await
ctx
.
app
.
memcache
.
set
(
key
,
value
,
7
*
24
*
3600
);
let
authToken
=
await
ctx
.
app
.
memcache
.
get
(
'course_auth_token_'
+
userInfo
.
uuid
);
if
(
ctx
.
isEmpty
(
authToken
))
{
authToken
=
await
this
.
service
.
jwt
.
apply
({
user_uuid
:
userInfo
.
uuid
,
openid
:
userInfo
.
openid
});
await
ctx
.
app
.
memcache
.
set
(
'course_auth_token_'
+
userInfo
.
uuid
,
authToken
,
30
*
24
*
3600
);
}
const
ret
=
{
user_uuid
:
userInfo
.
uuid
,
auth_token
:
authToken
,
};
return
ret
;
}
}
}
module
.
exports
=
UserService
;
module
.
exports
=
UserService
;
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