Commit 56ef1ba3 authored by Liang Ding's avatar Liang Ding

Merge remote-tracking branch 'refs/remotes/origin/2.1.0-dev'

parents 766ebac8 da54d798
......@@ -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);
}
Templates.MAIN_CFG.setServletContextForTemplateLoading(SoloServletListener.getServletContext(),
"/skins/" + specifiedSkin);
request.setAttribute(Keys.TEMAPLTE_DIR_NAME, specifiedSkin);
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
final Cookie cookie = new Cookie(Skin.SKIN, specifiedSkin);
cookie.setPath("/");
response.addCookie(cookie);
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);
......
......@@ -47,7 +47,7 @@ import javax.servlet.http.HttpServletResponse;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.1.0.6, Oct 17, 2015
* @version 1.1.0.7, May 6, 2017
* @since 0.4.0
*/
@Service
......@@ -56,7 +56,12 @@ public class UserMgmtService {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(UserMgmtService.class.getName());
private static final Logger LOGGER = Logger.getLogger(UserMgmtService.class);
/**
* Length of hashed password.
*/
private static final int HASHED_PASSWORD_LENGTH = 32;
/**
* User repository.
......@@ -70,15 +75,10 @@ public class UserMgmtService {
@Inject
private LangPropsService langPropsService;
/**
* Length of hashed password.
*/
private static final int HASHED_PASSWORD_LENGTH = 32;
/**
* Tries to login with cookie.
*
* @param request the specified request
* @param request the specified request
* @param response the specified response
*/
public void tryLogInWithCookie(final HttpServletRequest request, final HttpServletResponse response) {
......@@ -91,7 +91,6 @@ public class UserMgmtService {
try {
for (int i = 0; i < cookies.length; i++) {
final Cookie cookie = cookies[i];
if (!"b3log-latke".equals(cookie.getName())) {
continue;
}
......@@ -99,7 +98,6 @@ public class UserMgmtService {
final JSONObject cookieJSONObject = new JSONObject(cookie.getValue());
final String userEmail = cookieJSONObject.optString(User.USER_EMAIL);
if (Strings.isEmptyOrNull(userEmail)) {
break;
}
......@@ -122,10 +120,9 @@ public class UserMgmtService {
}
}
} catch (final Exception e) {
LOGGER.log(Level.WARN, "Parses cookie failed, clears the cookie[name=b3log-latke]", e);
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("/");
......@@ -136,17 +133,13 @@ public class UserMgmtService {
/**
* Updates a user by the specified request json object.
*
* @param requestJSONObject the specified request json object, for example, <pre>
* {
* "oId": "",
* "userName": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userRole": "", // optional
* "userURL": "", // optional
* }
* </pre>
*
* @param requestJSONObject the specified request json object, for example,
* "oId": "",
* "userName": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userRole": "", // optional
* "userURL": "", // optional
* @throws ServiceException service exception
*/
public void updateUser(final JSONObject requestJSONObject) throws ServiceException {
......@@ -195,7 +188,7 @@ public class UserMgmtService {
if (!Strings.isEmptyOrNull(userURL)) {
oldUser.put(User.USER_URL, userURL);
}
final String userAvatar = requestJSONObject.optString(UserExt.USER_AVATAR);
if (!StringUtils.equals(userAvatar, oldUser.optString(UserExt.USER_AVATAR))) {
oldUser.put(UserExt.USER_AVATAR, userAvatar);
......@@ -239,6 +232,7 @@ public class UserMgmtService {
}
userRepository.update(userId, oldUser);
transaction.commit();
} catch (final RepositoryException e) {
if (transaction.isActive()) {
......@@ -253,17 +247,14 @@ public class UserMgmtService {
/**
* Adds a user with the specified request json object.
*
* @param requestJSONObject the specified request json object, for example, <pre>
* {
* "userName": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userURL": "", // optional, uses 'servePath' instead if not specified
* "userRole": "", // optional, uses {@value Role#DEFAULT_ROLE} instead if not specified
* "userAvatar": "" // optional, users generated gravatar url instead if not specified
* }
* </pre>,see {@link User} for more details
*
* @param requestJSONObject the specified request json object, for example,
* "userName": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userURL": "", // optional, uses 'servePath' instead if not specified
* "userRole": "", // optional, uses {@value Role#DEFAULT_ROLE} instead if not specified
* "userAvatar": "" // optional, users generated gravatar url instead if not specified
* ,see {@link User} for more details
* @return generated user id
* @throws ServiceException service exception
*/
......
......@@ -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 {
......@@ -67,9 +69,9 @@ public final class Skins {
* Fills the specified data model with the current skink's (WebRoot/skins/${skinName}/lang/lang_xx_XX.properties)
* and core language (WebRoot/WEB-INF/classes/lang_xx_XX.properties) configurations.
*
* @param localeString the specified locale string
* @param localeString the specified locale string
* @param currentSkinDirName the specified current skin directory name
* @param dataModel the specified data model
* @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)
......@@ -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