Commit e2cf8707 authored by Liang Ding's avatar Liang Ding

💚 #12630

parent f857c29f
......@@ -35,6 +35,7 @@ import org.b3log.solo.model.Common;
import org.b3log.solo.service.DataModelService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.UserQueryService;
import org.json.JSONObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -101,12 +102,9 @@ public class ErrorProcessor {
try {
final Map<String, String> langs = langPropsService.getAll(Locales.getLocale(request));
dataModel.putAll(langs);
final JSONObject preference = preferenceQueryService.getPreference();
dataModelService.fillCommon(context, dataModel, preference);
dataModel.put(Common.LOGIN_URL, userQueryService.getLoginURL(Common.ADMIN_INDEX_URI));
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);
dataModelService.fillMinified(dataModel);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......
......@@ -102,6 +102,7 @@ public class LoginProcessor {
final JSONObject preference = preferenceQueryService.getPreference();
try {
Skins.fillLangs(preference.optString(Option.ID_C_LOCALE_STRING), (String) context.attr(Keys.TEMAPLTE_DIR_NAME), dataModel);
dataModelService.fillCommon(context, dataModel, preference);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......
......@@ -48,7 +48,7 @@ import java.util.*;
* Skin utilities.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.6.3, Oct 28, 2018
* @version 1.1.6.4, Jan 24, 2019
* @since 0.3.1
*/
public final class Skins {
......@@ -128,11 +128,14 @@ public final class Skins {
* @param dataModel the specified data model
* @throws ServiceException service exception
*/
public static void fillLangs(final String localeString, final String currentSkinDirName, final Map<String, Object> dataModel)
public static void fillLangs(final String localeString, String currentSkinDirName, final Map<String, Object> dataModel)
throws ServiceException {
Stopwatchs.start("Fill Skin Langs");
try {
if (StringUtils.isBlank(currentSkinDirName)) {
currentSkinDirName = Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME;
}
final String langName = currentSkinDirName + "." + localeString;
Map<String, String> langs = LANG_MAP.get(langName);
if (null == langs) {
......
......@@ -18,27 +18,21 @@
package org.b3log.solo.processor;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.model.User;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.MockHttpServletRequest;
import org.b3log.solo.MockHttpServletResponse;
import org.b3log.solo.model.Option;
import org.b3log.solo.util.Solos;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.Test;
import javax.servlet.http.Cookie;
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.List;
/**
* {@link LoginProcessor} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.0, Feb 18, 2017
* @version 1.0.1.1, Jan 24, 2019
* @since 1.7.0
*/
@Test(suiteName = "processor")
......@@ -65,30 +59,7 @@ public class LoginProcessorTestCase extends AbstractTestCase {
mockDispatcherServletService(request, response);
final String content = response.body();
Assert.assertTrue(StringUtils.contains(content, "<title>Admin 的个人博客 - 欢迎使用!</title>"));
}
/**
* login.
*/
@Test(dependsOnMethods = "init")
public void login() {
final MockHttpServletRequest request = mockRequest();
request.setRequestURI("/login");
request.setMethod("POST");
request.setAttribute(Keys.TEMAPLTE_DIR_NAME, Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME);
final JSONObject requestJSON = new JSONObject();
requestJSON.put(User.USER_EMAIL, "test@gmail.com");
requestJSON.put(User.USER_PASSWORD, "pass");
final BufferedReader reader = new BufferedReader(new StringReader(requestJSON.toString()));
request.setReader(reader);
final MockHttpServletResponse response = mockResponse();
mockDispatcherServletService(request, response);
final String content = response.body();
Assert.assertTrue(StringUtils.contains(content, "isLoggedIn\":true"));
Assert.assertTrue(StringUtils.contains(content, "<title>Admin 的个人博客 - 登录</title>"));
}
/**
......@@ -107,39 +78,4 @@ public class LoginProcessorTestCase extends AbstractTestCase {
Assert.assertNull(cookies.get(0).getValue());
}
/**
* showForgot.
*/
@Test(dependsOnMethods = "init")
public void showForgot() {
final MockHttpServletRequest request = mockRequest();
request.setRequestURI("/forgot");
final MockHttpServletResponse response = mockResponse();
mockDispatcherServletService(request, response);
final String content = response.body();
Assert.assertTrue(StringUtils.contains(content, " <title>Admin 的个人博客 - 忘记密码!</title>"));
}
/**
* forgot.
*/
@Test(dependsOnMethods = "init")
public void forgot() {
final MockHttpServletRequest request = mockRequest();
request.setRequestURI("/forgot");
request.setMethod("POST");
request.setAttribute(Keys.TEMAPLTE_DIR_NAME, Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME);
final JSONObject requestJSON = new JSONObject();
requestJSON.put(User.USER_EMAIL, "test@gmail.com");
final BufferedReader reader = new BufferedReader(new StringReader(requestJSON.toString()));
request.setReader(reader);
final MockHttpServletResponse response = mockResponse();
mockDispatcherServletService(request, response);
final String content = response.body();
Assert.assertTrue(StringUtils.contains(content, "succeed\":true"));
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
User-agent: *
Disallow: /*.do
Disallow: /login
Disallow: /logout
Disallow: /authors/*
Disallow: /console/*
Disallow: /error/*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment