You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2005/12/20 21:24:27 UTC
svn commit: r358093 -
/incubator/roller/trunk/src/org/roller/presentation/velocity/MathCommentAuthenticator.java
Author: agilliland
Date: Tue Dec 20 12:24:25 2005
New Revision: 358093
URL: http://svn.apache.org/viewcvs?rev=358093&view=rev
Log:
fixing math comment authenticator.
Modified:
incubator/roller/trunk/src/org/roller/presentation/velocity/MathCommentAuthenticator.java
Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/MathCommentAuthenticator.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/MathCommentAuthenticator.java?rev=358093&r1=358092&r2=358093&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/MathCommentAuthenticator.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/MathCommentAuthenticator.java Tue Dec 20 12:24:25 2005
@@ -22,13 +22,14 @@
private static Log mLogger = LogFactory.getLog(MathCommentAuthenticator.class);
+
public String getHtml(Context context,
HttpServletRequest request,
HttpServletResponse response) {
String answer = "";
- HttpSession session = request.getSession();
+ HttpSession session = request.getSession(true);
if (session.getAttribute("mathAnswer") == null) {
// starting a new test
int value1 = (int)(Math.random()*10.0);
@@ -63,28 +64,34 @@
return sb.toString();
}
+
public boolean authenticate(CommentData comment, HttpServletRequest request) {
- boolean ret = false;
+ boolean authentic = false;
+ HttpSession session = request.getSession(false);
String answerString = request.getParameter("answer");
- if (answerString != null || answerString.trim().length()==0) {
+
+ if (answerString != null && session != null) {
try {
int answer = Integer.parseInt(answerString);
- Integer sum =
- (Integer)request.getSession().getAttribute("mathAnswer");
+ Integer sum = (Integer) session.getAttribute("mathAnswer");
+
if (answer == sum.intValue()) {
- ret = true;
- request.getSession().removeAttribute("mathAnswer");
- request.getSession().removeAttribute("mathValue1");
- request.getSession().removeAttribute("mathValue2");
+ authentic = true;
+ session.removeAttribute("mathAnswer");
+ session.removeAttribute("mathValue1");
+ session.removeAttribute("mathValue2");
}
- } catch (NumberFormatException ignored) {} catch (Exception e) {
+ } catch (NumberFormatException ignored) {
+ // ignored ... someone is just really bad at math
+ } catch (Exception e) {
+ // unexpected
mLogger.error(e);
}
}
- return ret;
+ return authentic;
}
}