Search in sources :

Example 41 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer 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);
}
Also used : 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 42 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer 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);
}
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 43 with AbstractFreeMarkerRenderer

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

the class LoginProcessor method showLogin.

/**
 * Shows login page.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/login", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showLogin(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);
    String referer = request.getParameter(Common.GOTO);
    if (!StringUtils.startsWith(referer, Latkes.getServePath())) {
        referer = request.getHeader("referer");
    }
    if (StringUtils.isBlank(referer)) {
        referer = Latkes.getServePath();
    }
    renderer.setTemplateName("/verify/login.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModel.put(Common.GOTO, referer);
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : 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 44 with AbstractFreeMarkerRenderer

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

the class ManProcessor method showMan.

/**
 * Shows man.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/man", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showMan(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    if (!ManQueryService.TLDR_ENABLED) {
        response.sendRedirect("https://hacpai.com/man");
        return;
    }
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("other/man.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);
    String cmd = request.getParameter(Common.CMD);
    if (StringUtils.isBlank(cmd)) {
        cmd = "man";
    }
    List<JSONObject> mans = manQueryService.getMansByCmdPrefix(cmd);
    if (mans.isEmpty()) {
        mans = manQueryService.getMansByCmdPrefix("man");
    }
    dataModel.put(Common.MANS, mans);
}
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 45 with AbstractFreeMarkerRenderer

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

the class NotificationProcessor method showFollowingNotifications.

/**
 * Shows [following] notifications.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/notifications/following", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showFollowingNotifications(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final JSONObject currentUser = userQueryService.getCurrentUser(request);
    if (null == currentUser) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("/home/notifications/following.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    final String userId = currentUser.optString(Keys.OBJECT_ID);
    String pageNumStr = request.getParameter("p");
    if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
        pageNumStr = "1";
    }
    final int pageNum = Integer.valueOf(pageNumStr);
    final int pageSize = Symphonys.getInt("followingNotificationsCnt");
    final int windowSize = Symphonys.getInt("followingNotificationsWindowSize");
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    final JSONObject result = notificationQueryService.getFollowingNotifications(avatarViewMode, userId, pageNum, pageSize);
    final List<JSONObject> followingNotifications = (List<JSONObject>) result.get(Keys.RESULTS);
    dataModel.put(Common.FOLLOWING_NOTIFICATIONS, followingNotifications);
    fillNotificationCount(userId, dataModel);
    final int recordCnt = result.getInt(Pagination.PAGINATION_RECORD_COUNT);
    final int pageCount = (int) Math.ceil((double) recordCnt / (double) pageSize);
    final List<Integer> pageNums = Paginator.paginate(pageNum, pageSize, pageCount, windowSize);
    if (!pageNums.isEmpty()) {
        dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
        dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
    }
    dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
    dataModel.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
    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