use of org.b3log.latke.servlet.annotation.Before 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");
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class SettingsProcessor method updateI18n.
/**
* Updates user i18n.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
*/
@RequestProcessing(value = "/settings/i18n", method = HTTPRequestMethod.POST)
@Before(adviceClass = { LoginCheck.class, CSRFCheck.class })
public void updateI18n(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) {
context.renderJSON();
JSONObject requestJSONObject;
try {
requestJSONObject = Requests.parseRequestJSONObject(request, response);
request.setAttribute(Keys.REQUEST, requestJSONObject);
} catch (final Exception e) {
LOGGER.warn(e.getMessage());
requestJSONObject = new JSONObject();
}
String userLanguage = requestJSONObject.optString(UserExt.USER_LANGUAGE, Locale.SIMPLIFIED_CHINESE.toString());
if (!Languages.getAvailableLanguages().contains(userLanguage)) {
userLanguage = Locale.US.toString();
}
String userTimezone = requestJSONObject.optString(UserExt.USER_TIMEZONE, TimeZone.getDefault().getID());
if (!Arrays.asList(TimeZone.getAvailableIDs()).contains(userTimezone)) {
userTimezone = TimeZone.getDefault().getID();
}
try {
final JSONObject user = userQueryService.getCurrentUser(request);
user.put(UserExt.USER_LANGUAGE, userLanguage);
user.put(UserExt.USER_TIMEZONE, userTimezone);
userMgmtService.updateUser(user.optString(Keys.OBJECT_ID), user);
context.renderTrueResult();
} catch (final ServiceException e) {
context.renderMsg(e.getMessage());
}
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class SettingsProcessor method updateAvatar.
/**
* Updates user avatar.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/settings/avatar", method = HTTPRequestMethod.POST)
@Before(adviceClass = { LoginCheck.class, CSRFCheck.class, UpdateProfilesValidation.class })
public void updateAvatar(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
context.renderJSON();
final JSONObject requestJSONObject = (JSONObject) request.getAttribute(Keys.REQUEST);
final String userAvatarURL = requestJSONObject.optString(UserExt.USER_AVATAR_URL);
final JSONObject user = userQueryService.getCurrentUser(request);
user.put(UserExt.USER_AVATAR_TYPE, UserExt.USER_AVATAR_TYPE_C_UPLOAD);
user.put(UserExt.USER_UPDATE_TIME, System.currentTimeMillis());
if (Strings.contains(userAvatarURL, new String[] { "<", ">", "\"", "'" })) {
user.put(UserExt.USER_AVATAR_URL, Symphonys.get("defaultThumbnailURL"));
} else {
if (Symphonys.getBoolean("qiniu.enabled")) {
final String qiniuDomain = Symphonys.get("qiniu.domain");
if (!StringUtils.startsWith(userAvatarURL, qiniuDomain)) {
user.put(UserExt.USER_AVATAR_URL, Symphonys.get("defaultThumbnailURL"));
} else {
user.put(UserExt.USER_AVATAR_URL, userAvatarURL);
}
} else {
user.put(UserExt.USER_AVATAR_URL, userAvatarURL);
}
}
try {
userMgmtService.updateUser(user.optString(Keys.OBJECT_ID), user);
context.renderTrueResult();
} catch (final ServiceException e) {
context.renderMsg(e.getMessage());
}
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class SettingsProcessor method updateGeoStatus.
/**
* Updates user geo status.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
*/
@RequestProcessing(value = "/settings/geo/status", method = HTTPRequestMethod.POST)
@Before(adviceClass = { LoginCheck.class, CSRFCheck.class })
public void updateGeoStatus(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) {
context.renderJSON();
JSONObject requestJSONObject;
try {
requestJSONObject = Requests.parseRequestJSONObject(request, response);
request.setAttribute(Keys.REQUEST, requestJSONObject);
} catch (final Exception e) {
LOGGER.warn(e.getMessage());
requestJSONObject = new JSONObject();
}
int geoStatus = requestJSONObject.optInt(UserExt.USER_GEO_STATUS);
if (UserExt.USER_GEO_STATUS_C_PRIVATE != geoStatus && UserExt.USER_GEO_STATUS_C_PUBLIC != geoStatus) {
geoStatus = UserExt.USER_GEO_STATUS_C_PUBLIC;
}
try {
final JSONObject user = userQueryService.getCurrentUser(request);
user.put(UserExt.USER_GEO_STATUS, geoStatus);
userMgmtService.updateUser(user.optString(Keys.OBJECT_ID), user);
context.renderTrueResult();
} catch (final ServiceException e) {
context.renderMsg(e.getMessage());
}
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class ChatRoomProcessor method showChatRoom.
/**
* Shows chat room.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = { "/cr", "/chat-room", "/community" }, method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, AnonymousViewCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showChatRoom(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("chat-room.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Common.MESSAGES, messages);
dataModel.put("chatRoomMsgCnt", Symphonys.getInt("chatRoom.msgCnt"));
// Qiniu file upload authenticate
final Auth auth = Auth.create(Symphonys.get("qiniu.accessKey"), Symphonys.get("qiniu.secretKey"));
dataModel.put("qiniuUploadToken", auth.uploadToken(Symphonys.get("qiniu.bucket")));
dataModel.put("qiniuDomain", Symphonys.get("qiniu.domain"));
final long imgMaxSize = Symphonys.getLong("upload.img.maxSize");
dataModel.put("imgMaxSize", imgMaxSize);
final long fileMaxSize = Symphonys.getLong("upload.file.maxSize");
dataModel.put("fileMaxSize", fileMaxSize);
dataModel.put(Common.ONLINE_CHAT_CNT, SESSIONS.size());
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);
}
Aggregations