Merge remote-tracking branch 'origin/v1' into v1

# Conflicts:
#	src/main/java/run/halo/app/model/freemarker/tag/PostTagDirective.java
pull/146/head
ruibaby 2019-04-30 00:51:45 +08:00
commit 57c0f80399
2 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,8 @@
package run.halo.app.config; package run.halo.app.config;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.jackson.JsonComponentModule; import org.springframework.boot.jackson.JsonComponentModule;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -20,11 +22,12 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import run.halo.app.config.properties.HaloProperties; import run.halo.app.config.properties.HaloProperties;
import run.halo.app.controller.support.PageJacksonSerializer;
import run.halo.app.factory.StringToEnumConverterFactory; import run.halo.app.factory.StringToEnumConverterFactory;
import run.halo.app.model.support.HaloConst; import run.halo.app.model.support.HaloConst;
import run.halo.app.security.resolver.AuthenticationArgumentResolver; import run.halo.app.security.resolver.AuthenticationArgumentResolver;
import run.halo.app.controller.support.PageJacksonSerializer;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -111,13 +114,20 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
* @return new FreeMarkerConfigurer * @return new FreeMarkerConfigurer
*/ */
@Bean @Bean
public FreeMarkerConfigurer freemarkerConfig(HaloProperties haloProperties) { public FreeMarkerConfigurer freemarkerConfig(HaloProperties haloProperties) throws IOException, TemplateException {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer(); FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPaths(FILE_PROTOCOL + haloProperties.getWorkDir() + "templates/", "classpath:/templates/"); configurer.setTemplateLoaderPaths(FILE_PROTOCOL + haloProperties.getWorkDir() + "templates/", "classpath:/templates/");
configurer.setDefaultEncoding("UTF-8"); configurer.setDefaultEncoding("UTF-8");
// if (haloProperties.isProductionEnv()) {
// configurer.getConfiguration().setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); // Predefine configuration
// } freemarker.template.Configuration configuration = configurer.createConfiguration();
if (haloProperties.isProductionEnv()) {
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
}
// Set predefined freemarker configuration
configurer.setConfiguration(configuration);
return configurer; return configurer;
} }

View File

@ -154,7 +154,7 @@ public class AdminServiceImpl implements AdminService {
Assert.hasText(refreshToken, "Refresh token must not be blank"); Assert.hasText(refreshToken, "Refresh token must not be blank");
Integer userId = cacheStore.getAny(SecurityUtils.buildTokenRefreshKey(refreshToken), Integer.class) Integer userId = cacheStore.getAny(SecurityUtils.buildTokenRefreshKey(refreshToken), Integer.class)
.orElseThrow(() -> new BadRequestException("The refresh token may have been expired already")); .orElseThrow(() -> new BadRequestException("The refresh token may have been expired already").setErrorData(refreshToken));
// Get user info // Get user info
User user = userService.getById(userId); User user = userService.getById(userId);