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
c750988dc50ac03d4f787d9d6ca34cbeef70f054
1 parent
fb3f154d
update captcha
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
35 deletions
apps/passport/controllers/back.js
apps/passport/controllers/captcha.js
apps/passport/models/captcha-service.js
apps/passport/router.js
apps/passport/controllers/back.js
View file @
c750988
...
...
@@ -48,7 +48,7 @@ const validateInputAPI = (req, res, next) => {
/**
* 校验用户输入信息,是否是已经注册的用户
*/
const
validate
User
Page
=
(
req
,
res
,
next
)
=>
{
const
validate
Input
Page
=
(
req
,
res
,
next
)
=>
{
let
userInput
=
req
.
body
.
phoneNum
||
''
;
let
areaCode
=
(
req
.
body
.
area
||
'86'
).
replace
(
'+'
,
''
);
...
...
@@ -78,6 +78,7 @@ const sendCodePage = (req, res, next) => {
service
.
sendCodeToUserAsync
(
inputInfo
.
type
,
inputInfo
.
phone
,
inputInfo
.
area
)
.
then
(
result
=>
{
if
(
!
(
result
.
code
&&
result
.
code
===
200
))
{
console
.
log
(
result
);
return
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index'
));
}
...
...
@@ -98,6 +99,7 @@ const saveInSession = (req, res) => {
{
req
.
session
.
mobile
=
req
.
inputInfo
.
phone
;
req
.
session
.
area
=
req
.
inputInfo
.
area
;
req
.
session
.
verifyCode
=
req
.
session
.
captcha
;
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/verification'
));
break
;
}
...
...
@@ -138,9 +140,9 @@ const validateEmailInSession = (req, res, next) => {
return
res
.
redirect
(
helpers
.
urlFormat
(
'/passport/back/index'
));
}
let
isp
=
email
.
split
(
'@'
)[
1
];
let
isp
=
email
.
split
(
'@'
)[
1
]
.
toLowerCase
()
;
const
mapperEmailISP
=
{
'yoho.cn'
:
'http://
smail.yoho.c
n'
'yoho.cn'
:
'http://
exmail.qq.com/logi
n'
};
req
.
body
.
emailUrl
=
mapperEmailISP
[
isp
]
||
`
http
:
//mail.${isp}`;
...
...
@@ -254,9 +256,9 @@ const resetPwdSuccessPage = (req, res, next) => {
};
const
verifyCodeByMobileAPI
=
(
req
,
res
)
=>
{
let
mobile
=
req
.
param
(
'mobile'
,
''
);
let
area
=
req
.
param
(
'area'
,
'86'
);
let
mobileCode
=
req
.
param
(
'code'
,
''
);
let
mobile
=
req
.
body
.
mobile
||
''
;
let
area
=
req
.
body
.
area
||
'86'
;
let
mobileCode
=
req
.
body
.
code
||
''
;
const
ERR
=
{
code
:
400
,
message
:
'验证码错误!'
,
...
...
@@ -279,7 +281,6 @@ const verifyCodeByMobileAPI = (req, res) => {
};
const
validateExistCodePage
=
(
req
,
res
,
next
)
=>
{
let
code
=
req
.
query
.
code
||
req
.
body
.
code
;
if
(
!
code
)
{
...
...
@@ -343,7 +344,7 @@ const updatePwdAPI = (req, res, next) => {
const
validateMobileInSession
=
(
req
,
res
,
next
)
=>
{
req
.
body
.
mobile
=
req
.
session
.
mobile
||
''
;
req
.
body
.
verifyCode
=
req
.
session
.
verifyCode
||
''
;
req
.
body
.
verifyCode
=
req
.
session
.
captcha
||
''
;
req
.
body
.
area
=
req
.
session
.
area
||
''
;
if
(
!
(
req
.
body
.
mobile
&&
req
.
body
.
verifyCode
))
{
...
...
@@ -371,7 +372,7 @@ module.exports = {
resetPwdSuccessPage
,
// 重设密码成功页面
validateInputAPI
,
// 验证用户输入的邮箱或者手机是否合法,返回是json
validate
UserPage
,
// 验证用户输入的邮箱或者手机是否合法,跳转是页面
validate
InputPage
,
// 验证用户输入的邮箱或者手机是否合法,跳转是页面
validateEmailInSession
,
// 验证邮箱是否在session中
validateMobileInSession
,
// 验证手机是否在session中
...
...
apps/passport/controllers/captcha.js
View file @
c750988
...
...
@@ -4,13 +4,11 @@
'use strict'
;
const
Captchapng
=
require
(
'captchapng'
);
const
_
=
require
(
'lodash'
);
const
captchaService
=
require
(
'../models/captcha-service'
);
const
helpers
=
global
.
yoho
.
helpers
;
const
requiredAPI
=
(
req
,
res
,
next
)
=>
{
let
captchaToken
=
+
(
req
.
body
.
verifyCode
||
''
).
toLowerCase
()
;
let
captchaToken
=
req
.
body
.
verifyCode
||
''
;
if
(
captchaToken
===
req
.
session
.
captcha
)
{
return
next
();
...
...
@@ -23,7 +21,7 @@ const requiredAPI = (req, res, next) => {
};
const
requiredPage
=
(
req
,
res
,
next
)
=>
{
let
captchaToken
=
+
(
req
.
body
.
verifyCode
||
''
).
toLowerCase
()
;
let
captchaToken
=
req
.
body
.
verifyCode
||
''
;
if
(
captchaToken
===
req
.
session
.
captcha
)
{
return
next
();
...
...
@@ -32,28 +30,11 @@ const requiredPage = (req, res, next) => {
}
};
const
_generateCaptcha
=
(
width
,
height
,
length
)
=>
{
let
min
=
Math
.
pow
(
10
,
(
length
-
1
||
1
));
let
max
=
Math
.
pow
(
10
,
(
length
-
1
||
1
))
*
9
;
let
token
=
''
+
_
.
random
(
min
,
max
);
let
png
=
new
Captchapng
(
width
,
height
,
token
);
//
png
.
color
(
0
,
0
,
0
,
0
);
// First color: background (red, green, blue, alpha)
png
.
color
(
80
,
80
,
80
,
255
);
// Second color: paint (red, green, blue, alpha)
return
{
image
:
new
Buffer
(
png
.
getBase64
(),
'base64'
),
text
:
token
};
};
const
generate
=
(
req
,
res
)
=>
{
let
width
=
req
.
query
.
w
||
150
;
let
height
=
req
.
query
.
h
||
50
;
let
length
=
+
(
req
.
query
.
l
||
4
);
let
captcha
=
_
generateCaptcha
(
width
,
height
,
length
);
let
captcha
=
captchaService
.
generateCaptcha
(
width
,
height
,
length
);
req
.
session
.
captcha
=
captcha
.
text
;
res
.
writeHead
(
200
,
{
...
...
apps/passport/models/captcha-service.js
0 → 100644
View file @
c750988
/**
* Created by TaoHuang on 2016/7/1.
*/
'use strict'
;
const
_
=
require
(
'lodash'
);
const
Captchapng
=
require
(
'captchapng'
);
exports
.
generateCaptcha
=
(
width
,
height
,
length
)
=>
{
let
min
=
Math
.
pow
(
10
,
(
length
-
1
||
1
));
let
max
=
Math
.
pow
(
10
,
(
length
-
1
||
1
))
*
9
;
let
token
=
''
+
_
.
random
(
min
,
max
);
let
png
=
new
Captchapng
(
width
,
height
,
token
);
//
png
.
color
(
0
,
0
,
0
,
0
);
// First color: background (red, green, blue, alpha)
png
.
color
(
80
,
80
,
80
,
255
);
// Second color: paint (red, green, blue, alpha)
return
{
image
:
new
Buffer
(
png
.
getBase64
(),
'base64'
),
text
:
token
};
};
...
...
apps/passport/router.js
View file @
c750988
...
...
@@ -84,14 +84,14 @@ router.post('/back/authcode',
// 提交按钮邮件API
router
.
post
(
'/back/email'
,
captcha
.
requiredPage
,
back
.
validate
User
Page
,
back
.
validate
Input
Page
,
back
.
sendCodePage
,
back
.
saveInSession
);
// 提交按钮手机API
router
.
post
(
'/back/mobile'
,
captcha
.
requiredPage
,
back
.
validate
User
Page
,
back
.
validate
Input
Page
,
back
.
sendCodePage
,
back
.
saveInSession
);
...
...
@@ -108,7 +108,6 @@ router.get('/back/sendEmail',
*/
// 验证手机短信页面
router
.
get
(
'/back/verification'
,
captcha
.
requiredPage
,
back
.
validateMobileInSession
,
back
.
verifyCodeByMobilePage
);
...
...
Please
register
or
login
to post a comment