Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
1f31d921
Commit
1f31d921
authored
Feb 13, 2018
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚸
Fix #12399
parent
0602c7d8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
34 deletions
+23
-34
src/main/java/org/b3log/solo/processor/CaptchaProcessor.java
src/main/java/org/b3log/solo/processor/CaptchaProcessor.java
+9
-0
src/main/java/org/b3log/solo/processor/CommentProcessor.java
src/main/java/org/b3log/solo/processor/CommentProcessor.java
+0
-18
src/test/java/org/b3log/solo/processor/CommentProcessorTestCase.java
...va/org/b3log/solo/processor/CommentProcessorTestCase.java
+14
-16
No files found.
src/main/java/org/b3log/solo/processor/CaptchaProcessor.java
View file @
1f31d921
...
@@ -69,6 +69,11 @@ public class CaptchaProcessor {
...
@@ -69,6 +69,11 @@ public class CaptchaProcessor {
*/
*/
private
static
final
int
CAPTCHA_LENGTH
=
4
;
private
static
final
int
CAPTCHA_LENGTH
=
4
;
/**
* Flag of captcha is enabled.
*/
public
static
boolean
CAPTCHA_ON
=
true
;
/**
/**
* Gets captcha.
* Gets captcha.
*
*
...
@@ -124,6 +129,10 @@ public class CaptchaProcessor {
...
@@ -124,6 +129,10 @@ public class CaptchaProcessor {
* @return {@code true} if it is invalid, returns {@code false} otherwise
* @return {@code true} if it is invalid, returns {@code false} otherwise
*/
*/
public
static
boolean
invalidCaptcha
(
final
String
captcha
)
{
public
static
boolean
invalidCaptcha
(
final
String
captcha
)
{
if
(!
CAPTCHA_ON
)
{
return
false
;
}
if
(
Strings
.
isEmptyOrNull
(
captcha
)
||
captcha
.
length
()
!=
CAPTCHA_LENGTH
)
{
if
(
Strings
.
isEmptyOrNull
(
captcha
)
||
captcha
.
length
()
!=
CAPTCHA_LENGTH
)
{
return
true
;
return
true
;
}
}
...
...
src/main/java/org/b3log/solo/processor/CommentProcessor.java
View file @
1f31d921
...
@@ -41,7 +41,6 @@ import org.json.JSONObject;
...
@@ -41,7 +41,6 @@ import org.json.JSONObject;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -140,15 +139,6 @@ public class CommentProcessor {
...
@@ -140,15 +139,6 @@ public class CommentProcessor {
return
;
return
;
}
}
final
HttpSession
session
=
httpServletRequest
.
getSession
(
false
);
if
(
null
==
session
)
{
jsonObject
.
put
(
Keys
.
STATUS_CODE
,
false
);
jsonObject
.
put
(
Keys
.
MSG
,
langPropsService
.
get
(
"captchaErrorLabel"
));
return
;
}
if
(!
userQueryService
.
isLoggedIn
(
httpServletRequest
,
httpServletResponse
))
{
if
(!
userQueryService
.
isLoggedIn
(
httpServletRequest
,
httpServletResponse
))
{
final
String
captcha
=
requestJSONObject
.
optString
(
CaptchaProcessor
.
CAPTCHA
);
final
String
captcha
=
requestJSONObject
.
optString
(
CaptchaProcessor
.
CAPTCHA
);
if
(
CaptchaProcessor
.
invalidCaptcha
(
captcha
))
{
if
(
CaptchaProcessor
.
invalidCaptcha
(
captcha
))
{
...
@@ -247,14 +237,6 @@ public class CommentProcessor {
...
@@ -247,14 +237,6 @@ public class CommentProcessor {
return
;
return
;
}
}
final
HttpSession
session
=
httpServletRequest
.
getSession
(
false
);
if
(
null
==
session
)
{
jsonObject
.
put
(
Keys
.
STATUS_CODE
,
false
);
jsonObject
.
put
(
Keys
.
MSG
,
langPropsService
.
get
(
"captchaErrorLabel"
));
return
;
}
if
(!
userQueryService
.
isLoggedIn
(
httpServletRequest
,
httpServletResponse
))
{
if
(!
userQueryService
.
isLoggedIn
(
httpServletRequest
,
httpServletResponse
))
{
final
String
captcha
=
requestJSONObject
.
optString
(
CaptchaProcessor
.
CAPTCHA
);
final
String
captcha
=
requestJSONObject
.
optString
(
CaptchaProcessor
.
CAPTCHA
);
if
(
CaptchaProcessor
.
invalidCaptcha
(
captcha
))
{
if
(
CaptchaProcessor
.
invalidCaptcha
(
captcha
))
{
...
...
src/test/java/org/b3log/solo/processor/CommentProcessorTestCase.java
View file @
1f31d921
...
@@ -15,14 +15,6 @@
...
@@ -15,14 +15,6 @@
*/
*/
package
org
.
b3log
.
solo
.
processor
;
package
org
.
b3log
.
solo
.
processor
;
import
java.io.BufferedReader
;
import
java.io.PrintWriter
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
javax.servlet.ServletContext
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.b3log.latke.model.User
;
import
org.b3log.latke.model.User
;
import
org.b3log.latke.service.ServiceException
;
import
org.b3log.latke.service.ServiceException
;
...
@@ -35,15 +27,25 @@ import org.b3log.solo.service.InitService;
...
@@ -35,15 +27,25 @@ import org.b3log.solo.service.InitService;
import
org.b3log.solo.service.PageMgmtService
;
import
org.b3log.solo.service.PageMgmtService
;
import
org.b3log.solo.service.UserQueryService
;
import
org.b3log.solo.service.UserQueryService
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
static
org
.
mockito
.
Mockito
.*;
import
org.testng.Assert
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
import
org.testng.annotations.Test
;
import
javax.servlet.ServletContext
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.BufferedReader
;
import
java.io.PrintWriter
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
/**
* {@link CommentProcessorTestCase} test case.
* {@link CommentProcessorTestCase} test case.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.
1, Nov 5, 2016
* @version 1.0.0.
2, Feb 13, 2018
* @since 1.7.0
* @since 1.7.0
*/
*/
@Test
(
suiteName
=
"processor"
)
@Test
(
suiteName
=
"processor"
)
...
@@ -81,9 +83,7 @@ public class CommentProcessorTestCase extends AbstractTestCase {
...
@@ -81,9 +83,7 @@ public class CommentProcessorTestCase extends AbstractTestCase {
when
(
request
.
getRequestURI
()).
thenReturn
(
"/add-page-comment.do"
);
when
(
request
.
getRequestURI
()).
thenReturn
(
"/add-page-comment.do"
);
when
(
request
.
getMethod
()).
thenReturn
(
"POST"
);
when
(
request
.
getMethod
()).
thenReturn
(
"POST"
);
final
HttpSession
session
=
mock
(
HttpSession
.
class
);
CaptchaProcessor
.
CAPTCHA_ON
=
false
;
when
(
session
.
getAttribute
(
CaptchaProcessor
.
CAPTCHA
)).
thenReturn
(
"captcha123456"
);
when
(
request
.
getSession
(
false
)).
thenReturn
(
session
);
final
JSONObject
requestJSON
=
new
JSONObject
();
final
JSONObject
requestJSON
=
new
JSONObject
();
requestJSON
.
put
(
"captcha"
,
"captcha123456"
);
requestJSON
.
put
(
"captcha"
,
"captcha123456"
);
...
@@ -123,9 +123,7 @@ public class CommentProcessorTestCase extends AbstractTestCase {
...
@@ -123,9 +123,7 @@ public class CommentProcessorTestCase extends AbstractTestCase {
when
(
request
.
getRequestURI
()).
thenReturn
(
"/add-article-comment.do"
);
when
(
request
.
getRequestURI
()).
thenReturn
(
"/add-article-comment.do"
);
when
(
request
.
getMethod
()).
thenReturn
(
"POST"
);
when
(
request
.
getMethod
()).
thenReturn
(
"POST"
);
final
HttpSession
session
=
mock
(
HttpSession
.
class
);
CaptchaProcessor
.
CAPTCHA_ON
=
false
;
when
(
session
.
getAttribute
(
CaptchaProcessor
.
CAPTCHA
)).
thenReturn
(
"captcha123456"
);
when
(
request
.
getSession
(
false
)).
thenReturn
(
session
);
final
JSONObject
requestJSON
=
new
JSONObject
();
final
JSONObject
requestJSON
=
new
JSONObject
();
requestJSON
.
put
(
"captcha"
,
"captcha123456"
);
requestJSON
.
put
(
"captcha"
,
"captcha123456"
);
...
...
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