mirror of https://github.com/halo-dev/halo
Merge remote-tracking branch 'origin/v1' into v1
commit
a10fa0e312
|
@ -79,7 +79,8 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
|
|||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
String workDir = FILE_PROTOCOL + haloProperties.getWorkDir();
|
||||
registry.addResourceHandler("/static/**")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
.addResourceLocations("classpath:/static/")
|
||||
.addResourceLocations(workDir + "static/");
|
||||
registry.addResourceHandler("/**")
|
||||
.addResourceLocations(workDir + "templates/themes/")
|
||||
.addResourceLocations(workDir + "templates/admin/")
|
||||
|
|
|
@ -43,8 +43,10 @@ public class JournalCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("latest")
|
||||
public List<JournalCommentWithJournalVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
return journalCommentService.convertToWithJournalVo(journalCommentService.pageLatest(top).getContent());
|
||||
public List<JournalCommentWithJournalVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||
List<JournalComment> latestComments = journalCommentService.pageLatest(top, status).getContent();
|
||||
return journalCommentService.convertToWithJournalVo(latestComments);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
|
|
|
@ -43,16 +43,12 @@ public class PostCommentController {
|
|||
|
||||
@GetMapping("latest")
|
||||
@ApiOperation("Pages latest comments")
|
||||
public List<PostCommentWithPostVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
List<PostComment> content = postCommentService.pageLatest(top).getContent();
|
||||
return postCommentService.convertToWithPostVo(content);
|
||||
}
|
||||
|
||||
@GetMapping("latest/{status}")
|
||||
@ApiOperation("Pages latest comments by status")
|
||||
public List<PostCommentWithPostVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||
@PathVariable("status") CommentStatus status) {
|
||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||
// Get latest comment
|
||||
List<PostComment> content = postCommentService.pageLatest(top, status).getContent();
|
||||
|
||||
// Convert and return
|
||||
return postCommentService.convertToWithPostVo(content);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,9 @@ public class SheetCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("latest")
|
||||
public List<SheetCommentWithSheetVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
Page<SheetComment> sheetCommentPage = sheetCommentService.pageLatest(top);
|
||||
public List<SheetCommentWithSheetVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||
Page<SheetComment> sheetCommentPage = sheetCommentService.pageLatest(top, status);
|
||||
return sheetCommentService.convertToWithPostVo(sheetCommentPage.getContent());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package run.halo.app.controller.content;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -13,6 +12,8 @@ import run.halo.app.service.SheetService;
|
|||
import run.halo.app.service.ThemeService;
|
||||
|
||||
/**
|
||||
* Content sheet controller.
|
||||
*
|
||||
* @author ryanwang
|
||||
* @date : 2019-03-21
|
||||
*/
|
||||
|
@ -68,10 +69,8 @@ public class ContentSheetController {
|
|||
model.addAttribute("post", sheetService.convertToDetail(sheet));
|
||||
model.addAttribute("is_sheet", true);
|
||||
|
||||
if (StrUtil.isNotEmpty(sheet.getTemplate())) {
|
||||
if (themeService.templateExists(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate() + HaloConst.SUFFIX_FTL)) {
|
||||
return themeService.render(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate());
|
||||
}
|
||||
if (themeService.templateExists(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate() + HaloConst.SUFFIX_FTL)) {
|
||||
return themeService.render(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate());
|
||||
}
|
||||
return themeService.render("sheet");
|
||||
}
|
||||
|
|
|
@ -52,38 +52,8 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
// save halo version to database
|
||||
this.printStartInfo();
|
||||
this.initThemes();
|
||||
|
||||
// Init user in development environment
|
||||
// if (!haloProperties.isProductionEnv()) {
|
||||
// initAnTestUserIfAbsent();
|
||||
// }
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Initialize an test user if absent
|
||||
// */
|
||||
// private void initAnTestUserIfAbsent() {
|
||||
// // Create an user if absent
|
||||
// List<User> users = userService.listAll();
|
||||
//
|
||||
// if (users.isEmpty()) {
|
||||
// UserParam userParam = new UserParam();
|
||||
// userParam.setUsername("test");
|
||||
// userParam.setNickname("developer");
|
||||
// userParam.setEmail("test@test.com");
|
||||
// userParam.setPassword("opentest");
|
||||
//
|
||||
// log.debug("Initializing a test user: [{}]", userParam);
|
||||
//
|
||||
// // Validate the user param
|
||||
// ValidationUtils.validate(userParam, CreateCheck.class);
|
||||
//
|
||||
// User testUser = userService.createBy(userParam);
|
||||
//
|
||||
// log.debug("Initialized a test user: [{}]", testUser);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void printStartInfo() {
|
||||
String blogUrl = optionService.getBlogBaseUrl();
|
||||
|
||||
|
@ -102,7 +72,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
// Whether the blog has initialized
|
||||
Boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false);
|
||||
|
||||
if (isInstalled) {
|
||||
if (haloProperties.isProductionEnv() && isInstalled) {
|
||||
// Skip
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.service;
|
||||
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import run.halo.app.handler.theme.config.support.Group;
|
||||
import run.halo.app.handler.theme.config.support.ThemeProperty;
|
||||
|
@ -65,6 +66,9 @@ public interface ThemeService {
|
|||
*/
|
||||
String THEMES_CACHE_KEY = "themes";
|
||||
|
||||
/**
|
||||
* Custom sheet prefix.
|
||||
*/
|
||||
String CUSTOM_SHEET_PREFIX = "sheet_";
|
||||
|
||||
/**
|
||||
|
@ -79,11 +83,11 @@ public interface ThemeService {
|
|||
/**
|
||||
* Get theme property by theme id.
|
||||
*
|
||||
* @param themeId must not be blank
|
||||
* @param themeId theme id
|
||||
* @return a optional theme property
|
||||
*/
|
||||
@NonNull
|
||||
Optional<ThemeProperty> getThemeBy(@NonNull String themeId);
|
||||
Optional<ThemeProperty> getThemeBy(@Nullable String themeId);
|
||||
|
||||
/**
|
||||
* Gets all themes
|
||||
|
@ -123,15 +127,15 @@ public interface ThemeService {
|
|||
* @param template template must not be blank
|
||||
* @return boolean
|
||||
*/
|
||||
boolean templateExists(@NonNull String template);
|
||||
boolean templateExists(@Nullable String template);
|
||||
|
||||
/**
|
||||
* Checks whether theme exists under template path
|
||||
*
|
||||
* @param themeId theme name
|
||||
* @param themeId theme id
|
||||
* @return boolean
|
||||
*/
|
||||
boolean themeExists(@NonNull String themeId);
|
||||
boolean themeExists(@Nullable String themeId);
|
||||
|
||||
/**
|
||||
* Gets theme base path.
|
||||
|
|
|
@ -59,7 +59,7 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
|
|||
* @return a page of comments
|
||||
*/
|
||||
@NonNull
|
||||
Page<COMMENT> pageLatest(int top, CommentStatus status);
|
||||
Page<COMMENT> pageLatest(int top, @Nullable CommentStatus status);
|
||||
|
||||
/**
|
||||
* Pages comments.
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.util.Assert;
|
||||
import run.halo.app.cache.StringCacheStore;
|
||||
import run.halo.app.exception.BadRequestException;
|
||||
import run.halo.app.exception.NotFoundException;
|
||||
import run.halo.app.model.dto.StatisticDTO;
|
||||
import run.halo.app.model.entity.User;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
|
@ -78,14 +79,25 @@ public class AdminServiceImpl implements AdminService {
|
|||
Assert.notNull(loginParam, "Login param must not be null");
|
||||
|
||||
String username = loginParam.getUsername();
|
||||
User user = Validator.isEmail(username) ?
|
||||
userService.getByEmailOfNonNull(username) : userService.getByUsernameOfNonNull(username);
|
||||
|
||||
String mismatchTip = "用户名或者密码不正确";
|
||||
|
||||
final User user;
|
||||
|
||||
try {
|
||||
// Get user by username or email
|
||||
user = Validator.isEmail(username) ?
|
||||
userService.getByEmailOfNonNull(username) : userService.getByUsernameOfNonNull(username);
|
||||
} catch (NotFoundException e) {
|
||||
log.error("Failed to find user by name: " + username, e);
|
||||
throw new BadRequestException(mismatchTip);
|
||||
}
|
||||
|
||||
userService.mustNotExpire(user);
|
||||
|
||||
if (!userService.passwordMatch(user, loginParam.getPassword())) {
|
||||
// If the password is mismatch
|
||||
throw new BadRequestException("用户名或者密码不正确");
|
||||
throw new BadRequestException(mismatchTip);
|
||||
}
|
||||
|
||||
if (SecurityContextHolder.getContext().isAuthenticated()) {
|
||||
|
|
|
@ -75,12 +75,16 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
|||
|
||||
@Override
|
||||
public Page<COMMENT> pageLatest(int top) {
|
||||
return listAll(ServiceUtils.buildLatestPageable(top));
|
||||
return pageLatest(top, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<COMMENT> pageLatest(int top,CommentStatus status){
|
||||
return baseCommentRepository.findAllByStatus(status,ServiceUtils.buildLatestPageable(top));
|
||||
public Page<COMMENT> pageLatest(int top, CommentStatus status) {
|
||||
if (status == null) {
|
||||
return listAll(ServiceUtils.buildLatestPageable(top));
|
||||
}
|
||||
|
||||
return baseCommentRepository.findAllByStatus(status, ServiceUtils.buildLatestPageable(top));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -105,7 +105,9 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
|
||||
@Override
|
||||
public Optional<ThemeProperty> getThemeBy(String themeId) {
|
||||
Assert.hasText(themeId, "Theme id must not be blank");
|
||||
if (StringUtils.isBlank(themeId)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
// Get all themes
|
||||
Set<ThemeProperty> themes = getThemes();
|
||||
|
@ -181,7 +183,9 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
|
||||
@Override
|
||||
public boolean templateExists(String template) {
|
||||
Assert.hasText(template, "Template must not be blank");
|
||||
if (StringUtils.isBlank(template)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Resolve template path
|
||||
Path templatePath = Paths.get(getActivatedTheme().getThemePath(), template);
|
||||
|
@ -507,7 +511,7 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
*/
|
||||
private void setActivatedTheme(@Nullable ThemeProperty activatedTheme) {
|
||||
this.activatedTheme = activatedTheme;
|
||||
this.activatedThemeId = activatedTheme.getId();
|
||||
this.activatedThemeId = Optional.ofNullable(activatedTheme).map(ThemeProperty::getId).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue