Search in sources :

Example 71 with Before

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

the class TopProcessor method showCheckin.

/**
 * Shows checkin ranking list.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/top/checkin", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, AnonymousViewCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showCheckin(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    ;
    context.setRenderer(renderer);
    renderer.setTemplateName("/top/checkin.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    final List<JSONObject> users = activityQueryService.getTopCheckinUsers(avatarViewMode, Symphonys.getInt("topCheckinCnt"));
    dataModel.put(Common.TOP_CHECKIN_USERS, users);
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
    dataModelService.fillRandomArticles(avatarViewMode, dataModel);
    dataModelService.fillSideHotArticles(avatarViewMode, dataModel);
    dataModelService.fillSideTags(dataModel);
    dataModelService.fillLatestCmts(dataModel);
}
Also used : JSONObject(org.json.JSONObject) 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 72 with Before

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

the class UserProcessor method showHomeAnonymousComments.

/**
 * Shows user home anonymous comments page.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param userName the specified user name
 * @throws Exception exception
 */
@RequestProcessing(value = "/member/{userName}/comments/anonymous", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, UserBlockCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showHomeAnonymousComments(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userName) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("/home/comments.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
    final boolean isLoggedIn = (Boolean) dataModel.get(Common.IS_LOGGED_IN);
    JSONObject currentUser = null;
    if (isLoggedIn) {
        currentUser = (JSONObject) dataModel.get(Common.CURRENT_USER);
    }
    final JSONObject user = (JSONObject) request.getAttribute(User.USER);
    if (null == currentUser || (!currentUser.optString(Keys.OBJECT_ID).equals(user.optString(Keys.OBJECT_ID))) && !Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE))) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    String pageNumStr = request.getParameter("p");
    if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
        pageNumStr = "1";
    }
    final int pageNum = Integer.valueOf(pageNumStr);
    final int pageSize = Symphonys.getInt("userHomeCmtsCnt");
    final int windowSize = Symphonys.getInt("userHomeCmtsWindowSize");
    fillHomeUser(dataModel, user, roleQueryService);
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    avatarQueryService.fillUserAvatarURL(avatarViewMode, user);
    final String followingId = user.optString(Keys.OBJECT_ID);
    dataModel.put(Follow.FOLLOWING_ID, followingId);
    if (isLoggedIn) {
        currentUser = (JSONObject) dataModel.get(Common.CURRENT_USER);
        final String followerId = currentUser.optString(Keys.OBJECT_ID);
        final boolean isFollowing = followQueryService.isFollowing(followerId, followingId, Follow.FOLLOWING_TYPE_C_USER);
        dataModel.put(Common.IS_FOLLOWING, isFollowing);
    }
    user.put(UserExt.USER_T_CREATE_TIME, new Date(user.getLong(Keys.OBJECT_ID)));
    final List<JSONObject> userComments = commentQueryService.getUserComments(avatarViewMode, user.optString(Keys.OBJECT_ID), Comment.COMMENT_ANONYMOUS_C_ANONYMOUS, pageNum, pageSize, currentUser);
    dataModel.put(Common.USER_HOME_COMMENTS, userComments);
    int recordCount = 0;
    int pageCount = 0;
    if (!userComments.isEmpty()) {
        final JSONObject first = userComments.get(0);
        pageCount = first.optInt(Pagination.PAGINATION_PAGE_COUNT);
        recordCount = first.optInt(Pagination.PAGINATION_RECORD_COUNT);
    }
    final List<Integer> pageNums = Paginator.paginate(pageNum, pageSize, pageCount, windowSize);
    if (!pageNums.isEmpty()) {
        dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
        dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
    }
    dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
    dataModel.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
    dataModel.put(Pagination.PAGINATION_RECORD_COUNT, recordCount);
    dataModel.put(Common.TYPE, "commentsAnonymous");
}
Also used : AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Date(java.util.Date) JSONObject(org.json.JSONObject) 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 73 with Before

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

the class UserProcessor method showHomeFollowingUsers.

/**
 * Shows user home following users page.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param userName the specified user name
 * @throws Exception exception
 */
