72 lines
2.4 KiB
Java
72 lines
2.4 KiB
Java
|
|
package it.acxent.human.servlet;
|
||
|
|
|
||
|
|
import it.acxent.cc.Attivita;
|
||
|
|
import it.acxent.db.ApplParmFull;
|
||
|
|
import it.acxent.db.CRAdapter;
|
||
|
|
import it.acxent.db.DBAdapter;
|
||
|
|
import it.acxent.human.Challenge;
|
||
|
|
import it.acxent.servlet.AblServletSvlt;
|
||
|
|
import javax.servlet.annotation.WebServlet;
|
||
|
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
import org.json.JSONObject;
|
||
|
|
|
||
|
|
@WebServlet(urlPatterns = {"/HumanCeck.abl"})
|
||
|
|
public class HumanCeckSvlt extends AblServletSvlt {
|
||
|
|
private static final String _SESSION_CHALLENGE = "_challenge";
|
||
|
|
|
||
|
|
private static final long serialVersionUID = 476646217816287146L;
|
||
|
|
|
||
|
|
protected void fillComboAfterDetail(DBAdapter beanA, HttpServletRequest req, HttpServletResponse res) {}
|
||
|
|
|
||
|
|
protected void fillComboAfterSearch(CRAdapter CR, HttpServletRequest req, HttpServletResponse res) {}
|
||
|
|
|
||
|
|
protected DBAdapter getBean(HttpServletRequest req) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected boolean isSecureServlet(HttpServletRequest req) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
_sendChallenge(req, res);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void _checkChallenge(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Challenge ch = (Challenge)req.getSession().getAttribute("_challenge");
|
||
|
|
String ans = getRequestParameter(req, "h_answer");
|
||
|
|
JSONObject jo = new JSONObject();
|
||
|
|
if (ch.checkAnswer(ans)) {
|
||
|
|
long endTime = DBAdapter.getNow().getTime() + ch.getHttl() * 1000L;
|
||
|
|
req.getSession().setAttribute("_HC_" + ch.getHid(), Long.valueOf(endTime));
|
||
|
|
jo.put("res", "true");
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
jo.put("page", attivita.getWwwAddress() + attivita.getWwwAddress());
|
||
|
|
} else {
|
||
|
|
jo.put("res", "false");
|
||
|
|
}
|
||
|
|
sendHtmlMsgResponse(req, res, jo.toString());
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void search(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
_sendChallenge(req, res);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected String getBeanPageName(HttpServletRequest req) {
|
||
|
|
return "_inc_human_check.jsp";
|
||
|
|
}
|
||
|
|
|
||
|
|
public void _sendChallenge(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
Challenge ch = new Challenge(getApFull(req), 10, 3);
|
||
|
|
fillObject(req, ch);
|
||
|
|
req.getSession().setAttribute("_challenge", ch);
|
||
|
|
setJspPage("/_inc_human_check_challenge.jsp", req);
|
||
|
|
callJsp(req, res);
|
||
|
|
}
|
||
|
|
}
|