use of org.b3log.symphony.util.GeetestLib in project symphony by b3log.
the class ActivityProcessor method dailyCheckin.
/**
* Daily checkin.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/activity/daily-checkin", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = StopwatchEndAdvice.class)
public void dailyCheckin(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final JSONObject user = (JSONObject) request.getAttribute(User.USER);
final String userId = user.optString(Keys.OBJECT_ID);
if (!Symphonys.getBoolean("geetest.enabled")) {
activityMgmtService.dailyCheckin(userId);
} else {
final String challenge = request.getParameter(GeetestLib.fn_geetest_challenge);
final String validate = request.getParameter(GeetestLib.fn_geetest_validate);
final String seccode = request.getParameter(GeetestLib.fn_geetest_seccode);
if (StringUtils.isBlank(challenge) || StringUtils.isBlank(validate) || StringUtils.isBlank(seccode)) {
response.sendRedirect(Latkes.getServePath() + "/member/" + user.optString(User.USER_NAME) + "/points");
return;
}
final GeetestLib gtSdk = new GeetestLib(Symphonys.get("geetest.id"), Symphonys.get("geetest.key"));
final int gt_server_status_code = (Integer) request.getSession().getAttribute(gtSdk.gtServerStatusSessionKey);
int gtResult = 0;
if (gt_server_status_code == 1) {
gtResult = gtSdk.enhencedValidateRequest(challenge, validate, seccode, userId);
} else {
gtResult = gtSdk.failbackValidateRequest(challenge, validate, seccode);
}
if (gtResult == 1) {
activityMgmtService.dailyCheckin(userId);
}
}
response.sendRedirect(Latkes.getServePath() + "/member/" + user.optString(User.USER_NAME) + "/points");
}
use of org.b3log.symphony.util.GeetestLib in project symphony by b3log.
the class GeetestCaptchaServlet method doGet.
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
final JSONObject currentUser = Sessions.currentUser(request);
if (null == currentUser) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final GeetestLib gtSdk = new GeetestLib(Symphonys.get("geetest.id"), Symphonys.get("geetest.key"));
String resStr = "{}";
final String userId = currentUser.optString(Keys.OBJECT_ID);
final int gtServerStatus = gtSdk.preProcess(userId);
request.getSession().setAttribute(gtSdk.gtServerStatusSessionKey, gtServerStatus);
resStr = gtSdk.getResponseStr();
final PrintWriter out = response.getWriter();
out.println(resStr);
}
Aggregations