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
8 years ago
Commit
9cff09a3e34edff473856dfe2bfe59416eb5c1e3
1 parent
669d374b
fix captcha
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
9 deletions
apps/passport/controllers/captcha.js
public/js/plugins/captcha.js
apps/passport/controllers/captcha.js
View file @
9cff09a
...
...
@@ -6,22 +6,28 @@
const
captchaService
=
require
(
'../models/captcha-service'
);
const
helpers
=
global
.
yoho
.
helpers
;
const
cache
=
global
.
yoho
.
cache
;
const
checkAsync
=
(
req
,
res
)
=>
{
};
// 中间件
const
requiredAPI
=
(
req
,
res
,
next
)
=>
{
let
captchaToken
=
req
.
body
.
verifyCode
||
''
;
let
count
=
req
.
session
.
captchaCount
;
if
(
count
>
5
)
{
req
.
session
.
captcha
=
'yoho9646'
;
return
res
.
json
({
code
:
403
,
message
:
'该验证码已失效'
});
}
req
.
session
.
captchaCount
=
count
+
1
;
if
(
captchaToken
===
req
.
session
.
captcha
)
{
return
next
();
}
else
{
return
res
.
json
({
code
:
400
,
message
:
'
您输入的验证码不正确!
'
message
:
'
请将图形验证码翻转至正确方向
'
});
}
};
...
...
@@ -29,7 +35,18 @@ const requiredAPI = (req, res, next) => {
// 重定向调用
const
requiredPage
=
(
req
,
res
,
next
)
=>
{
let
captchaToken
=
req
.
body
.
verifyCode
||
''
;
let
count
=
req
.
session
.
captchaCount
;
if
(
count
>
5
)
{
req
.
session
.
captcha
=
'yoho9646'
;
return
res
.
json
({
code
:
403
,
message
:
'该验证码已失效'
});
}
req
.
session
.
captchaCount
=
count
+
1
;
if
(
captchaToken
===
req
.
session
.
captcha
)
{
return
next
();
}
else
{
...
...
@@ -41,6 +58,7 @@ const requiredPage = (req, res, next) => {
const
generate
=
(
req
,
res
,
next
)
=>
{
captchaService
.
generateCaptcha
().
then
((
result
)
=>
{
req
.
session
.
captcha
=
result
.
data
.
text
;
req
.
session
.
captchaCount
=
0
;
if
(
result
.
code
===
200
)
{
return
res
.
json
({
...
...
@@ -62,7 +80,18 @@ const generate = (req, res, next) => {
// ajax 异步调用
const
checkAPI
=
(
req
,
res
)
=>
{
let
captchaToken
=
req
.
body
.
verifyCode
||
''
;
let
count
=
req
.
session
.
captchaCount
;
if
(
count
>
5
)
{
req
.
session
.
captcha
=
'yoho9646'
;
return
res
.
json
({
code
:
403
,
message
:
'该验证码已失效'
});
}
req
.
session
.
captchaCount
=
count
+
1
;
if
(
captchaToken
===
req
.
session
.
captcha
)
{
return
res
.
json
({
code
:
200
,
...
...
@@ -71,7 +100,7 @@ const checkAPI = (req, res) => {
}
else
{
return
res
.
json
({
code
:
400
,
message
:
'
您输入的验证码不正确!
'
message
:
'
请将图形验证码翻转至正确方向
'
});
}
};
...
...
public/js/plugins/captcha.js
View file @
9cff09a
...
...
@@ -140,7 +140,7 @@ Captcha.prototype = {
if
(
result
.
code
===
200
)
{
return
$
.
Deferred
().
resolve
().
promise
();
// eslint-disable-line
}
else
{
self
.
showTip
();
self
.
showTip
(
result
.
message
);
return
$
.
Deferred
().
reject
().
promise
();
//eslint-disable-line
}
});
...
...
@@ -185,7 +185,13 @@ Captcha.prototype = {
/**
* 显示错误
*/
showTip
:
function
()
{
showTip
:
function
(
msg
)
{
if
(
msg
)
{
this
.
$tip
.
find
(
'.span'
).
html
(
msg
);
}
else
{
this
.
$tip
.
find
(
'.span'
).
html
(
'请将图形验证码翻转至正确方向'
);
}
if
(
this
.
$tip
)
{
this
.
$tip
.
removeClass
(
'hide'
);
}
...
...
Please
register
or
login
to post a comment