Search in sources :

Example 6 with ConsoleRenderer

use of org.b3log.solo.processor.renderer.ConsoleRenderer in project solo by b3log.

the class LoginProcessor method renderPage.

/**
     * Render a page template with the destination URL.
     *
     * @param context        the context
     * @param pageTemplate   the page template
     * @param destinationURL the destination URL
     * @param request        for reset password page
     * @throws JSONException    the JSONException
     * @throws ServiceException the ServiceException
     */
private void renderPage(final HTTPRequestContext context, final String pageTemplate, final String destinationURL, final HttpServletRequest request) throws JSONException, ServiceException {
    final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
    renderer.setTemplateName(pageTemplate);
    context.setRenderer(renderer);
    final Map<String, Object> dataModel = renderer.getDataModel();
    final Map<String, String> langs = langPropsService.getAll(Latkes.getLocale());
    final JSONObject preference = preferenceQueryService.getPreference();
    dataModel.putAll(langs);
    dataModel.put(Common.GOTO, destinationURL);
    dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
    dataModel.put(Common.VERSION, SoloServletListener.VERSION);
    dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion());
    dataModel.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE));
    final String token = request.getParameter("token");
    final String email = request.getParameter("login");
    final JSONObject tokenObj = optionQueryService.getOptionById(token);
    if (tokenObj == null) {
        dataModel.put("inputType", "email");
    } else {
        // TODO verify the expired time in the tokenObj
        dataModel.put("inputType", "password");
        dataModel.put("userEmailHidden", email);
    }
    final String from = request.getParameter("from");
    if ("forgot".equals(from)) {
        dataModel.put("resetMsg", langPropsService.get("resetPwdSuccessSend"));
    } else if ("reset".equals(from)) {
        dataModel.put("resetMsg", langPropsService.get("resetPwdSuccessMsg"));
    } else {
        dataModel.put("resetMsg", "");
    }
    Keys.fillRuntime(dataModel);
    filler.fillMinified(dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) ConsoleRenderer(org.b3log.solo.processor.renderer.ConsoleRenderer) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)

Example 7 with ConsoleRenderer

use of org.b3log.solo.processor.renderer.ConsoleRenderer in project solo by b3log.

the class AdminConsole method showAdminFunctions.

/**
     * Shows administrator functions with the specified context.
     *
     * @param request the specified request
     * @param context the specified context
     */
@RequestProcessing(value = { "/admin-article.do", "/admin-article-list.do", "/admin-comment-list.do", "/admin-link-list.do", "/admin-page-list.do", "/admin-others.do", "/admin-draft-list.do", "/admin-user-list.do", "/admin-plugin-list.do", "/admin-main.do", "/admin-about.do" }, method = HTTPRequestMethod.GET)
public void showAdminFunctions(final HttpServletRequest request, final HTTPRequestContext context) {
    final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
    context.setRenderer(renderer);
    final String requestURI = request.getRequestURI();
    final String templateName = StringUtils.substringBetween(requestURI, Latkes.getContextPath() + '/', ".") + ".ftl";
    LOGGER.log(Level.TRACE, "Admin function[templateName={0}]", templateName);
    renderer.setTemplateName(templateName);
    final Locale locale = Latkes.getLocale();
    final Map<String, String> langs = langPropsService.getAll(locale);
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModel.put("isMySQL", RuntimeDatabase.MYSQL == Latkes.getRuntimeDatabase());
    dataModel.putAll(langs);
    Keys.fillRuntime(dataModel);
    dataModel.put(Option.ID_C_LOCALE_STRING, locale.toString());
    fireFreeMarkerActionEvent(templateName, dataModel);
}
Also used : Locale(java.util.Locale) JSONObject(org.json.JSONObject) ConsoleRenderer(org.b3log.solo.processor.renderer.ConsoleRenderer) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 8 with ConsoleRenderer

use of org.b3log.solo.processor.renderer.ConsoleRenderer in project solo by b3log.

the class ArticleProcessor method showArticlePwdForm.

/**
     * Shows the article view password form.
     *
     * @param context the specified context
     * @param request the specified HTTP servlet request
     * @param response the specified HTTP servlet response
     * @throws Exception exception
     */
@RequestProcessing(value = "/console/article-pwd", method = HTTPRequestMethod.GET)
public void showArticlePwdForm(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final String articleId = request.getParameter("articleId");
    if (Strings.isEmptyOrNull(articleId)) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    final JSONObject article = articleQueryService.getArticleById(articleId);
    if (null == article) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
    context.setRenderer(renderer);
    renderer.setTemplateName("article-pwd.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModel.put("articleId", articleId);
    dataModel.put("articlePermalink", article.optString(Article.ARTICLE_PERMALINK));
    dataModel.put("articleTitle", article.optString(Article.ARTICLE_TITLE));
    dataModel.put("articleAbstract", article.optString(Article.ARTICLE_ABSTRACT));
    final String msg = request.getParameter(Keys.MSG);
    if (!Strings.isEmptyOrNull(msg)) {
        dataModel.put(Keys.MSG, langPropsService.get("passwordNotMatchLabel"));
    }
    final Map<String, String> langs = langPropsService.getAll(Latkes.getLocale());
    dataModel.putAll(langs);
    final JSONObject preference = preferenceQueryService.getPreference();
    dataModel.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE));
    dataModel.put(Common.VERSION, SoloServletListener.VERSION);
    dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion());
    dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
    Keys.fillRuntime(dataModel);
    filler.fillMinified(dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) ConsoleRenderer(org.b3log.solo.processor.renderer.ConsoleRenderer) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Aggregations

ConsoleRenderer (org.b3log.solo.processor.renderer.ConsoleRenderer)8 JSONObject (org.json.JSONObject)8 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)7 AbstractFreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)7 ServiceException (org.b3log.latke.service.ServiceException)3 IOException (java.io.IOException)2 Locale (java.util.Locale)2 Auth (com.qiniu.util.Auth)1 EventException (org.b3log.latke.event.EventException)1