Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
htoooth
9 years ago
Commit
99e0da29bf37aecb1e102371c1dc3baed9dfc60b
1 parent
1ff03703
master
...
baidu_ocpcapi
develop
feature/canbuy
feature/channelDataMap
feature/company-profile
feature/contact
feature/detail-link
feature/home-optimize
feature/overseas-edition
feature/payment
feature/pcurl
feature/reduce
feature/refactor_alert
feature/shoppingPay
feature/virtualOrder
hotfix/11
hotfix/cart
hotfix/changeappversion
hotfix/gift
hotfix/im
hotfix/link
hotfix/ocpc
hotfix/shop
hotfix/upload
hotfix/yohobi
release/6.9.0
release/6.9.2
2019-12-5
all
change apiSign
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
307 additions
and
251 deletions
apps/passport/controllers/back.js
apps/passport/controllers/captcha.js
apps/passport/models/back-api.js
apps/passport/models/back-service.js
apps/passport/models/captcha-service.js
apps/passport/models/index-api.js
apps/passport/models/index-service.js
apps/passport/models/passport-helper.js
apps/passport/models/user-api.js
apps/passport/models/user-service.js
apps/passport/router.js
apps/passport/controllers/back.js
View file @
99e0da2
...
...
@@ -5,12 +5,11 @@
'use strict'
;
const
library
=
'../../../library'
;
const
helpers
=
require
(
`
$
{
library
}
/helpers`
)
;
const
service
=
require
(
'../models/back-service'
);
const
library
=
'../../../library'
;
const
helpers
=
require
(
`
$
{
library
}
/helpers`
)
;
const
service
=
require
(
'../models/back-service'
);
const
passportHelper
=
require
(
'../models/passport-helper'
);
const
moment
=
require
(
'moment'
);
const
moment
=
require
(
'moment'
);
// 本地地址 localhost
helpers
.
urlFormat
=
helpers
.
fakeUrlFormat
;
...
...
@@ -19,13 +18,15 @@ helpers.urlFormat = helpers.fakeUrlFormat;
* 找回密码主页面
*/
module
.
exports
.
indexPage
=
(
req
,
res
,
next
)
=>
{
service
.
indexPageDataAsync
().
then
(
result
=>
{
res
.
render
(
'back/index'
,
Object
.
assign
({
module
:
'passport'
,
page
:
'back-index'
,
title
:
'找回密码'
},
result
));
}).
catch
(
next
);
service
.
indexPageDataAsync
()
.
then
(
result
=>
{
res
.
render
(
'back/index'
,
Object
.
assign
({
module
:
'passport'
,
page
:
'back-index'
,
title
:
'找回密码'
},
result
));
})
.
catch
(
next
);
};
/**
...
...
@@ -33,8 +34,7 @@ module.exports.indexPage = (req, res, next) => {
*/
module
.
exports
.
validateInputAPI
=
(
req
,
res
,
next
)
=>
{
let
userInput
=
req
.
body
.
phoneNum
||
''
;
let
areaCode
=
(
req
.
body
.
area
||
'86'
).
replace
(
'+'
,
''
);
let
areaCode
=
(
req
.
body
.
area
||
'86'
).
replace
(
'+'
,
''
);
service
.
validateEmailOrMobileAsync
(
userInput
,
areaCode
)
.
then
(
result
=>
{
...
...
@@ -44,7 +44,7 @@ module.exports.validateInputAPI = (req, res, next) => {
})
.
catch
(
err
=>
{
res
.
json
({
code
:
400
,
code
:
400
,
message
:
err
});
});
...
...
@@ -55,8 +55,7 @@ module.exports.validateInputAPI = (req, res, next) => {
*/
module
.
exports
.
validateUserPage
=
(
req
,
res
,
next
)
=>
{
let
userInput
=
req
.
body
.
phoneNum
||
''
;
let
areaCode
=
(
req
.
body
.
area
||
'86'
).
replace
(
'+'
,
''
);
let
areaCode
=
(
req
.
body
.
area
||
'86'
).
replace
(
'+'
,
''
);
service
.
validateEmailOrMobileAsync
(
userInput
,
areaCode
)
.
then
(
result
=>
{
...
...
@@ -74,22 +73,25 @@ module.exports.getUserInfoAPI = (req, res, next) => {
service
.
findUserAsync
(
inputInfo
.
type
,
inputInfo
.
phone
,
inputInfo
.
area
)
.
then
(
result
=>
{
res
.
json
(
result
);
}).
catch
(
next
);
})
.
catch
(
next
);
};
module
.
exports
.
sendCodePage
=
(
req
,
res
,
next
)
=>
{
let
inputInfo
=
req
.
inputInfo
;
service
.
sendCodeToUserAsync
(
inputInfo
.
type
,
inputInfo
.
phone
,
inputInfo
.
area
).
then
(
result
=>
{
if
(
_
.
isEmpty
(
result
))
{
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index.html'
));
}
else
{
next
();
}
service
.
sendCodeToUserAsync
(
inputInfo
.
type
,
inputInfo
.
phone
,
inputInfo
.
area
)
.
then
(
result
=>
{
if
(
_
.
isEmpty
(
result
))
{
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index.html'
));
}
else
{
next
();
}
}).
catch
(()
=>
{
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index.html'
));
});
})
.
catch
(()
=>
{
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index.html'
));
});
};
module
.
exports
.
saveInSession
=
(
req
,
res
)
=>
{
...
...
@@ -103,7 +105,7 @@ module.exports.saveInSession = (req, res) => {
case
'mobile'
:
{
req
.
session
.
mobile
=
req
.
inputInfo
.
phone
;
req
.
session
.
area
=
req
.
inputInfo
.
area
;
req
.
session
.
area
=
req
.
inputInfo
.
area
;
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/verification.html'
));
break
;
}
...
...
@@ -118,7 +120,8 @@ module.exports.sendBackMobileAPI = (req, res, next) => {
service
.
sendCodeToMobileAsync
(
area
,
mobile
)
.
then
(
result
=>
{
res
.
json
(
result
);
}).
catch
(
next
);
})
.
catch
(
next
);
};
module
.
exports
.
validateMobileAPI
=
(
req
,
res
,
next
)
=>
{
...
...
@@ -157,13 +160,13 @@ module.exports.sendEmailPage = (req, res, next) => {
.
then
(
result
=>
{
res
.
render
(
'back/send-email'
,
Object
.
assign
({
module
:
'passport'
,
page
:
'back-send-email-ok'
,
title
:
"邮件发送成功"
page
:
'back-send-email-ok'
,
title
:
"邮件发送成功"
},
{
sendEmail
:
{
coverHref
:
result
.
url
,
coverImg
:
result
.
img
,
email
:
req
.
body
.
emailUrl
coverImg
:
result
.
img
,
email
:
req
.
body
.
emailUrl
}
}));
}).
catch
(
next
);
...
...
@@ -185,7 +188,8 @@ module.exports.validateCodeByEmailPage = (req, res, next) => {
}
else
{
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index.html'
));
}
}).
catch
(
next
);
})
.
catch
(
next
);
};
module
.
exports
.
resetPasswordPage
=
(
req
,
res
,
next
)
=>
{
...
...
@@ -195,39 +199,40 @@ module.exports.resetPasswordPage = (req, res, next) => {
.
then
(
result
=>
{
res
.
render
(
'back/reset-pwd'
,
Object
.
assign
({
module
:
'passport'
,
page
:
'back-reset-pwd'
,
title
:
'重置密码'
page
:
'back-reset-pwd'
,
title
:
'重置密码'
},
{
resetPwd
:
Object
.
assign
({
coverHref
:
result
.
url
,
coverImg
:
result
.
img
,
code
:
code
coverImg
:
result
.
img
,
code
:
code
},
req
.
mobileAuth
)
}))
}).
catch
(
next
);
})
.
catch
(
next
);
};
/**
* 手机验证页面
*/
module
.
exports
.
verifyCodeByMobilePage
=
(
req
,
res
,
next
)
=>
{
passportHelper
.
getLeftBannerAsync
()
.
then
(
result
=>
{
res
.
render
(
'back/verification'
,
Object
.
assign
({
module
:
'passport'
,
page
:
'back-verify-mobile-code'
,
title
:
'手机验证'
page
:
'back-verify-mobile-code'
,
title
:
'手机验证'
},
{
verification
:
{
coverHref
:
result
.
url
,
coverImg
:
result
.
img
,
mobile
:
req
.
body
.
mobile
,
area
:
req
.
body
.
area
,
coverHref
:
result
.
url
,
coverImg
:
result
.
img
,
mobile
:
req
.
body
.
mobile
,
area
:
req
.
body
.
area
,
verifyCode
:
req
.
body
.
verifyCode
}
}));
}).
catch
(
next
);
})
.
catch
(
next
);
};
module
.
exports
.
checkSuccessStatusPage
=
(
req
,
res
,
next
)
=>
{
...
...
@@ -246,31 +251,28 @@ module.exports.resetPwdSuccessPage = (req, res, next) => {
.
then
(
result
=>
{
res
.
render
(
'back/reset-success'
,
Object
.
assign
({
module
:
'passport'
,
page
:
'back-index'
,
title
:
'重置密码成功'
page
:
'back-index'
,
title
:
'重置密码成功'
},
{
resetSuccess
:
{
coverHref
:
result
.
url
,
coverImg
:
result
.
img
coverImg
:
result
.
img
}
}))
}).
catch
(
next
);
})
.
catch
(
next
);
};
module
.
exports
.
verifyCodeByMobileAPI
=
(
req
,
res
)
=>
{
let
mobile
=
req
.
param
(
'mobile'
,
''
);
let
area
=
req
.
param
(
'area'
,
'86'
);
let
mobile
=
req
.
param
(
'mobile'
,
''
);
let
area
=
req
.
param
(
'area'
,
'86'
);
let
mobileCode
=
req
.
param
(
'code'
,
''
);
const
session
=
req
.
session
;
const
session
=
req
.
session
;
const
ERR
=
{
code
:
400
,
code
:
400
,
message
:
'验证码错误!'
,
data
:
helpers
.
urlFormat
(
'/passport/back/index.html'
)
data
:
helpers
.
urlFormat
(
'/passport/back/index.html'
)
};
if
(
!
code
||
mobile
!==
session
.
mobile
||
area
!==
session
.
area
)
{
...
...
@@ -298,8 +300,7 @@ module.exports.validateExistCodePage = (req, res, next) => {
};
module
.
exports
.
validateCodeByMobilePage
=
(
req
,
res
,
next
)
=>
{
let
code
=
req
.
param
(
'code'
,
''
);
let
code
=
req
.
param
(
'code'
,
''
);
let
mobile
=
req
.
param
(
'mobile'
,
''
);
if
(
!
mobile
)
{
...
...
@@ -309,13 +310,13 @@ module.exports.validateCodeByMobilePage = (req, res, next) => {
}
let
data
=
{
mobile
:
mobile
,
area
:
req
.
param
(
'area'
,
''
),
token
:
req
.
param
(
'token'
,
''
),
mobile
:
mobile
,
area
:
req
.
param
(
'area'
,
''
),
token
:
req
.
param
(
'token'
,
''
),
create_time
:
req
.
param
(
'create_time'
,
0
)
};
code
=
new
Buffer
(
code
,
'base64'
).
toString
();
code
=
new
Buffer
(
code
,
'base64'
).
toString
();
req
.
mobileAuth
=
service
.
authRequest
(
data
,
code
);
next
();
};
...
...
@@ -330,11 +331,9 @@ module.exports.validatePwdPage = (req, res, next) => {
}
};
module
.
exports
.
updatePwdAPI
=
(
req
,
res
)
=>
{
let
code
=
req
.
body
.
code
||
''
;
let
mobileAuth
=
req
.
mobileAuth
;
module
.
exports
.
updatePwdAPI
=
(
req
,
res
,
next
)
=>
{
let
code
=
req
.
body
.
code
||
''
;
let
mobileAuth
=
req
.
mobileAuth
;
let
newPassword
=
req
.
body
.
pwd
;
service
.
updatePwdAsync
(
code
,
mobileAuth
,
newPassword
)
...
...
@@ -345,13 +344,14 @@ module.exports.updatePwdAPI = (req, res) => {
}
else
{
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index.html'
));
}
});
})
.
catch
(
next
);
};
module
.
exports
.
validateMobileInSession
=
(
req
,
res
,
next
)
=>
{
req
.
body
.
mobile
=
req
.
session
.
mobile
||
""
;
req
.
body
.
mobile
=
req
.
session
.
mobile
||
""
;
req
.
body
.
verifyCode
=
req
.
session
.
verifyCode
||
""
;
req
.
body
.
area
=
req
.
session
.
area
||
""
;
req
.
body
.
area
=
req
.
session
.
area
||
""
;
if
(
req
.
body
.
mobile
&&
req
.
body
.
verifyCode
)
{
next
()
...
...
@@ -359,3 +359,4 @@ module.exports.validateMobileInSession = (req, res, next) => {
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index.html'
));
}
};
...
...
apps/passport/controllers/captcha.js
View file @
99e0da2
...
...
@@ -4,38 +4,40 @@
'use strict'
;
const
_
=
require
(
'lodash'
);
const
library
=
'../../../library'
;
const
captcha
=
require
(
'../models/captcha-service'
);
const
helpers
=
require
(
library
+
'/helpers'
);
exports
.
validateAPI
=
(
req
,
res
,
next
)
=>
{
const
validateAPI
=
(
req
,
res
,
next
)
=>
{
let
captchaToken
=
(
req
.
body
.
verifyCode
||
''
).
toLowerCase
();
if
(
captchaToken
===
req
.
session
.
captcha
)
{
next
();
return
;
return
next
();
}
else
{
return
res
.
json
({
code
:
400
,
code
:
400
,
message
:
'您输入的验证码不正确!'
});
}
};
exports
.
validatePage
=
(
req
,
res
,
next
)
=>
{
const
validatePage
=
(
req
,
res
,
next
)
=>
{
let
captchaToken
=
(
req
.
body
.
verifyCode
||
''
).
toLowerCase
();
if
(
captchaToken
===
req
.
session
.
captcha
)
{
next
();
return
;
return
next
();
}
else
{
return
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index.html'
));
}
};
exports
.
generatePage
=
(
req
,
res
,
next
)
=>
{
const
validate
=
(
req
,
res
,
next
)
=>
{
};
const
generatePage
=
(
req
,
res
,
next
)
=>
{
let
len
=
req
.
query
.
len
||
4
;
captcha
.
generateAsync
(
len
)
.
then
(
result
=>
{
req
.
session
.
captcha
=
result
.
text
.
toLowerCase
();
...
...
@@ -44,3 +46,10 @@ exports.generatePage = (req, res, next) => {
})
.
catch
(
next
);
};
module
.
exports
=
{
validateAPI
,
validatePage
,
validate
,
generatePage
,
};
...
...
apps/passport/models/back-api.js
View file @
99e0da2
...
...
@@ -2,15 +2,10 @@
* Created by TaoHuang on 2016/6/15.
*/
/**
* Created by Tao.Huang on 2016/6/14.
*/
'use strict'
;
var
API
=
require
(
'../../../library/api'
).
API
;
var
API
=
require
(
'../../../library/api'
).
API
;
const
library
=
'../../../library'
;
const
sign
=
require
(
`
$
{
library
}
/sign`
)
;
var
api
=
new
API
();
...
...
@@ -19,10 +14,10 @@ const YOHOBUY_URL = 'http://www.yohobuy.com/';
/**
* 获取地区数据
*/
module
.
exports
.
getAreaDataAsync
=
()
=>
{
return
api
.
get
(
''
,
sign
.
apiSign
({
const
getAreaDataAsync
=
()
=>
{
return
api
.
get
(
''
,
{
method
:
'app.passport.getArea'
})
)
.
then
(
result
=>
{
}).
then
(
result
=>
{
result
.
data
=
result
.
data
.
map
(
value
=>
{
value
.
areaCode
=
`
+
$
{
value
.
area
}
`
;
...
...
@@ -45,11 +40,11 @@ module.exports.getAreaDataAsync = () => {
*
* @param string mail 邮箱地址
*/
module
.
exports
.
sendCodeToEmailAsync
=
(
email
)
=>
{
return
api
.
get
(
''
,
sign
.
apiSign
({
const
sendCodeToEmailAsync
=
(
email
)
=>
{
return
api
.
get
(
''
,
{
method
:
'app.register.backpwdByEmail'
,
email
:
email
}));
email
:
email
});
};
/**
...
...
@@ -58,13 +53,13 @@ module.exports.sendCodeToEmailAsync = (email) => {
* @param string pwd 新密码
* @param string code 邮箱验证码
*/
module
.
exports
.
modifyPasswordByEmailAsync
=
(
pwd
,
code
)
=>
{
const
modifyPasswordByEmailAsync
=
(
pwd
,
code
)
=>
{
const
options
=
{
url
:
`
$
{
YOHOBUY_URL
}
passport
/
back
/
update
`
,
form
:
{
pwd
:
pwd
,
url
:
`
$
{
YOHOBUY_URL
}
passport
/
back
/
update
`
,
form
:
{
pwd
:
pwd
,
're-input'
:
pwd
,
code
:
code
code
:
code
},
timeout
:
3000
};
...
...
@@ -78,14 +73,14 @@ module.exports.modifyPasswordByEmailAsync = (pwd, code) => {
* @param string mobile 手机号
* @param integer area 地区码ID
*/
module
.
exports
.
sendCodeToMobileAsync
=
(
mobile
,
area
)
=>
{
const
sendCodeToMobileAsync
=
(
mobile
,
area
)
=>
{
area
=
area
||
86
;
return
api
.
get
(
''
,
sign
.
apiSign
(
{
return
api
.
get
(
''
,
{
mobile
:
mobile
,
area
:
area
,
area
:
area
,
method
:
'app.register.sendBackpwdCodeToMobile'
})
)
;
});
};
/**
...
...
@@ -95,14 +90,14 @@ module.exports.sendCodeToMobileAsync = (mobile, area) => {
* @param string code 验证码
* @param integer area 地区码ID
*/
module
.
exports
.
validateMobileCodeAsync
=
(
mobile
,
code
,
area
)
=>
{
const
validateMobileCodeAsync
=
(
mobile
,
code
,
area
)
=>
{
area
=
area
||
86
;
return
api
.
get
(
''
,
sign
.
apiSign
(
{
return
api
.
get
(
''
,
{
mobile
:
mobile
,
code
:
code
,
area
:
area
,
code
:
code
,
area
:
area
,
method
:
'app.register.validBackpwdCode'
})
)
;
});
};
/**
...
...
@@ -112,34 +107,45 @@ module.exports.validateMobileCodeAsync = (mobile, code, area) => {
* @param string token 验证手机验证码返回的token
* @param integer area 地区码ID
*/
module
.
exports
.
modifyPasswordByMobileAsync
=
(
mobile
,
token
,
newpwd
,
area
)
=>
{
const
modifyPasswordByMobileAsync
=
(
mobile
,
token
,
newpwd
,
area
)
=>
{
area
=
area
||
86
;
return
api
.
get
(
''
,
sign
.
apiSign
(
{
return
api
.
get
(
''
,
{
mobile
:
mobile
,
token
:
token
,
token
:
token
,
newpwd
:
newpwd
,
area
:
area
,
area
:
area
,
method
:
'app.register.changepwdByMobileCode'
})
)
;
});
};
/**
* 验证找回邮件code
*/
module
.
exports
.
checkEmailCodeAsync
=
(
code
)
=>
{
return
api
.
get
(
''
,
sign
.
apiSign
({
code
:
code
,
const
checkEmailCodeAsync
=
(
code
)
=>
{
return
api
.
get
(
''
,
{
code
:
code
,
method
:
'web.passport.checkCodeValid'
})
)
;
});
};
/**
* 根据邮箱code修改密码
*/
module
.
exports
.
modifyPasswordByEmailCodeAsync
=
(
code
,
password
)
=>
{
return
api
.
get
(
''
,
sign
.
apiSign
({
code
:
code
,
const
modifyPasswordByEmailCodeAsync
=
(
code
,
password
)
=>
{
return
api
.
get
(
''
,
{
code
:
code
,
newPwd
:
password
,
method
:
'app.register.resetPwdByCode'
}));
});
};
module
.
exports
=
{
getAreaDataAsync
,
sendCodeToEmailAsync
,
modifyPasswordByEmailAsync
,
sendCodeToMobileAsync
,
validateMobileCodeAsync
,
modifyPasswordByMobileAsync
,
checkEmailCodeAsync
,
modifyPasswordByEmailCodeAsync
};
...
...
apps/passport/models/back-service.js
View file @
99e0da2
...
...
@@ -5,31 +5,31 @@
'use strict'
;
const
helpers
=
require
(
`
$
{
library
}
/helpers`
)
;
const
api
=
require
(
'./back-api'
);
const
api
=
require
(
'./back-api'
);
const
Promise
=
require
(
'bluebird'
);
const
co
=
Promise
.
coroutine
;
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
const
co
=
Promise
.
coroutine
;
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
const
userService
=
require
(
'./user-service'
);
const
userService
=
require
(
'./user-service'
);
const
passportHelper
=
require
(
'./passport-helper'
);
const
authHelper
=
require
(
'./auth-helper'
);
const
authHelper
=
require
(
'./auth-helper'
);
const
BACK_LEFT_BANNER_CODE
=
'3bbaf502c447a2ddad60879042e286d8'
;
//找回密码左边的banner
module
.
exports
.
validateEmailOrMobileAsync
=
(
userInput
,
areaCode
)
=>
{
const
validateEmailOrMobileAsync
=
(
userInput
,
areaCode
)
=>
{
return
new
Promise
(
function
(
resolve
,
rejected
)
{
let
result
=
{
type
:
'email'
,
area
:
''
,
phone
:
''
};
if
(
helpers
.
verifyEmail
(
userInput
))
{
result
.
type
=
'email'
;
result
.
area
=
''
;
result
.
type
=
'email'
;
result
.
area
=
''
;
result
.
phone
=
userInput
;
resolve
(
result
);
}
else
if
(
helpers
.
verifyAreaMobile
(
helpers
.
makeAreaMobile
(
areaCode
,
userInput
)))
{
result
.
type
=
'mobile'
;
result
.
area
=
areaCode
;
result
.
type
=
'mobile'
;
result
.
area
=
areaCode
;
result
.
phone
=
userInput
;
resolve
(
result
);
...
...
@@ -40,16 +40,16 @@ module.exports.validateEmailOrMobileAsync = (userInput, areaCode) => {
};
module
.
exports
.
findUserAsync
=
(
type
,
phone
,
area
)
=>
{
const
findUserAsync
=
(
type
,
phone
,
area
)
=>
{
return
co
(
function
*
()
{
const
MESSAGE
=
{
mobile
:
'您输入的手机号码尚未注册!'
,
email
:
'您输入的邮件账户尚未注册!'
,
ok
:
'验证成功'
email
:
'您输入的邮件账户尚未注册!'
,
ok
:
'验证成功'
};
const
findBy
=
{
email
:
userService
.
findByEmailAsync
,
email
:
userService
.
findByEmailAsync
,
mobile
:
userService
.
findByMobileAsync
};
...
...
@@ -59,7 +59,7 @@ module.exports.findUserAsync = (type, phone, area) => {
if
(
_
.
isEmpty
(
user
))
{
return
{
code
:
402
,
code
:
402
,
message
:
MESSAGE
[
type
]
};
}
...
...
@@ -68,7 +68,7 @@ module.exports.findUserAsync = (type, phone, area) => {
})();
};
function
sendCodeToEmailAsync
(
input
)
{
const
_sendCodeToEmailAsync
=
input
=>
{
return
api
.
sendCodeToEmailAsync
(
input
).
then
(
result
=>
{
if
(
!
result
.
code
||
result
.
code
!==
200
)
{
return
Promise
.
reject
(
'request error!'
);
...
...
@@ -80,7 +80,7 @@ function sendCodeToEmailAsync(input) {
});
}
function
sendCodeToMobileAsync
(
areaCode
,
userInput
)
{
const
_sendCodeToMobileAsync
=
(
areaCode
,
userInput
)
=>
{
return
api
.
sendCodeToMobileAsync
(
areaCode
,
userInput
).
then
(
result
=>
{
if
(
!
result
.
code
||
result
.
code
!==
200
)
{
return
Promise
.
reject
(
'request error'
);
...
...
@@ -92,10 +92,10 @@ function sendCodeToMobileAsync(areaCode, userInput) {
});
}
module
.
exports
.
sendCodeToUserAsync
=
(
type
,
mobile
,
areaCode
)
=>
{
const
sendCodeToUserAsync
=
(
type
,
mobile
,
areaCode
)
=>
{
let
sendTo
=
{
email
:
sendCodeToEmailAsync
,
mobile
:
sendCodeToMobileAsync
email
:
_sendCodeToEmailAsync
,
mobile
:
_sendCodeToMobileAsync
};
return
sendTo
[
type
](
mobile
,
areaCode
);
...
...
@@ -104,36 +104,36 @@ module.exports.sendCodeToUserAsync = (type, mobile, areaCode) => {
/**
* 发送找回手机号短信
*/
module
.
exports
.
sendCodeToMobileAsync
=
(
areaCode
,
mobile
)
=>
{
const
sendCodeToMobileAsync
=
(
areaCode
,
mobile
)
=>
{
return
api
.
sendCodeToMobileAsync
(
mobile
,
areaCode
);
};
/**
* 获得首页的数据
*/
module
.
exports
.
indexPageDataAsync
=
()
=>
{
const
indexPageDataAsync
=
()
=>
{
return
co
(
function
*
()
{
let
banner
=
yield
passportHelper
.
getLeftBannerAsync
(
BACK_LEFT_BANNER_CODE
);
let
banner
=
yield
passportHelper
.
getLeftBannerAsync
(
BACK_LEFT_BANNER_CODE
);
let
countryList
=
passportHelper
.
getCountry
();
return
{
back
:
{
coverHref
:
banner
.
url
,
coverImg
:
banner
.
img
,
coverHref
:
banner
.
url
,
coverImg
:
banner
.
img
,
countryCode
:
86
,
countryName
:
"中国"
,
captchaUrl
:
helpers
.
urlFormat
(
'/passport/images'
,
{
t
:
moment
().
unix
()}),
captchaUrl
:
helpers
.
urlFormat
(
'/passport/images'
,
{
t
:
moment
().
unix
()}),
countryList
:
countryList
}
}
})();
};
module
.
exports
.
verifyCodyByMobileAsync
=
(
area
,
mobile
,
mobileCode
)
=>
{
const
verifyCodyByMobileAsync
=
(
area
,
mobile
,
mobileCode
)
=>
{
const
ERR
=
{
code
:
400
,
code
:
400
,
message
:
'验证码错误!'
,
data
:
helpers
.
urlFormat
(
'/passport/back/index.html'
)
data
:
helpers
.
urlFormat
(
'/passport/back/index.html'
)
};
api
.
validateMobileCodeAsync
(
mobile
,
mobileCode
,
area
)
...
...
@@ -143,29 +143,28 @@ module.exports.verifyCodyByMobileAsync = (area, mobile, mobileCode) => {
}
let
data
=
{
mobile
:
mobile
,
area
:
area
,
token
:
result
.
data
.
token
,
mobile
:
mobile
,
area
:
area
,
token
:
result
.
data
.
token
,
create_time
:
moment
().
unix
()
};
data
.
code
=
new
Buffer
(
authHelper
.
makeToken
(
data
)).
toString
(
'base64'
);
return
{
code
:
200
,
code
:
200
,
message
:
'验证成功'
,
data
:
helpers
.
urlFormat
(
'/passport/back/backcode'
,
data
)
data
:
helpers
.
urlFormat
(
'/passport/back/backcode'
,
data
)
};
})
};
module
.
exports
.
authRequest
=
(
data
,
token
)
=>
{
const
authRequest
=
(
data
,
token
)
=>
{
if
(
!
authHelper
.
validateToken
(
data
,
token
))
{
return
{};
}
let
existTime
=
moment
.
duration
(
1
,
'hours'
).
seconds
();
let
existTime
=
moment
.
duration
(
1
,
'hours'
).
seconds
();
let
isExpired
=
(
moment
().
unix
()
-
data
.
create_time
)
>
existTime
;
if
(
isExpired
)
{
...
...
@@ -175,44 +174,49 @@ module.exports.authRequest = (data, token) => {
}
};
module
.
exports
.
updatePwdAsync
=
(
emailToken
,
mobileToken
,
newPassword
)
=>
{
const
updatePwdAsync
=
(
emailToken
,
mobileToken
,
newPassword
)
=>
{
return
co
(
function
*
()
{
let
result
=
{
type
:
'mobile'
,
status
:
false
};
const
ERR
=
{
type
:
''
,
status
:
false
};
const
ERR
=
{
type
:
''
,
status
:
false
};
if
(
!
_
.
isEmpty
(
mobileToken
))
{
if
(
!
mobileToken
.
mobile
||
mobileToken
.
uid
)
{
return
ERR
;
}
let
mobile
=
mobileToken
.
mobile
;
let
area
=
mobileToken
.
area
;
let
token
=
mobileToken
.
token
;
let
mobile
=
mobileToken
.
mobile
;
let
area
=
mobileToken
.
area
;
let
token
=
mobileToken
.
token
;
let
modifyStatus
=
yield
api
.
modifyPasswordByMobileAsync
(
mobile
,
token
,
newPassword
,
area
);
let
data
=
yield
api
.
modifyPasswordByMobileAsync
(
mobile
,
token
,
newPassword
,
area
);
if
(
!
data
.
code
||
data
.
code
!==
200
)
{
if
(
!
modifyStatus
.
code
||
modifyStatus
.
code
!==
200
)
{
return
ERR
;
}
result
.
type
=
'mobile'
;
result
.
type
=
'mobile'
;
result
.
status
=
true
;
}
else
{
let
data
=
yield
api
.
modifyPasswordByEmailCodeAsync
(
emailToken
,
newPassword
);
let
modifyStatus
=
yield
api
.
modifyPasswordByEmailCodeAsync
(
emailToken
,
newPassword
);
if
(
!
data
.
code
||
data
.
code
!==
200
)
{
if
(
!
modifyStatus
.
code
||
modifyStatus
.
code
!==
200
)
{
return
ERR
;
}
result
.
type
=
'email'
;
result
.
type
=
'email'
;
result
.
status
=
true
;
}
return
result
;
})();
};
module
.
exports
=
{
validateEmailOrMobileAsync
,
findUserAsync
,
sendCodeToUserAsync
,
sendCodeToMobileAsync
,
indexPageDataAsync
,
verifyCodyByMobileAsync
,
authRequest
,
updatePwdAsync
};
...
...
apps/passport/models/captcha-service.js
View file @
99e0da2
...
...
@@ -7,7 +7,7 @@ const Promise = require('bluebird');
const
co
=
Promise
.
coroutine
;
const
fs
=
require
(
'fs'
);
module
.
exports
.
generateAsync
=
()
=>
{
const
generateAsync
=
()
=>
{
const
path
=
'./fake_captcha_mer2.png'
;
const
readFileAsync
=
Promise
.
promisify
(
fs
.
readFile
);
...
...
@@ -22,3 +22,7 @@ module.exports.generateAsync = () => {
}
})();
};
module
.
exports
=
{
generateAsync
};
...
...
apps/passport/models/index-api.js
View file @
99e0da2
...
...
@@ -3,15 +3,11 @@
*/
'use strict'
;
const
library
=
'../../../library'
;
var
ServiceAPI
=
require
(
library
+
"/api"
).
ServiceAPI
;
const
sign
=
require
(
`
$
{
library
}
/sign`
)
;
const
_
=
require
(
'lodash'
);
var
serviceAPI
=
new
ServiceAPI
();
const
ServiceAPI
=
require
(
library
+
"/api"
).
ServiceAPI
;
const
serviceAPI
=
new
ServiceAPI
();
module
.
exports
.
getResourceAsync
=
(
resourceCode
)
=>
{
return
serviceAPI
.
get
(
'/operations/api/v5/resource/get'
,
sign
.
apiSign
(
{
return
serviceAPI
.
get
(
'/operations/api/v5/resource/get'
,
{
content_code
:
resourceCode
})
,
true
)
;
});
};
...
...
apps/passport/models/index-service.js
View file @
99e0da2
...
...
@@ -12,7 +12,8 @@ module.exports.getResourceAsync = (resourceCode) => {
}
else
{
return
{};
}
}).
catch
(()
=>
{
})
.
catch
(()
=>
{
return
{};
});
};
...
...
apps/passport/models/passport-helper.js
View file @
99e0da2
...
...
@@ -7,8 +7,8 @@
const
helpers
=
require
(
library
+
'/helpers'
);
const
Promise
=
require
(
'bluebird'
);
const
co
=
Promise
.
coroutine
;
const
_
=
require
(
'lodash'
);
const
co
=
Promise
.
coroutine
;
const
_
=
require
(
'lodash'
);
const
indexService
=
require
(
'./index-service'
);
...
...
@@ -20,7 +20,6 @@ module.exports.getLeftBannerAsync = (resourceCode) => {
};
return
co
(
function
*
()
{
let
resource
=
yield
indexService
.
getResourceAsync
(
resourceCode
);
if
(
_
.
isEmpty
(
resource
))
{
...
...
@@ -41,62 +40,62 @@ module.exports.getCountry = () => {
{
areaCode
:
'+61'
,
selected
:
false
,
name
:
'澳大利亚'
name
:
'澳大利亚'
},
{
areaCode
:
'+82'
,
selected
:
false
,
name
:
'韩国'
name
:
'韩国'
},
{
areaCode
:
'+1'
,
selected
:
false
,
name
:
'加拿大'
name
:
'加拿大'
},
{
areaCode
:
'+60'
,
selected
:
false
,
name
:
'马来西亚'
name
:
'马来西亚'
},
{
areaCode
:
'+1'
,
selected
:
false
,
name
:
'美国'
name
:
'美国'
},
{
areaCode
:
'+81'
,
selected
:
false
,
name
:
'日本'
name
:
'日本'
},
{
areaCode
:
'+65'
,
selected
:
false
,
name
:
'新加坡'
name
:
'新加坡'
},
{
areaCode
:
'+44'
,
selected
:
false
,
name
:
'英国'
name
:
'英国'
},
{
areaCode
:
'+86'
,
selected
:
true
,
name
:
'中国'
name
:
'中国'
},
{
areaCode
:
'+853'
,
selected
:
false
,
name
:
'中国澳门'
name
:
'中国澳门'
},
{
areaCode
:
'+886'
,
selected
:
false
,
name
:
'中国台湾'
name
:
'中国台湾'
},
{
areaCode
:
'+852'
,
selected
:
false
,
name
:
'中国香港'
name
:
'中国香港'
}
];
};
...
...
apps/passport/models/user-api.js
View file @
99e0da2
...
...
@@ -4,49 +4,56 @@
'use strict'
;
const
library
=
'../../../library'
;
var
API
=
require
(
'../../../library/api'
).
API
;
const
sign
=
require
(
`
$
{
library
}
/sign`
)
;
const
_
=
require
(
'lodash'
);
var
api
=
new
API
();
const
API
=
require
(
'../../../library/api'
).
API
;
const
_
=
require
(
'lodash'
);
const
api
=
new
API
();
const
EMPTY
=
{};
/**
* 根据手机号获取用户信息
*/
module
.
exports
.
findByMobileAsync
=
(
area
,
mobile
)
=>
{
return
api
.
get
(
''
,
sign
.
apiSign
({
mobile
:
mobile
,
area
:
area
,
method
:
'app.passport.getProfileByMobile'
})).
then
(
result
=>
{
if
(
!
result
.
code
||
result
.
code
!==
200
||
!
result
.
data
||
_
.
isEmpty
(
result
.
data
))
{
const
findByMobileAsync
=
(
area
,
mobile
)
=>
{
return
api
.
get
(
''
,
{
mobile
:
mobile
,
area
:
area
,
method
:
'app.passport.getProfileByMobile'
})
.
then
(
result
=>
{
if
(
!
result
.
code
||
result
.
code
!==
200
||
!
result
.
data
||
_
.
isEmpty
(
result
.
data
))
{
return
EMPTY
;
}
return
result
.
data
;
})
.
catch
(()
=>
{
return
EMPTY
;
}
return
result
.
data
;
}).
catch
(()
=>
{
return
EMPTY
;
});
});
};
/**
* 根据邮箱获取用户信息
*/
module
.
exports
.
findByEmailAsync
=
(
email
)
=>
{
return
api
.
get
(
''
,
sign
.
apiSign
({
email
:
email
,
method
:
'app.passport.getProfileByEmail'
})).
then
(
result
=>
{
if
(
!
result
.
code
||
result
.
code
!==
200
||
!
result
.
data
||
_
.
isEmpty
(
result
.
data
))
{
const
findByEmailAsync
=
(
email
)
=>
{
return
api
.
get
(
''
,
{
email
:
email
,
method
:
'app.passport.getProfileByEmail'
})
.
then
(
result
=>
{
if
(
!
result
.
code
||
result
.
code
!==
200
||
!
result
.
data
||
_
.
isEmpty
(
result
.
data
))
{
return
EMPTY
;
}
return
result
.
data
;
})
.
catch
(()
=>
{
return
EMPTY
;
}
return
result
.
data
;
});
};
}).
catch
(()
=>
{
return
EMPTY
;
});
module
.
exports
=
{
findByMobileAsync
,
findByEmailAsync
};
...
...
apps/passport/models/user-service.js
View file @
99e0da2
...
...
@@ -5,6 +5,4 @@
const
api
=
require
(
'./user-api'
);
module
.
exports
.
findByEmailAsync
=
api
.
findByEmailAsync
;
module
.
exports
.
findByMobileAsync
=
api
.
findByMobileAsync
;
module
.
exports
=
api
;
...
...
apps/passport/router.js
View file @
99e0da2
...
...
@@ -7,11 +7,11 @@
'use strict'
;
const
express
=
require
(
'express'
);
const
cRoot
=
'./controllers'
;
const
login
=
require
(
cRoot
+
'/login'
);
const
cRoot
=
'./controllers'
;
const
login
=
require
(
cRoot
+
'/login'
);
const
Captcha
=
require
(
cRoot
+
'/captcha'
);
const
Back
=
require
(
cRoot
+
'/back'
);
const
Back
=
require
(
cRoot
+
'/back'
);
const
router
=
express
.
Router
();
// eslint-disable-line
...
...
@@ -25,47 +25,78 @@ router.get('/login/wechat/callback', login.wechat.callback);
router
.
get
(
'/back/index.html'
,
Back
.
indexPage
);
// 实时验证输入是否正确
router
.
post
(
'/back/authcode'
,
Captcha
.
validateAPI
,
Back
.
validateInputAPI
,
Back
.
getUserInfoAPI
);
router
.
post
(
'/back/authcode'
,
Captcha
.
validateAPI
,
Back
.
validateInputAPI
,
Back
.
getUserInfoAPI
);
// 提交按钮邮件API
router
.
post
(
'/back/email'
,
Captcha
.
validatePage
,
Back
.
validateUserPage
,
Back
.
sendCodePage
,
Back
.
saveInSession
);
router
.
post
(
'/back/email'
,
Captcha
.
validatePage
,
Back
.
validateUserPage
,
Back
.
sendCodePage
,
Back
.
saveInSession
);
// 提交按钮手机API
router
.
post
(
'/back/mobile'
,
Captcha
.
validatePage
,
Back
.
validateUserPage
,
Back
.
sendCodePage
,
Back
.
saveInSession
);
router
.
post
(
'/back/mobile'
,
Captcha
.
validatePage
,
Back
.
validateUserPage
,
Back
.
sendCodePage
,
Back
.
saveInSession
);
/**
* 邮件找回密码
*/
// 发送邮件成功页面
router
.
get
(
'/back/sendEmail.html'
,
Back
.
validateEmailInSession
,
Back
.
sendEmailPage
);
router
.
get
(
'/back/sendEmail.html'
,
Back
.
validateEmailInSession
,
Back
.
sendEmailPage
);
/**
* 短信找回密码
*/
// 验证手机短信页面
router
.
get
(
'/back/verification.html'
,
Back
.
validateMobileInSession
,
Captcha
.
validatePage
,
Back
.
verifyCodeByMobilePage
);
router
.
get
(
'/back/verification.html'
,
Back
.
validateMobileInSession
,
Captcha
.
validatePage
,
Back
.
verifyCodeByMobilePage
);
// 重新发送短信接口
router
.
post
(
'/back/sendBackMobile'
,
Captcha
.
validateAPI
,
Back
.
validateMobileAPI
,
Back
.
sendBackMobileAPI
);
router
.
post
(
'/back/sendBackMobile'
,
Captcha
.
validateAPI
,
Back
.
validateMobileAPI
,
Back
.
sendBackMobileAPI
);
// 验证手机验证码接口
router
.
post
(
'/back/backMobile'
,
Captcha
.
validateAPI
,
Back
.
verifyCodeByMobileAPI
);
router
.
post
(
'/back/backMobile'
,
Captcha
.
validateAPI
,
Back
.
verifyCodeByMobileAPI
);
/**
* 重置密码
*/
// 重置密码页面
router
.
get
(
'/back/backcode'
,
Back
.
validateExistCodePage
,
Back
.
validateCodeByMobilePage
,
Back
.
validateCodeByEmailPage
,
Back
.
resetPasswordPage
);
router
.
get
(
'/back/backcode'
,
Back
.
validateExistCodePage
,
Back
.
validateCodeByMobilePage
,
Back
.
validateCodeByEmailPage
,
Back
.
resetPasswordPage
);
// 重置密码接口
router
.
post
(
'/back/update'
,
Back
.
validateExistCodePage
,
Back
.
validateCodeByMobilePage
,
Back
.
validatePwdPage
,
Back
.
updatePwdAPI
);
router
.
post
(
'/back/update'
,
Back
.
validateExistCodePage
,
Back
.
validateCodeByMobilePage
,
Back
.
validatePwdPage
,
Back
.
updatePwdAPI
);
// 重置密码成功页面
router
.
get
(
'/back/resetSuccess.html'
,
Back
.
checkSuccessStatusPage
,
Back
.
resetPwdSuccessPage
);
router
.
get
(
'/back/resetSuccess.html'
,
Back
.
checkSuccessStatusPage
,
Back
.
resetPwdSuccessPage
);
/**
* 验证码生成
*/
router
.
get
(
'/images'
,
Captcha
.
generatePage
);
router
.
get
(
'/images'
,
Captcha
.
generatePage
);
module
.
exports
=
router
;
...
...
Please
register
or
login
to post a comment