Search in sources :

Example 76 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method updateUser.

/**
 * Updates a user.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param userId   the specified user id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/user/{userId}", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateUser(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userId) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/user.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    final JSONObject user = userQueryService.getUser(userId);
    dataModel.put(User.USER, user);
    final String oldRole = user.optString(User.USER_ROLE);
    final JSONObject result = roleQueryService.getRoles(1, Integer.MAX_VALUE, 10);
    final List<JSONObject> roles = (List<JSONObject>) result.opt(Role.ROLES);
    dataModel.put(Role.ROLES, roles);
    final Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        final String name = parameterNames.nextElement();
        final String value = request.getParameter(name);
        switch(name) {
            case UserExt.USER_POINT:
            case UserExt.USER_APP_ROLE:
            case UserExt.USER_STATUS:
            case UserExt.USER_COMMENT_VIEW_MODE:
            case UserExt.USER_AVATAR_VIEW_MODE:
            case UserExt.USER_LIST_PAGE_SIZE:
            case UserExt.USER_NOTIFY_STATUS:
            case UserExt.USER_SUB_MAIL_STATUS:
            case UserExt.USER_KEYBOARD_SHORTCUTS_STATUS:
            case UserExt.USER_GEO_STATUS:
            case UserExt.USER_ARTICLE_STATUS:
            case UserExt.USER_COMMENT_STATUS:
            case UserExt.USER_FOLLOWING_USER_STATUS:
            case UserExt.USER_FOLLOWING_TAG_STATUS:
            case UserExt.USER_FOLLOWING_ARTICLE_STATUS:
            case UserExt.USER_WATCHING_ARTICLE_STATUS:
            case UserExt.USER_FOLLOWER_STATUS:
            case UserExt.USER_POINT_STATUS:
            case UserExt.USER_ONLINE_STATUS:
            case UserExt.USER_UA_STATUS:
            case UserExt.USER_TIMELINE_STATUS:
            case UserExt.USER_FORGE_LINK_STATUS:
            case UserExt.USER_JOIN_POINT_RANK:
            case UserExt.USER_JOIN_USED_POINT_RANK:
                user.put(name, Integer.valueOf(value));
                break;
            case User.USER_PASSWORD:
                final String oldPwd = user.getString(name);
                if (!oldPwd.equals(value) && !Strings.isEmptyOrNull(value)) {
                    user.put(name, MD5.hash(value));
                }
                break;
            case UserExt.SYNC_TO_CLIENT:
                user.put(UserExt.SYNC_TO_CLIENT, Boolean.valueOf(value));
                break;
            default:
                user.put(name, value);
                break;
        }
    }
    final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
    if (!Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE))) {
        user.put(User.USER_ROLE, oldRole);
    }
    userMgmtService.updateUser(userId, user);
    dataModelService.fillHeaderAndFooter(request, response, 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 77 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method showInvitecode.

/**
 * Shows an invitecode.
 *
 * @param context      the specified context
 * @param request      the specified request
 * @param response     the specified response
 * @param invitecodeId the specified invitecode id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/invitecode/{invitecodeId}", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showInvitecode(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String invitecodeId) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/invitecode.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    final JSONObject invitecode = invitecodeQueryService.getInvitecodeById(invitecodeId);
    dataModel.put(Invitecode.INVITECODE, invitecode);
    dataModelService.fillHeaderAndFooter(request, response, 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 78 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method updateMisc.

/**
 * Updates admin miscellaneous.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/misc", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateMisc(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/misc.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    List<JSONObject> misc = new ArrayList<>();
    final Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        final String name = parameterNames.nextElement();
        final String value = request.getParameter(name);
        final JSONObject option = new JSONObject();
        option.put(Keys.OBJECT_ID, name);
        option.put(Option.OPTION_VALUE, value);
        option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_MISC);
        misc.add(option);
    }
    for (final JSONObject option : misc) {
        optionMgmtService.updateOption(option.getString(Keys.OBJECT_ID), option);
    }
    misc = optionQueryService.getMisc();
    dataModel.put(Option.OPTIONS, misc);
    dataModelService.fillHeaderAndFooter(request, response, 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 79 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method showComments.

/**
 * Shows admin comments.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/comments", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showComments(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/comments.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    String pageNumStr = request.getParameter("p");
    if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
        pageNumStr = "1";
    }
    final int pageNum = Integer.valueOf(pageNumStr);
    final int pageSize = PAGE_SIZE;
    final int windowSize = WINDOW_SIZE;
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, pageSize);
    requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, windowSize);
    final Map<String, Class<?>> commentFields = new HashMap<>();
    commentFields.put(Keys.OBJECT_ID, String.class);
    commentFields.put(Comment.COMMENT_CREATE_TIME, String.class);
    commentFields.put(Comment.COMMENT_AUTHOR_ID, String.class);
    commentFields.put(Comment.COMMENT_ON_ARTICLE_ID, String.class);
    commentFields.put(Comment.COMMENT_SHARP_URL, String.class);
    commentFields.put(Comment.COMMENT_STATUS, Integer.class);
    commentFields.put(Comment.COMMENT_CONTENT, String.class);
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    final JSONObject result = commentQueryService.getComments(avatarViewMode, requestJSONObject, commentFields);
    dataModel.put(Comment.COMMENTS, CollectionUtils.jsonArrayToList(result.optJSONArray(Comment.COMMENTS)));
    final JSONObject pagination = result.optJSONObject(Pagination.PAGINATION);
    final int pageCount = pagination.optInt(Pagination.PAGINATION_PAGE_COUNT);
    final JSONArray pageNums = pagination.optJSONArray(Pagination.PAGINATION_PAGE_NUMS);
    dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.opt(0));
    dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.opt(pageNums.length() - 1));
    dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
    dataModel.put(Pagination.PAGINATION_PAGE_NUMS, CollectionUtils.jsonArrayToList(pageNums));
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) 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 80 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method updateComment.

/**
 * Updates a comment.
 *
 * @param context   the specified context
 * @param request   the specified request
 * @param response  the specified response
 * @param commentId the specified comment id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/comment/{commentId}", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateComment(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String commentId) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/comment.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    JSONObject comment = commentQueryService.getComment(commentId);
    final Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        final String name = parameterNames.nextElement();
        final String value = request.getParameter(name);
        if (name.equals(Comment.COMMENT_STATUS) || name.equals(Comment.COMMENT_GOOD_CNT) || name.equals(Comment.COMMENT_BAD_CNT)) {
            comment.put(name, Integer.valueOf(value));
        } else {
            comment.put(name, value);
        }
    }
    commentMgmtService.updateComment(commentId, comment);
    comment = commentQueryService.getComment(commentId);
    dataModel.put(Comment.COMMENT, comment);
    dataModelService.fillHeaderAndFooter(request, response, 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)

Aggregations

AbstractFreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)120 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)119 JSONObject (org.json.JSONObject)117 After (org.b3log.latke.servlet.annotation.After)105 Before (org.b3log.latke.servlet.annotation.Before)105 ServiceException (org.b3log.latke.service.ServiceException)22 IOException (java.io.IOException)15 Date (java.util.Date)12 ArrayList (java.util.ArrayList)8 JSONArray (org.json.JSONArray)8 Auth (com.qiniu.util.Auth)7 FreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.FreeMarkerRenderer)7 ConsoleRenderer (org.b3log.solo.processor.renderer.ConsoleRenderer)7 ParseException (java.text.ParseException)6 List (java.util.List)6 EventException (org.b3log.latke.event.EventException)3 JSONException (org.json.JSONException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Locale (java.util.Locale)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2