Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
ef9c0486
Commit
ef9c0486
authored
Feb 11, 2020
by
宋毅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tj
parent
e6aca6ec
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
39 deletions
+150
-39
center-app/app/base/api/impl/auth/accessAuth.js
+17
-15
center-app/app/base/db/cache/appUserPinByLoginPwdCache.js
+1
-0
center-app/app/base/db/cache/appUserPinByLoginVcodeCache.js
+5
-0
center-app/app/base/system.js
+6
-0
center-app/app/base/utils/businessManager/opPlatformUtils.js
+121
-24
No files found.
center-app/app/base/api/impl/auth/accessAuth.js
View file @
ef9c0486
...
...
@@ -11,23 +11,15 @@ class AccessAuthAPI extends APIBase {
return
result
;
}
async
getVerifyCodeByMoblie
(
pobj
,
qobj
,
req
)
{
async
getVerifyCodeByMoblie
(
pobj
,
qobj
,
req
)
{
//获取默认模板的手机验证码
if
(
!
pobj
.
actionBody
.
mobile
)
{
return
system
.
getResult
(
null
,
"actionBody.mobile can not be empty !"
);
}
var
result
=
await
this
.
opPlatformUtils
.
fetchVCode
(
pobj
.
actionBody
.
mobile
,
pobj
.
appInfo
.
uapp_key
,
pobj
.
appInfo
.
uapp_secret
);
var
result
=
await
this
.
opPlatformUtils
.
fetch
Default
VCode
(
pobj
.
actionBody
.
mobile
,
pobj
.
appInfo
.
uapp_key
,
pobj
.
appInfo
.
uapp_secret
);
return
result
;
}
async
loginUserByChannelUserId
(
pobj
,
qobj
,
req
)
{
if
(
!
pobj
.
actionBody
.
channelUserId
)
{
return
system
.
getResult
(
null
,
"actionBody.channelUserId can not be empty !"
);
}
var
result
=
await
this
.
opPlatformUtils
.
getReqUserPinByChannelUserId
(
pobj
);
return
result
;
}
async
login
(
pobj
,
qobj
,
req
)
{
async
login
(
pobj
,
qobj
,
req
)
{
//通过账户和密码登录
if
(
!
pobj
.
actionBody
.
userName
)
{
return
system
.
getResult
(
null
,
"actionBody.userName can not be empty !"
);
}
...
...
@@ -38,7 +30,7 @@ class AccessAuthAPI extends APIBase {
return
result
;
}
async
loginByVerifyCode
(
pobj
,
qobj
,
req
)
{
async
loginByVerifyCode
(
pobj
,
qobj
,
req
)
{
//通过短信登录或注册信息
if
(
!
pobj
.
actionBody
.
mobile
)
{
return
system
.
getResult
(
null
,
"actionBody.mobile can not be empty !"
);
}
...
...
@@ -48,7 +40,7 @@ class AccessAuthAPI extends APIBase {
var
result
=
await
this
.
opPlatformUtils
.
getReqUserPinByLgoinVcode
(
pobj
);
return
result
;
}
async
modiPasswordByMobile
(
pobj
,
qobj
,
req
)
{
async
modiPasswordByMobile
(
pobj
,
qobj
,
req
)
{
//通过手机验证码修改用户密码
var
actionBody
=
pobj
.
actionBody
;
if
(
!
actionBody
.
mobile
)
{
return
system
.
getResult
(
null
,
"actionBody.mobile can not be empty !"
);
...
...
@@ -59,11 +51,21 @@ class AccessAuthAPI extends APIBase {
if
(
!
actionBody
.
newPwd
)
{
return
system
.
getResult
(
null
,
"actionBody.newPwd can not be empty !"
);
}
if
(
!
actionBody
.
userpin
)
{
return
system
.
getResult
(
null
,
"actionBody.userpin can not be empty !"
);
}
var
result
=
await
this
.
opPlatformUtils
.
putUserPwdByMobile
(
pobj
,
actionBody
);
return
result
;
}
async
logout
(
pobj
,
qobj
,
req
){
async
getLoginInfo
(
pobj
,
qobj
,
req
)
{
//通过手机验证码修改用户密码
var
actionBody
=
pobj
.
actionBody
;
if
(
!
actionBody
.
userpin
)
{
return
system
.
getResult
(
null
,
"actionBody.userpin can not be empty !"
);
}
var
result
=
await
this
.
opPlatformUtils
.
getUserLoginInfo
(
pobj
,
actionBody
);
return
result
;
}
async
logout
(
pobj
,
qobj
,
req
)
{
var
result
=
await
this
.
opPlatformUtils
.
logout
(
pobj
);
return
result
;
}
...
...
center-app/app/base/db/cache/appUserPinByLoginPwdCache.js
View file @
ef9c0486
...
...
@@ -30,6 +30,7 @@ class AppUserPinByLoginPwdCache extends CacheBase {
if
(
userInfo
.
is_enabled
!=
1
)
{
return
system
.
getResult
(
null
,
"user to item is Disable !"
);
}
userInfo
.
userpin
=
actionBody
.
userpin
;
return
system
.
getResultSuccess
(
userInfo
);
}
}
...
...
center-app/app/base/db/cache/appUserPinByLoginVcodeCache.js
View file @
ef9c0486
...
...
@@ -27,6 +27,10 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
if
(
userInfo
.
is_enabled
!=
1
)
{
return
system
.
getResult
(
null
,
"user to item is Disable !"
);
}
if
(
actionBody
.
reqType
==
"reg"
)
{
return
system
.
getResultFail
(
system
.
existUserRegFail
,
"已经存在此用户,注册失败"
);
}
userInfo
.
userpin
=
actionBody
.
userpin
;
return
system
.
getResultSuccess
(
userInfo
);
}
var
params
=
{
...
...
@@ -42,6 +46,7 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
last_login_time
:
new
Date
()
};
userInfo
=
await
this
.
appuserDao
.
create
(
params
);
userInfo
.
userpin
=
actionBody
.
userpin
;
return
system
.
getResultSuccess
(
userInfo
);
}
}
...
...
center-app/app/base/system.js
View file @
ef9c0486
...
...
@@ -296,6 +296,12 @@ System.exTime = 4 * 3600;//缓存过期时间,4小时
System
.
shortExTime
=
300
;
//300
//缓存失效
System
.
cacheInvalidation
=
-
88
;
System
.
noLogin
=
-
99
;
//已经存在此用户,注册失败
System
.
existUserRegFail
=
2000
;
//重复登录
System
.
reDoLoginFail
=
2060
;
...
...
center-app/app/base/utils/businessManager/opPlatformUtils.js
View file @
ef9c0486
...
...
@@ -6,12 +6,17 @@ var settings = require("../../../config/settings");
class
OpPlatformUtils
{
constructor
()
{
this
.
restClient
=
system
.
getObject
(
"util.restClient"
);
this
.
redisClient
=
system
.
getObject
(
"util.redisClient"
);
this
.
createUserUrl
=
settings
.
paasUrl
()
+
"api/auth/accessAuth/register"
;
this
.
fetchDefaultVCodeUrl
=
settings
.
paasUrl
()
+
"api/auth/accessAuth/fetchDefaultVCode"
;
this
.
fetchOtherVCodeUrl
=
settings
.
paasUrl
()
+
"api/auth/accessAuth/fetchOtherVCode"
;
this
.
loginUrl
=
settings
.
paasUrl
()
+
"api/auth/accessAuth/login"
;
this
.
loginByVCodeUrl
=
settings
.
paasUrl
()
+
"api/auth/accessAuth/loginByVCode"
;
this
.
modiPasswordByMobileUrl
=
settings
.
paasUrl
()
+
"api/auth/accessAuth/modiPasswordByMobile"
;
}
getUserPinKey
(
userpin
)
{
return
settings
.
cacheprefix
+
"_userPin:"
+
userpin
;
}
getUUID
()
{
var
uuid
=
uuidv4
();
var
u
=
uuid
.
replace
(
/
\-
/g
,
""
);
...
...
@@ -70,10 +75,40 @@ class OpPlatformUtils {
return
system
.
getResultSuccess
(
restResult
.
data
);
}
/**
*
* @param {*} mobile 手机号
* 通过自定义模板获取手机模板短信
* @param {*} param {
mobile: actionBody.mobile,
tmplCode: "SMS_151685065",
signName: "小望科技",
accessKeyId: "LTAI4Fjk6qBh4GELjkBxfyJF",
accessKeySecret: "Z3wUHmZ0hnQst6uaTY3GzOYVoWwxb9"
}
* @param {*} appKey
* @param {*} secret
*/
async
fetchOtherVCode
(
param
,
appKey
,
secret
)
{
var
reqApiAccessKey
=
await
this
.
getReqApiAccessKey
(
appKey
,
secret
);
if
(
reqApiAccessKey
.
status
!=
0
)
{
return
reqApiAccessKey
;
}
//按照访问token
var
restResult
=
await
this
.
restClient
.
execPostWithAK
(
param
,
this
.
fetchOtherVCodeUrl
,
reqApiAccessKey
.
data
.
accessKey
);
if
(
restResult
.
status
!=
0
||
!
restResult
.
data
)
{
return
system
.
getResult
(
null
,
restResult
.
msg
);
}
return
system
.
getResultSuccess
();
}
/**
* 获取默认的手机模板短信
* @param {*} mobile
* @param {*} appKey
* @param {*} secret
*/
async
fetchVCode
(
mobile
,
appKey
,
secret
)
{
async
fetch
Default
VCode
(
mobile
,
appKey
,
secret
)
{
var
reqApiAccessKey
=
await
this
.
getReqApiAccessKey
(
appKey
,
secret
);
if
(
reqApiAccessKey
.
status
!=
0
)
{
return
reqApiAccessKey
;
...
...
@@ -123,7 +158,7 @@ class OpPlatformUtils {
this
.
loginByVCodeUrl
,
reqApiAccessKey
.
data
.
accessKey
);
if
(
restResult
.
status
!=
0
||
!
restResult
.
data
)
{
return
system
.
getResult
(
restResult
.
status
,
restResult
.
msg
);
return
system
.
getResult
Fail
(
restResult
.
status
,
restResult
.
msg
);
}
return
system
.
getResultSuccess
(
restResult
.
data
);
}
...
...
@@ -164,7 +199,7 @@ class OpPlatformUtils {
return
system
.
getResultSuccess
(
restResult
.
data
);
}
/**
* 通过opencode获取用户登录信息
* 通过opencode获取用户登录信息
----暂时不用
* @param {*} opencode 用户登录或注册opencode
*
* 返回值:
...
...
@@ -218,37 +253,77 @@ class OpPlatformUtils {
var
result
=
await
cacheManager
[
"AppTokenByHostsCache"
].
cache
(
inputkey
,
actionBody
,
system
.
shortExTime
);
return
result
;
}
async
getReqUserPinByChannelUserId
(
pobj
)
{
var
inputkey
=
pobj
.
appInfo
.
uapp_key
+
"_"
+
pobj
.
actionBody
.
channelUserId
;
var
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
var
result
=
await
cacheManager
[
"AppUserPinByChannelUserIdCache"
].
getCache
(
inputkey
,
pobj
,
system
.
shortExTime
);
if
(
result
&&
result
.
status
==
0
)
{
return
system
.
getResultFail
(
system
.
reDoLoginFail
,
"请勿重复登录"
);
}
result
=
await
cacheManager
[
"AppUserPinByChannelUserIdCache"
].
cache
(
inputkey
,
pobj
,
system
.
shortExTime
);
return
result
;
}
// async getReqUserPinByChannelUserId(pobj) {
// var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.channelUserId;
// var cacheManager = system.getObject("db.common.cacheManager");
// var result = await cacheManager["AppUserPinByChannelUserIdCache"].getCache(inputkey, pobj, system.shortExTime);
// if (result && result.status == 0) {
// return system.getResultFail(system.reDoLoginFail, "请勿重复登录");
// }
// result = await cacheManager["AppUserPinByChannelUserIdCache"].cache(inputkey, pobj, system.shortExTime);
// return result;
// if (!actionBody.channelUserId) {
// return system.getResult(null, "actionBody.channelUserId can not be empty");
// }
// var cacheManager = system.getObject("db.common.cacheManager");
// var result = await cacheManager["AppUserPinByChannelUserId"].cache(userPinValue, actionBody, system.exTime);
// return result;
// }
// async getReqUserPinByChannelUserId(actionBody, userPinValue) {
// if (!actionBody.channelUserId) {
// return system.getResult(null, "actionBody.channelUserId can not be empty");
// }
// var cacheManager = system.getObject("db.common.cacheManager");
// var result = await cacheManager["AppUserPinByChannelUserId"].cache(userPinValue, actionBody, system.exTime);
// return result;
// }
/**
* 通过账户和密码登录
* @param {*} pobj pobj.actionBody:{userName:XX,password:XXX}
*/
async
getReqUserPinByLgoin
(
pobj
)
{
var
inputkey
=
pobj
.
appInfo
.
uapp_key
+
"_"
+
pobj
.
actionBody
.
userName
;
var
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
var
result
=
await
cacheManager
[
"AppUserPinByLoginPwdCache"
].
getCache
(
inputkey
,
pobj
,
system
.
shortExTime
);
var
result
=
await
cacheManager
[
"AppUserPinByLoginPwdCache"
].
getCache
(
inputkey
);
if
(
result
&&
result
.
status
==
0
)
{
return
system
.
getResultFail
(
system
.
reDoLoginFail
,
"请勿重复登录"
);
return
system
.
getResultFail
(
system
.
reDoLoginFail
,
"请勿重复登录"
,
{
userpin
:
result
.
data
.
userpin
||
""
}
);
}
result
=
await
cacheManager
[
"AppUserPinByLoginPwdCache"
].
cache
(
inputkey
,
pobj
,
system
.
shortExTime
);
if
(
result
&&
result
.
status
==
0
)
{
var
userpinKey
=
this
.
getUserPinKey
(
pobj
.
actionBody
.
userpin
);
this
.
redisClient
.
setWithEx
(
userpinKey
,
JSON
.
stringify
(
result
),
system
.
exTime
);
}
return
result
;
}
/**
* 通过短信登录或注册信息
* @param {*} pobj pobj.actionBody:{mobile:XXX,vcode:XXX,reqType:"reg",password:XXX-reqType为reg时有此值}
*/
async
getReqUserPinByLgoinVcode
(
pobj
)
{
var
inputkey
=
pobj
.
appInfo
.
uapp_key
+
"_"
+
pobj
.
actionBody
.
mobile
;
var
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
var
result
=
await
cacheManager
[
"AppUserPinByLoginVcodeCache"
].
getCache
(
inputkey
,
pobj
,
system
.
shortExTime
);
if
(
pobj
.
actionBody
.
reqType
!=
"reg"
)
{
var
result
=
await
cacheManager
[
"AppUserPinByLoginVcodeCache"
].
getCache
(
inputkey
);
if
(
result
&&
result
.
status
==
0
)
{
return
system
.
getResultFail
(
system
.
reDoLoginFail
,
"请勿重复登录"
);
return
system
.
getResultFail
(
system
.
reDoLoginFail
,
"请勿重复登录"
,
{
userpin
:
result
.
data
.
userpin
||
""
});
}
}
result
=
await
cacheManager
[
"AppUserPinByLoginVcodeCache"
].
cache
(
inputkey
,
pobj
,
system
.
shortExTime
);
if
(
result
&&
result
.
status
==
0
&&
pobj
.
actionBody
.
reqType
!=
"reg"
)
{
var
userpinKey
=
this
.
getUserPinKey
(
pobj
.
actionBody
.
userpin
);
this
.
redisClient
.
setWithEx
(
userpinKey
,
JSON
.
stringify
(
result
),
system
.
exTime
);
}
return
result
;
}
/**
* 通过手机验证码修改用户密码
* @param {*} pobj
* @param {*} actionBody {mobile:XX,vcode:XXX,newPwd:XXX,userpin:XXXXX}
*/
async
putUserPwdByMobile
(
pobj
,
actionBody
)
{
if
(
!
actionBody
.
mobile
)
{
return
system
.
getResult
(
null
,
"pobj.mobile can not be empty !"
);
...
...
@@ -265,16 +340,38 @@ class OpPlatformUtils {
var
acckapp
=
await
this
.
modiPasswordByMobile
(
actionBody
.
mobile
,
actionBody
.
vcode
,
actionBody
.
newPwd
,
pobj
.
appInfo
.
uapp_key
,
pobj
.
appInfo
.
uapp_secret
);
return
acckapp
;
}
/**
* 获取账户信息
* @param {*} pobj pobj.actionBody:{userpin:XXX}
*/
async
getUserLoginInfo
(
pobj
)
{
var
userpinKey
=
this
.
getUserPinKey
(
pobj
.
actionBody
.
userpin
);
var
userInfoResult
=
await
this
.
redisClient
.
get
(
userpinKey
);
if
(
!
userInfoResult
)
{
return
system
.
getResultSuccess
(
system
.
noLogin
,
"user no login"
);
}
return
JSON
.
parse
(
userInfoResult
);
}
/**
* 退出账户登录
* @param {*} pobj pobj.actionBody:{userpin:XXX}
*/
async
logout
(
pobj
)
{
var
inputkey
=
pobj
.
appInfo
.
uapp_key
+
"_"
+
pobj
.
actionBody
.
userName
;
var
userpinKey
=
this
.
getUserPinKey
(
pobj
.
actionBody
.
userpin
);
var
userInfoResult
=
await
this
.
redisClient
.
get
(
userpinKey
);
if
(
!
userInfoResult
)
{
return
system
.
getResultSuccess
(
null
,
"ok!"
);
}
var
userResult
=
JSON
.
parse
(
userInfoResult
);
if
(
userResult
.
status
==
0
)
{
var
inputkey
=
pobj
.
appInfo
.
uapp_key
+
"_"
+
userResult
.
data
.
channel_username
;
var
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
await
cacheManager
[
"AppUserPinByLoginPwdCache"
].
invalidate
(
inputkey
);
await
cacheManager
[
"AppUserPinByLoginVcodeCache"
].
invalidate
(
inputkey
);
}
this
.
redisClient
.
delete
(
userpinKey
);
return
system
.
getResultSuccess
();;
}
}
module
.
exports
=
OpPlatformUtils
;
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