Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-blk
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
1
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
王水玲
8 years ago
Commit
f401cc572fa863379cce2bcbdab64c854cd3503e
1 parent
ac31657d
短信手机验证
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
43 deletions
apps/passport/controllers/captcha.js
apps/passport/controllers/login.js
apps/passport/router.js
public/js/passport/login/index.js
apps/passport/controllers/captcha.js
View file @
f401cc5
...
...
@@ -57,6 +57,7 @@ const generate = (req, res) => {
let
length
=
+
(
req
.
query
.
l
||
4
);
let
captcha
=
captchaService
.
generateCaptcha
(
width
,
height
,
length
);
req
.
session
.
sendMobile
=
''
;
req
.
session
.
captcha
=
captcha
.
text
;
req
.
session
.
captchaCount
=
0
;
...
...
@@ -97,31 +98,9 @@ const requiredPost = (req, res) => {
}
};
const
checkSendMobile
=
(
req
,
res
,
fromNode
,
mobile
)
=>
{
if
(
fromNode
)
{
// node中判断
if
(
req
.
session
.
sendMobile
&&
req
.
session
.
sendMobile
!==
mobile
)
{
return
true
;
}
else
{
return
false
;
}
}
if
(
req
.
session
.
sendMobile
&&
req
.
session
.
sendMobile
!==
req
.
query
.
mobile
)
{
// ajax中判断
return
res
.
json
({
code
:
400
,
message
:
'验证码已失效'
});
}
else
{
return
res
.
json
({
code
:
200
,
data
:
{}
});
}
};
module
.
exports
=
{
requiredAPI
,
requiredPage
,
generate
,
requiredPost
,
checkSendMobile
requiredPost
};
...
...
apps/passport/controllers/login.js
View file @
f401cc5
...
...
@@ -242,6 +242,15 @@ const local = {
});
}
if
(
req
.
session
.
sendMobile
&&
req
.
session
.
sendMobile
!==
mobile
)
{
// ajax中判断
req
.
session
.
sendMobile
=
''
;
req
.
session
.
captcha
=
''
;
return
res
.
json
({
code
:
400
,
message
:
'验证码已失效'
});
}
LoginService
.
sendPasswordBySMS
(
area
,
mobile
).
then
((
result
)
=>
{
if
(
result
&&
result
.
code
===
200
)
{
req
.
session
.
sendMobile
=
mobile
;
...
...
apps/passport/router.js
View file @
f401cc5
...
...
@@ -159,6 +159,5 @@ router.get('/back/resetSuccess',
router
.
get
(
'/images'
,
captcha
.
generate
);
router
.
post
(
'/images/check'
,
captcha
.
requiredPost
);
router
.
get
(
'/captcha/checkSendMobile'
,
captcha
.
checkSendMobile
);
module
.
exports
=
router
;
...
...
public/js/passport/login/index.js
View file @
f401cc5
...
...
@@ -48,7 +48,7 @@ var upDown = {
var
selectedIcon
=
''
;
// 短信验证码的计数器,60s
var
secondCount
=
5
;
var
secondCount
=
60
;
// 短信验证码只能验证一次
var
isSmsCheckedSuccessFlag
=
false
;
...
...
@@ -486,7 +486,7 @@ ep.on('smsCode', function(auth) {
function
disable60sSendSmsBtn
()
{
secondCount
-=
1
;
if
(
secondCount
<
0
)
{
secondCount
=
5
;
secondCount
=
60
;
$smsBtn
.
val
(
'获取短信验证码'
)
.
removeClass
(
'second-progress'
)
.
removeClass
(
'disable'
);
...
...
@@ -509,7 +509,7 @@ function sendCaptchaSmsAsync() {
verifyCode
:
$
.
trim
(
$imgCaptchaInput
.
val
())
}
}).
then
(
function
(
data
)
{
if
(
data
.
captchaCount
===
false
)
{
if
(
data
.
captchaCount
===
false
||
data
.
code
===
400
)
{
errTip
(
$imgCaptchaInput
,
data
.
message
);
ep
.
emit
(
'captcha'
,
false
);
refreshCaptcha
();
...
...
@@ -659,22 +659,8 @@ $smsBtn.on('mousedown', function() {
return
validateCaptchaImg
(
true
);
})
.
then
(
function
()
{
$
.
ajax
({
type
:
'GET'
,
url
:
'/passport/captcha/checkSendMobile'
,
data
:
{
mobile
:
getMoblie
()
}
}).
then
(
function
(
data
)
{
if
(
data
.
code
===
400
)
{
errTip
(
$imgCaptchaInput
,
data
.
message
);
ep
.
emit
(
'captcha'
,
false
);
refreshCaptcha
();
}
else
{
disable60sSendSmsBtn
();
sendCaptchaSmsAsync
();
}
});
disable60sSendSmsBtn
();
return
sendCaptchaSmsAsync
();
});
});
...
...
Please
register
or
login
to post a comment