Search in sources :

Example 1 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class ActivityProcessor method collectEatingSnake.

/**
 * Collects eating snake.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/activity/eating-snake/collect", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, StopwatchEndAdvice.class })
public void collectEatingSnake(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("/activity/eating-snake.ftl");
    JSONObject requestJSONObject;
    try {
        requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
        final int score = requestJSONObject.optInt("score");
        final JSONObject user = (JSONObject) request.getAttribute(User.USER);
        final JSONObject ret = activityMgmtService.collectEatingSnake(user.optString(Keys.OBJECT_ID), score);
        context.renderJSON(ret);
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, "Collects eating snake game failed", e);
        context.renderJSON(false).renderMsg("err....");
    }
}
Also used : JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 2 with Before

use of org.b3log.latke.servlet.annotation.Before 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");
}
Also used : JSONObject(org.json.JSONObject) GeetestLib(org.b3log.symphony.util.GeetestLib) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 3 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class ActivityProcessor method yesterdayLivenessReward.

/**
 * Yesterday liveness reward.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/activity/yesterday-liveness-reward", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = StopwatchEndAdvice.class)
public void yesterdayLivenessReward(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);
    activityMgmtService.yesterdayLivenessReward(userId);
    response.sendRedirect(Latkes.getServePath() + "/member/" + user.optString(User.USER_NAME) + "/points");
}
Also used : JSONObject(org.json.JSONObject) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 4 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class ActivityProcessor method startGobang.

/**
 * Starts gobang.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/activity/gobang/start", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = StopwatchEndAdvice.class)
public void startGobang(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
    final String fromId = currentUser.optString(Keys.OBJECT_ID);
    final JSONObject ret = Results.falseResult();
    final boolean succ = currentUser.optInt(UserExt.USER_POINT) - Pointtransfer.TRANSFER_SUM_C_ACTIVITY_GOBANG_START >= 0;
    ret.put(Keys.STATUS_CODE, succ);
    final String msg = succ ? "started" : langPropsService.get("activityStartGobangFailLabel");
    ret.put(Keys.MSG, msg);
    context.renderJSON(ret);
}
Also used : JSONObject(org.json.JSONObject) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 5 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class ActivityProcessor method show1A0001.

/**
 * Shows 1A0001.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/activity/1A0001", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, PermissionGrant.class, StopwatchEndAdvice.class })
public void show1A0001(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("/activity/1A0001.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
    final String userId = currentUser.optString(Keys.OBJECT_ID);
    final boolean closed = Symphonys.getBoolean("activity1A0001Closed");
    dataModel.put(Common.CLOSED, closed);
    final Calendar calendar = Calendar.getInstance();
    final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    final boolean closed1A0001 = dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY;
    dataModel.put(Common.CLOSED_1A0001, closed1A0001);
    final int hour = calendar.get(Calendar.HOUR_OF_DAY);
    final int minute = calendar.get(Calendar.MINUTE);
    final boolean end = hour > 14 || (hour == 14 && minute > 55);
    dataModel.put(Common.END, end);
    final boolean collected = activityQueryService.isCollected1A0001Today(userId);
    dataModel.put(Common.COLLECTED, collected);
    final boolean participated = activityQueryService.is1A0001Today(userId);
    dataModel.put(Common.PARTICIPATED, participated);
    while (true) {
        if (closed) {
            dataModel.put(Keys.MSG, langPropsService.get("activityClosedLabel"));
            break;
        }
        if (closed1A0001) {
            dataModel.put(Keys.MSG, langPropsService.get("activity1A0001CloseLabel"));
            break;
        }
        if (collected) {
            dataModel.put(Keys.MSG, langPropsService.get("activityParticipatedLabel"));
            break;
        }
        if (participated) {
            dataModel.put(Common.HOUR, hour);
            final List<JSONObject> records = pointtransferQueryService.getLatestPointtransfers(userId, Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_1A0001, 1);
            final JSONObject pointtransfer = records.get(0);
            final String data = pointtransfer.optString(Pointtransfer.DATA_ID);
            final String smallOrLarge = data.split("-")[1];
            final int sum = pointtransfer.optInt(Pointtransfer.SUM);
            String msg = langPropsService.get("activity1A0001BetedLabel");
            final String small = langPropsService.get("activity1A0001BetSmallLabel");
            final String large = langPropsService.get("activity1A0001BetLargeLabel");
            msg = msg.replace("{smallOrLarge}", StringUtils.equals(smallOrLarge, "0") ? small : large);
            msg = msg.replace("{point}", String.valueOf(sum));
            dataModel.put(Keys.MSG, msg);
            break;
        }
        if (end) {
            dataModel.put(Keys.MSG, langPropsService.get("activityEndLabel"));
            break;
        }
        break;
    }
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    dataModelService.fillRandomArticles(avatarViewMode, dataModel);
    dataModelService.fillSideHotArticles(avatarViewMode, dataModel);
    dataModelService.fillSideTags(dataModel);
    dataModelService.fillLatestCmts(dataModel);
}
Also used : JSONObject(org.json.JSONObject) Calendar(java.util.Calendar) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Aggregations

Before (org.b3log.latke.servlet.annotation.Before)169 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)169 JSONObject (org.json.JSONObject)166 After (org.b3log.latke.servlet.annotation.After)135 AbstractFreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)105 ServiceException (org.b3log.latke.service.ServiceException)37 Date (java.util.Date)13 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 JSONArray (org.json.JSONArray)8 Auth (com.qiniu.util.Auth)7 ParseException (java.text.ParseException)6 List (java.util.List)6 ServletException (javax.servlet.ServletException)3 Configuration (com.qiniu.storage.Configuration)1 UploadManager (com.qiniu.storage.UploadManager)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1