use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method chargePoint.
/**
* Charges a user's point.
*
* @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}/charge-point", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void chargePoint(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userId) throws Exception {
final String pointStr = request.getParameter(Common.POINT);
final String memo = request.getParameter("memo");
if (StringUtils.isBlank(pointStr) || StringUtils.isBlank(memo) || !Strings.isNumeric(memo.split("-")[0])) {
LOGGER.warn("Charge point memo format error");
response.sendRedirect(Latkes.getServePath() + "/admin/user/" + userId);
return;
}
try {
final int point = Integer.valueOf(pointStr);
final String transferId = pointtransferMgmtService.transfer(Pointtransfer.ID_C_SYS, userId, Pointtransfer.TRANSFER_TYPE_C_CHARGE, point, memo, System.currentTimeMillis());
final JSONObject notification = new JSONObject();
notification.put(Notification.NOTIFICATION_USER_ID, userId);
notification.put(Notification.NOTIFICATION_DATA_ID, transferId);
notificationMgmtService.addPointChargeNotification(notification);
} catch (final NumberFormatException | ServiceException e) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, e.getMessage());
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
response.sendRedirect(Latkes.getServePath() + "/admin/user/" + userId);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method showMisc.
/**
* Shows 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.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showMisc(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();
final List<JSONObject> misc = optionQueryService.getMisc();
dataModel.put(Option.OPTIONS, misc);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method updateTag.
/**
* Updates a tag.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @param tagId the specified tag id
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/tag/{tagId}", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateTag(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String tagId) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/tag.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
JSONObject tag = tagQueryService.getTag(tagId);
final String oldTitle = tag.optString(Tag.TAG_TITLE);
final Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
final String name = parameterNames.nextElement();
final String value = request.getParameter(name);
if (name.equals(Tag.TAG_REFERENCE_CNT) || name.equals(Tag.TAG_COMMENT_CNT) || name.equals(Tag.TAG_FOLLOWER_CNT) || name.contains(Tag.TAG_LINK_CNT) || name.contains(Tag.TAG_STATUS) || name.equals(Tag.TAG_GOOD_CNT) || name.equals(Tag.TAG_BAD_CNT)) {
tag.put(name, Integer.valueOf(value));
} else {
tag.put(name, value);
}
}
final String newTitle = tag.optString(Tag.TAG_TITLE);
if (oldTitle.equalsIgnoreCase(newTitle)) {
tagMgmtService.updateTag(tagId, tag);
}
tag = tagQueryService.getTag(tagId);
dataModel.put(Tag.TAG, tag);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method showRoles.
/**
* Shows roles.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/roles", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showRoles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/roles.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
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);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method updateUserName.
/**
* Updates a user's username.
*
* @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}/username", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateUserName(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userId) throws Exception {
final JSONObject user = userQueryService.getUser(userId);
final String oldUserName = user.optString(User.USER_NAME);
final String newUserName = request.getParameter(User.USER_NAME);
if (oldUserName.equals(newUserName)) {
response.sendRedirect(Latkes.getServePath() + "/admin/user/" + userId);
return;
}
user.put(User.USER_NAME, newUserName);
try {
userMgmtService.updateUserName(userId, user);
} catch (final ServiceException e) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, e.getMessage());
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
response.sendRedirect(Latkes.getServePath() + "/admin/user/" + userId);
}
Aggregations