use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class IndexProcessor method showB3log.
/**
* Shows b3log.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/b3log", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showB3log(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("other/b3log.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
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);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class LinkForgeProcessor method showLinkForge.
/**
* Shows link forge.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/forge/link", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showLinkForge(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("other/link-forge.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
final List<JSONObject> tags = linkForgeQueryService.getForgedLinks();
dataModel.put(Tag.TAGS, (Object) tags);
dataModel.put(Common.SELECTED, Common.FORGE);
final JSONObject statistic = optionQueryService.getStatistic();
final int tagCnt = statistic.optInt(Option.ID_C_STATISTIC_TAG_COUNT);
dataModel.put(Tag.TAG_T_COUNT, tagCnt);
final int linkCnt = statistic.optInt(Option.ID_C_STATISTIC_LINK_COUNT);
dataModel.put(Link.LINK_T_COUNT, linkCnt);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class LoginProcessor method showGuide.
/**
* Shows login page.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/guide", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, PermissionGrant.class, StopwatchEndAdvice.class })
public void showGuide(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
final int step = currentUser.optInt(UserExt.USER_GUIDE_STEP);
if (UserExt.USER_GUIDE_STEP_FIN == step) {
response.sendRedirect(Latkes.getServePath());
return;
}
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("/verify/guide.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Common.CURRENT_USER, currentUser);
final List<JSONObject> tags = tagQueryService.getTags(32);
dataModel.put(Tag.TAGS, tags);
final List<JSONObject> users = userQueryService.getNiceUsers(6);
final Iterator<JSONObject> iterator = users.iterator();
while (iterator.hasNext()) {
final JSONObject user = iterator.next();
if (user.optString(Keys.OBJECT_ID).equals(currentUser.optString(Keys.OBJECT_ID))) {
iterator.remove();
break;
}
}
dataModel.put(User.USERS, users);
// 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);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class LoginProcessor method showForgetPwd.
/**
* Shows forget password page.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/forget-pwd", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showForgetPwd(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
final Map<String, Object> dataModel = renderer.getDataModel();
renderer.setTemplateName("verify/forget-pwd.ftl");
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class LoginProcessor method showRegister.
/**
* Shows registration page.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/register", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showRegister(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if (null != userQueryService.getCurrentUser(request) || userMgmtService.tryLogInWithCookie(request, response)) {
response.sendRedirect(Latkes.getServePath());
return;
}
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Common.REFERRAL, "");
boolean useInvitationLink = false;
String referral = request.getParameter("r");
if (!UserRegisterValidation.invalidUserName(referral)) {
final JSONObject referralUser = userQueryService.getUserByName(referral);
if (null != referralUser) {
dataModel.put(Common.REFERRAL, referral);
final Map<String, JSONObject> permissions = roleQueryService.getUserPermissionsGrantMap(referralUser.optString(Keys.OBJECT_ID));
final JSONObject useILPermission = permissions.get(Permission.PERMISSION_ID_C_COMMON_USE_INVITATION_LINK);
useInvitationLink = useILPermission.optBoolean(Permission.PERMISSION_T_GRANT);
}
}
final String code = request.getParameter("code");
if (Strings.isEmptyOrNull(code)) {
// Register Step 1
renderer.setTemplateName("verify/register.ftl");
} else {
// Register Step 2
final JSONObject verifycode = verifycodeQueryService.getVerifycode(code);
if (null == verifycode) {
dataModel.put(Keys.MSG, langPropsService.get("verifycodeExpiredLabel"));
renderer.setTemplateName("/error/custom.ftl");
} else {
renderer.setTemplateName("verify/register2.ftl");
final String userId = verifycode.optString(Verifycode.USER_ID);
final JSONObject user = userQueryService.getUser(userId);
dataModel.put(User.USER, user);
if (UserExt.USER_STATUS_C_VALID == user.optInt(UserExt.USER_STATUS) || UserExt.NULL_USER_NAME.equals(user.optString(User.USER_NAME))) {
dataModel.put(Keys.MSG, langPropsService.get("userExistLabel"));
renderer.setTemplateName("/error/custom.ftl");
} else {
referral = StringUtils.substringAfter(code, "r=");
if (!Strings.isEmptyOrNull(referral)) {
dataModel.put(Common.REFERRAL, referral);
}
}
}
}
final String allowRegister = optionQueryService.getAllowRegister();
dataModel.put(Option.ID_C_MISC_ALLOW_REGISTER, allowRegister);
if (useInvitationLink && "2".equals(allowRegister)) {
dataModel.put(Option.ID_C_MISC_ALLOW_REGISTER, "1");
}
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Aggregations