use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class VoteProcessor method voteUpArticle.
/**
* Votes up an article.
* <p>
* The request json object:
* <pre>
* {
* "dataId": ""
* }
* </pre>
* </p>
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/vote/up/article", method = HTTPRequestMethod.POST)
@Before(adviceClass = { LoginCheck.class, PermissionCheck.class })
public void voteUpArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
context.renderJSON();
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
final String dataId = requestJSONObject.optString(Common.DATA_ID);
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
final String userId = currentUser.optString(Keys.OBJECT_ID);
if (!Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE)) && voteQueryService.isOwn(userId, dataId, Vote.DATA_TYPE_C_ARTICLE)) {
context.renderFalseResult().renderMsg(langPropsService.get("cantVoteSelfLabel"));
return;
}
final int vote = voteQueryService.isVoted(userId, dataId);
if (Vote.TYPE_C_UP == vote) {
voteMgmtService.voteCancel(userId, dataId, Vote.DATA_TYPE_C_ARTICLE);
} else {
voteMgmtService.voteUp(userId, dataId, Vote.DATA_TYPE_C_ARTICLE);
final JSONObject article = articleQueryService.getArticle(dataId);
final String articleAuthorId = article.optString(Article.ARTICLE_AUTHOR_ID);
if (!VOTES.contains(userId + dataId) && !userId.equals(articleAuthorId)) {
final JSONObject notification = new JSONObject();
notification.put(Notification.NOTIFICATION_USER_ID, articleAuthorId);
notification.put(Notification.NOTIFICATION_DATA_ID, dataId + "-" + userId);
notificationMgmtService.addArticleVoteUpNotification(notification);
}
VOTES.add(userId + dataId);
}
context.renderTrueResult().renderJSONValue(Vote.TYPE, vote);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class ActivityProcessor method showEatingSnake.
/**
* Shows 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", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, PermissionGrant.class, StopwatchEndAdvice.class })
public void showEatingSnake(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");
final Map<String, Object> dataModel = renderer.getDataModel();
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);
final List<JSONObject> maxUsers = activityQueryService.getTopEatingSnakeUsersMax(avatarViewMode, 10);
dataModel.put("maxUsers", (Object) maxUsers);
final List<JSONObject> sumUsers = activityQueryService.getTopEatingSnakeUsersSum(avatarViewMode, 10);
dataModel.put("sumUsers", (Object) sumUsers);
final JSONObject user = (JSONObject) request.getAttribute(User.USER);
final String userId = user.optString(Keys.OBJECT_ID);
final int startPoint = activityQueryService.getEatingSnakeAvgPoint(userId);
String pointActivityEatingSnake = langPropsService.get("activityStartEatingSnakeTipLabel");
pointActivityEatingSnake = pointActivityEatingSnake.replace("{point}", String.valueOf(startPoint));
dataModel.put("activityStartEatingSnakeTipLabel", pointActivityEatingSnake);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class ActivityProcessor method showGobang.
/**
* Shows gobang.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/activity/gobang", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, PermissionGrant.class, StopwatchEndAdvice.class })
public void showGobang(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("/activity/gobang.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
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);
String pointActivityGobang = langPropsService.get("activityStartGobangTipLabel");
pointActivityGobang = pointActivityGobang.replace("{point}", String.valueOf(Pointtransfer.TRANSFER_SUM_C_ACTIVITY_GOBANG_START));
dataModel.put("activityStartGobangTipLabel", pointActivityGobang);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class ActivityProcessor method startEatingSnake.
/**
* Starts 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/start", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class, CSRFCheck.class })
@After(adviceClass = StopwatchEndAdvice.class)
public void startEatingSnake(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 = activityMgmtService.startEatingSnake(fromId);
context.renderJSON(ret);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class ActivityProcessor method submitCharacter.
/**
* Submits character.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
*/
@RequestProcessing(value = "/activity/character/submit", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { StopwatchEndAdvice.class })
public void submitCharacter(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) {
context.renderJSON().renderFalseResult();
JSONObject requestJSONObject;
try {
requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
request.setAttribute(Keys.REQUEST, requestJSONObject);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Submits character failed", e);
context.renderJSON(false).renderMsg(langPropsService.get("activityCharacterRecognizeFailedLabel"));
return;
}
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
final String userId = currentUser.optString(Keys.OBJECT_ID);
final String dataURL = requestJSONObject.optString("dataURL");
final String dataPart = StringUtils.substringAfter(dataURL, ",");
final String character = requestJSONObject.optString("character");
final JSONObject result = activityMgmtService.submitCharacter(userId, dataPart, character);
context.renderJSON(result);
}
Aggregations