use of org.b3log.symphony.util.TimeZones in project symphony by b3log.
the class SettingsProcessor method showSettings.
/**
* Shows settings pages.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = { "/settings", "/settings/*" }, method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, PermissionGrant.class, StopwatchEndAdvice.class })
public void showSettings(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
final String requestURI = request.getRequestURI();
String page = StringUtils.substringAfter(requestURI, "/settings/");
if (StringUtils.isBlank(page)) {
page = "profile";
}
page += ".ftl";
renderer.setTemplateName("/home/settings/" + page);
final Map<String, Object> dataModel = renderer.getDataModel();
final JSONObject user = (JSONObject) request.getAttribute(User.USER);
user.put(UserExt.USER_T_CREATE_TIME, new Date(user.getLong(Keys.OBJECT_ID)));
UserProcessor.fillHomeUser(dataModel, user, roleQueryService);
final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
avatarQueryService.fillUserAvatarURL(avatarViewMode, user);
final String userId = user.optString(Keys.OBJECT_ID);
final int invitedUserCount = userQueryService.getInvitedUserCount(userId);
dataModel.put(Common.INVITED_USER_COUNT, invitedUserCount);
// Qiniu file upload authenticate
final Auth auth = Auth.create(Symphonys.get("qiniu.accessKey"), Symphonys.get("qiniu.secretKey"));
final String uploadToken = auth.uploadToken(Symphonys.get("qiniu.bucket"));
dataModel.put("qiniuUploadToken", uploadToken);
dataModel.put("qiniuDomain", Symphonys.get("qiniu.domain"));
if (!Symphonys.getBoolean("qiniu.enabled")) {
dataModel.put("qiniuUploadToken", "");
}
final long imgMaxSize = Symphonys.getLong("upload.img.maxSize");
dataModel.put("imgMaxSize", imgMaxSize);
final long fileMaxSize = Symphonys.getLong("upload.file.maxSize");
dataModel.put("fileMaxSize", fileMaxSize);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
String inviteTipLabel = (String) dataModel.get("inviteTipLabel");
inviteTipLabel = inviteTipLabel.replace("{point}", String.valueOf(Pointtransfer.TRANSFER_SUM_C_INVITE_REGISTER));
dataModel.put("inviteTipLabel", inviteTipLabel);
String pointTransferTipLabel = (String) dataModel.get("pointTransferTipLabel");
pointTransferTipLabel = pointTransferTipLabel.replace("{point}", Symphonys.get("pointTransferMin"));
dataModel.put("pointTransferTipLabel", pointTransferTipLabel);
String dataExportTipLabel = (String) dataModel.get("dataExportTipLabel");
dataExportTipLabel = dataExportTipLabel.replace("{point}", String.valueOf(Pointtransfer.TRANSFER_SUM_C_DATA_EXPORT));
dataModel.put("dataExportTipLabel", dataExportTipLabel);
final String allowRegister = optionQueryService.getAllowRegister();
dataModel.put("allowRegister", allowRegister);
String buyInvitecodeLabel = langPropsService.get("buyInvitecodeLabel");
buyInvitecodeLabel = buyInvitecodeLabel.replace("${point}", String.valueOf(Pointtransfer.TRANSFER_SUM_C_BUY_INVITECODE));
buyInvitecodeLabel = buyInvitecodeLabel.replace("${point2}", String.valueOf(Pointtransfer.TRANSFER_SUM_C_INVITECODE_USED));
dataModel.put("buyInvitecodeLabel", buyInvitecodeLabel);
final List<JSONObject> invitecodes = invitecodeQueryService.getValidInvitecodes(userId);
for (final JSONObject invitecode : invitecodes) {
String msg = langPropsService.get("expireTipLabel");
msg = msg.replace("${time}", DateFormatUtils.format(invitecode.optLong(Keys.OBJECT_ID) + Symphonys.getLong("invitecode.expired"), "yyyy-MM-dd HH:mm"));
invitecode.put(Common.MEMO, msg);
}
dataModel.put(Invitecode.INVITECODES, (Object) invitecodes);
if (requestURI.contains("function")) {
dataModel.put(Emotion.EMOTIONS, emotionQueryService.getEmojis(userId));
dataModel.put(Emotion.SHORT_T_LIST, emojiLists);
}
if (requestURI.contains("i18n")) {
dataModel.put(Common.LANGUAGES, Languages.getAvailableLanguages());
final List<JSONObject> timezones = new ArrayList<>();
final List<TimeZones.TimeZoneWithDisplayNames> timeZones = TimeZones.getInstance().getTimeZones();
for (final TimeZones.TimeZoneWithDisplayNames timeZone : timeZones) {
final JSONObject timezone = new JSONObject();
timezone.put(Common.ID, timeZone.getTimeZone().getID());
timezone.put(Common.NAME, timeZone.getDisplayName());
timezones.add(timezone);
}
dataModel.put(Common.TIMEZONES, timezones);
}
dataModel.put(Common.TYPE, "settings");
}
Aggregations