@RequestProcessing(value = "/member/{userName}/following/users", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, AnonymousViewCheck.class, UserBlockCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showHomeFollowingUsers(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userName) throws Exception {
    final JSONObject user = (JSONObject) request.getAttribute(User.USER);
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("/home/following-users.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
    String pageNumStr = request.getParameter("p");
    if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
        pageNumStr = "1";
    }
    final int pageNum = Integer.valueOf(pageNumStr);
    final int pageSize = Symphonys.getInt("userHomeFollowingUsersCnt");
    final int windowSize = Symphonys.getInt("userHomeFollowingUsersWindowSize");
    fillHomeUser(dataModel, user, roleQueryService);
    final String followingId = user.optString(Keys.OBJECT_ID);
    dataModel.put(Follow.FOLLOWING_ID, followingId);
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    avatarQueryService.fillUserAvatarURL(avatarViewMode, user);
    final JSONObject followingUsersResult = followQueryService.getFollowingUsers(avatarViewMode, followingId, pageNum, pageSize);
    final List<JSONObject> followingUsers = (List<JSONObject>) followingUsersResult.opt(Keys.RESULTS);
    dataModel.put(Common.USER_HOME_FOLLOWING_USERS, followingUsers);
    final boolean isLoggedIn = (Boolean) dataModel.get(Common.IS_LOGGED_IN);
    if (isLoggedIn) {
        final JSONObject currentUser = (JSONObject) dataModel.get(Common.CURRENT_USER);
        final String followerId = currentUser.optString(Keys.OBJECT_ID);
        final boolean isFollowing = followQueryService.isFollowing(followerId, followingId, Follow.FOLLOWING_TYPE_C_USER);
        dataModel.put(Common.IS_FOLLOWING, isFollowing);
        for (final JSONObject followingUser : followingUsers) {
            final String homeUserFollowingUserId = followingUser.optString(Keys.OBJECT_ID);
            followingUser.put(Common.IS_FOLLOWING, followQueryService.isFollowing(followerId, homeUserFollowingUserId, Follow.FOLLOWING_TYPE_C_USER));
        }
    }
    user.put(UserExt.USER_T_CREATE_TIME, new Date(user.getLong(Keys.OBJECT_ID)));
    final int followingUserCnt = followingUsersResult.optInt(Pagination.PAGINATION_RECORD_COUNT);
    final int pageCount = (int) Math.ceil((double) followingUserCnt / (double) pageSize);
    final List<Integer> pageNums = Paginator.paginate(pageNum, pageSize, pageCount, windowSize);
    if (!pageNums.isEmpty()) {
        dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
        dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
    }
    dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
    dataModel.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
    dataModel.put(Pagination.PAGINATION_RECORD_COUNT, followingUserCnt);
    dataModel.put(Common.TYPE, "followingUsers");
}
Also used : AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Date(java.util.Date) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 74 with Before

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

the class UserProcessor method showHome.

/**
 * Shows user home page.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param userName the specified user name
 * @throws Exception exception
 */
@RequestProcessing(value = "/member/{userName}", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, AnonymousViewCheck.class, UserBlockCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showHome(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userName) throws Exception {
    final JSONObject user = (JSONObject) request.getAttribute(User.USER);
    String pageNumStr = request.getParameter("p");
    if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
        pageNumStr = "1";
    }
    int pageNum = 1;
    try {
        pageNum = Integer.valueOf(pageNumStr);
    } catch (final Exception e) {
        pageNum = 1;
    }
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
    final String followingId = user.optString(Keys.OBJECT_ID);
    dataModel.put(Follow.FOLLOWING_ID, followingId);
    renderer.setTemplateName("/home/home.ftl");
    dataModel.put(User.USER, user);
    fillHomeUser(dataModel, user, roleQueryService);
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    avatarQueryService.fillUserAvatarURL(avatarViewMode, user);
    final boolean isLoggedIn = (Boolean) dataModel.get(Common.IS_LOGGED_IN);
    if (isLoggedIn) {
        final JSONObject currentUser = (JSONObject) dataModel.get(Common.CURRENT_USER);
        final String followerId = currentUser.optString(Keys.OBJECT_ID);
        final boolean isFollowing = followQueryService.isFollowing(followerId, followingId, Follow.FOLLOWING_TYPE_C_USER);
        dataModel.put(Common.IS_FOLLOWING, isFollowing);
    }
    user.put(UserExt.USER_T_CREATE_TIME, new Date(user.getLong(Keys.OBJECT_ID)));
    final int pageSize = Symphonys.getInt("userHomeArticlesCnt");
    final int windowSize = Symphonys.getInt("userHomeArticlesWindowSize");
    final List<JSONObject> userArticles = articleQueryService.getUserArticles(avatarViewMode, user.optString(Keys.OBJECT_ID), Article.ARTICLE_ANONYMOUS_C_PUBLIC, pageNum, pageSize);
    dataModel.put(Common.USER_HOME_ARTICLES, userArticles);
    int recordCount = 0;
    int pageCount = 0;
    if (!userArticles.isEmpty()) {
        final JSONObject first = userArticles.get(0);
        pageCount = first.optInt(Pagination.PAGINATION_PAGE_COUNT);
        recordCount = first.optInt(Pagination.PAGINATION_RECORD_COUNT);
    }
    final List<Integer> pageNums = Paginator.paginate(pageNum, pageSize, pageCount, windowSize);
    if (!pageNums.isEmpty()) {
        dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
        dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
    }
    dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
    dataModel.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
    dataModel.put(Pagination.PAGINATION_RECORD_COUNT, recordCount);
    final JSONObject currentUser = Sessions.currentUser(request);
    if (null == currentUser) {
        dataModel.put(Common.IS_MY_ARTICLE, false);
    } else {
        dataModel.put(Common.IS_MY_ARTICLE, userName.equals(currentUser.optString(User.USER_NAME)));
    }
    dataModel.put(Common.TYPE, "home");
}
Also used : AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Date(java.util.Date) JSONObject(org.json.JSONObject) 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 75 with Before

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

the class UserProcessor method queryInvitecode.

/**
 * Queries invitecode state.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/invitecode/state", method = HTTPRequestMethod.POST)
@Before(adviceClass = { LoginCheck.class, CSRFCheck.class })
public void queryInvitecode(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final JSONObject ret = Results.falseResult();
    context.renderJSON(ret);
    final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
    String invitecode = requestJSONObject.optString(Invitecode.INVITECODE);
    if (StringUtils.isBlank(invitecode)) {
        ret.put(Keys.STATUS_CODE, -1);
        ret.put(Keys.MSG, invitecode + " " + langPropsService.get("notFoundInvitecodeLabel"));
        return;
    }
    invitecode = invitecode.trim();
    final JSONObject result = invitecodeQueryService.getInvitecode(invitecode);
    if (null == result) {
        ret.put(Keys.STATUS_CODE, -1);
        ret.put(Keys.MSG, langPropsService.get("notFoundInvitecodeLabel"));
    } else {
        final int status = result.optInt(Invitecode.STATUS);
        ret.put(Keys.STATUS_CODE, status);
        switch(status) {
            case Invitecode.STATUS_C_USED:
                ret.put(Keys.MSG, langPropsService.get("invitecodeUsedLabel"));
                break;
            case Invitecode.STATUS_C_UNUSED:
                String msg = langPropsService.get("invitecodeOkLabel");
                msg = msg.replace("${time}", DateFormatUtils.format(result.optLong(Keys.OBJECT_ID) + Symphonys.getLong("invitecode.expired"), "yyyy-MM-dd HH:mm"));
                ret.put(Keys.MSG, msg);
                break;
            case Invitecode.STATUS_C_STOPUSE:
                ret.put(Keys.MSG, langPropsService.get("invitecodeStopLabel"));
                break;
            default:
                ret.put(Keys.MSG, langPropsService.get("notFoundInvitecodeLabel"));
        }
    }
}
Also used : JSONObject(org.json.JSONObject) Before(org.b3log.latke.servlet.annotation.Before) 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