Commit da54d798 authored by Liang Ding's avatar Liang Ding

🐛 修复皮肤动态切换问题

parent f71ba465
......@@ -61,7 +61,7 @@ import java.util.Set;
* Solo Servlet listener.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.9.2.20, Apr 10, 2017
* @version 1.9.3.20, May 7, 2017
* @since 0.3.1
*/
public final class SoloServletListener extends AbstractServletListener {
......@@ -315,7 +315,6 @@ public final class SoloServletListener extends AbstractServletListener {
final String requestURI = httpServletRequest.getRequestURI();
String desiredView = Requests.mobileSwitchToggle(httpServletRequest);
if (desiredView == null && !Requests.mobileRequest(httpServletRequest) || desiredView != null && desiredView.equals("normal")) {
desiredView = preference.getString(Skin.SKIN_DIR_NAME);
} else {
......
......@@ -52,13 +52,14 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import java.util.Set;
/**
* Index processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.2.2.6, Dec 27, 2015
* @version 1.2.3.6, May 7, 2017
* @since 0.3.1
*/
@RequestProcessor
......@@ -117,13 +118,22 @@ public class IndexProcessor {
if (null != specifiedSkin) {
if ("default".equals(specifiedSkin)) {
specifiedSkin = preference.optString(Option.ID_C_SKIN_DIR_NAME);
final Cookie cookie = new Cookie("skin", null);
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
}
} else {
specifiedSkin = preference.optString(Option.ID_C_SKIN_DIR_NAME);
}
final Set<String> skinDirNames = Skins.getSkinDirNames();
if (skinDirNames.contains(specifiedSkin)) {
Templates.MAIN_CFG.setServletContextForTemplateLoading(SoloServletListener.getServletContext(),
"/skins/" + specifiedSkin);
request.setAttribute(Keys.TEMAPLTE_DIR_NAME, specifiedSkin);
}
Skins.fillLangs(preference.optString(Option.ID_C_LOCALE_STRING), (String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), dataModel);
......@@ -146,9 +156,11 @@ public class IndexProcessor {
statisticMgmtService.incBlogViewCount(request, response);
// https://github.com/b3log/solo/issues/12060
if (!preference.optString(Skin.SKIN_DIR_NAME).equals(specifiedSkin) && !Requests.mobileRequest(request)) {
final Cookie cookie = new Cookie(Skin.SKIN, specifiedSkin);
cookie.setPath("/");
response.addCookie(cookie);
}
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......
......@@ -57,15 +57,18 @@ public class UserMgmtService {
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(UserMgmtService.class);
/**
* Length of hashed password.
*/
private static final int HASHED_PASSWORD_LENGTH = 32;
/**
* User repository.
*/
@Inject
private UserRepository userRepository;
/**
* Language service.
*/
......@@ -120,7 +123,6 @@ public class UserMgmtService {
LOGGER.log(Level.TRACE, "Parses cookie failed, clears the cookie [name=b3log-latke]");
final Cookie cookie = new Cookie("b3log-latke", null);
cookie.setMaxAge(0);
cookie.setPath("/");
......@@ -230,6 +232,7 @@ public class UserMgmtService {
}
userRepository.update(userId, oldUser);
transaction.commit();
} catch (final RepositoryException e) {
if (transaction.isActive()) {
......
......@@ -16,6 +16,7 @@
package org.b3log.solo.util;
import freemarker.template.TemplateExceptionHandler;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.LatkeBeanManager;
import org.b3log.latke.ioc.Lifecycle;
......@@ -25,6 +26,7 @@ import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.LangPropsServiceImpl;
import org.b3log.latke.service.ServiceException;
import org.b3log.latke.util.Locales;
import org.b3log.latke.util.Requests;
import org.b3log.latke.util.Stopwatchs;
import org.b3log.latke.util.Strings;
import org.b3log.latke.util.freemarker.Templates;
......@@ -42,7 +44,7 @@ import java.util.*;
* Skin utilities.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.4.8, Nov 2, 2016
* @version 1.1.5.8, May 7, 2017
* @since 0.3.1
*/
public final class Skins {
......@@ -157,8 +159,7 @@ public final class Skins {
final Set<String> ret = new HashSet<String>();
@SuppressWarnings("unchecked")
final Set<String> resourcePaths = servletContext.getResourcePaths("/skins");
@SuppressWarnings("unchecked") final Set<String> resourcePaths = servletContext.getResourcePaths("/skins");
for (final String path : resourcePaths) {
final String dirName = path.substring("/skins".length() + 1, path.length() - 1);
......@@ -174,7 +175,8 @@ public final class Skins {
}
/**
* Gets skin directory name from the specified request.
* Gets skin directory name from the specified request. Refers to https://github.com/b3log/solo/issues/12060 for
* more details.
*
* @param request the specified request
* @return directory name, or {@code "default"} if not found
......@@ -182,16 +184,18 @@ public final class Skins {
public static String getSkinDirName(final HttpServletRequest request) {
// https://github.com/b3log/solo/issues/12060
if (Requests.mobileRequest(request)) {
return (String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME); // resolved in listener
}
// 1. Get skin from query
final String specifiedSkin = request.getParameter(Skin.SKIN);
if ("default".equals(specifiedSkin)) {
return "default";
}
if (!Strings.isEmptyOrNull(specifiedSkin)) {
final Set<String> skinDirNames = Skins.getSkinDirNames();
if (skinDirNames.contains(specifiedSkin)) {
return specifiedSkin;
} else {
......
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