mirror of https://github.com/halo-dev/halo
Update cc.ryanc.halo.web.controller.admin.AdminController
parent
a7aa86404f
commit
fb04fc8b00
|
@ -3,8 +3,8 @@ package cc.ryanc.halo.model.domain;
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.undertow.util.DateUtils;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
import org.springframework.data.annotation.LastModifiedDate;
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||||
* @date : 2017/11/14
|
* @date : 2017/11/14
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@ToString
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "halo_post")
|
@Table(name = "halo_post")
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@ -161,8 +162,13 @@ public class Post implements Serializable {
|
||||||
@PrePersist
|
@PrePersist
|
||||||
public void prePersist() {
|
public void prePersist() {
|
||||||
DateTime now = DateUtil.date();
|
DateTime now = DateUtil.date();
|
||||||
|
if (postDate == null) {
|
||||||
postDate = now;
|
postDate = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (postUpdate == null) {
|
||||||
postUpdate = now;
|
postUpdate = now;
|
||||||
|
}
|
||||||
postId = null;
|
postId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,9 @@ public class MarkdownUtils {
|
||||||
/**
|
/**
|
||||||
* 渲染 Markdown
|
* 渲染 Markdown
|
||||||
*
|
*
|
||||||
* @see https://github.com/otale/tale/blob/master/src/main/java/com/tale/utils/TaleUtils.java
|
|
||||||
* @param content content
|
* @param content content
|
||||||
* @return String
|
* @return String
|
||||||
|
* @see <a href="https://github.com/otale/tale/blob/master/src/main/java/com/tale/utils/TaleUtils.java">TaleUtils.java</a>
|
||||||
*/
|
*/
|
||||||
public static String renderMarkdown(String content) {
|
public static String renderMarkdown(String content) {
|
||||||
final Node document = PARSER.parse(content);
|
final Node document = PARSER.parse(content);
|
||||||
|
|
|
@ -175,11 +175,20 @@ public class AdminController extends BaseController {
|
||||||
} else {
|
} else {
|
||||||
//更新失败次数
|
//更新失败次数
|
||||||
final Integer errorCount = userService.updateUserLoginError();
|
final Integer errorCount = userService.updateUserLoginError();
|
||||||
|
|
||||||
|
Integer limitCount = CommonParamsEnum.FIVE.getValue();
|
||||||
|
|
||||||
|
log.error("Login failure count: [{}], but limit count: [{}]", errorCount, limitCount);
|
||||||
|
|
||||||
//超过五次禁用账户
|
//超过五次禁用账户
|
||||||
if (errorCount >= CommonParamsEnum.FIVE.getValue()) {
|
if (errorCount >= limitCount) {
|
||||||
|
log.error("Exceeded login limit. You have been locked permanently");
|
||||||
userService.updateUserLoginEnable(TrueFalseEnum.FALSE.getDesc());
|
userService.updateUserLoginEnable(TrueFalseEnum.FALSE.getDesc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log login error detail
|
||||||
logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_ERROR + "[" + HtmlUtil.escape(loginName) + "," + HtmlUtil.escape(loginPwd) + "]", request);
|
logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_ERROR + "[" + HtmlUtil.escape(loginName) + "," + HtmlUtil.escape(loginPwd) + "]", request);
|
||||||
|
|
||||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.login.failed", new Integer[]{5 - errorCount}));
|
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.login.failed", new Integer[]{5 - errorCount}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,13 +301,17 @@ public class AdminController extends BaseController {
|
||||||
if (!CollectionUtils.isEmpty(frontMatters)) {
|
if (!CollectionUtils.isEmpty(frontMatters)) {
|
||||||
// Iterate the map and inner list
|
// Iterate the map and inner list
|
||||||
frontMatters.forEach((key, elementValue) -> elementValue.forEach(ele -> {
|
frontMatters.forEach((key, elementValue) -> elementValue.forEach(ele -> {
|
||||||
if ("title".equals(key)) {
|
switch (key) {
|
||||||
|
case "title":
|
||||||
post.setPostTitle(ele);
|
post.setPostTitle(ele);
|
||||||
} else if ("date".equals(key)) {
|
break;
|
||||||
|
case "date":
|
||||||
post.setPostDate(DateUtil.parse(ele));
|
post.setPostDate(DateUtil.parse(ele));
|
||||||
} else if ("updated".equals(key)) {
|
break;
|
||||||
|
case "updated":
|
||||||
post.setPostUpdate(DateUtil.parse(ele));
|
post.setPostUpdate(DateUtil.parse(ele));
|
||||||
} else if ("tags".equals(key)) {
|
break;
|
||||||
|
case "tags":
|
||||||
Tag tag = Optional.ofNullable(tagService.findTagByTagName(ele)).orElseGet(() -> {
|
Tag tag = Optional.ofNullable(tagService.findTagByTagName(ele)).orElseGet(() -> {
|
||||||
Tag aTag = new Tag();
|
Tag aTag = new Tag();
|
||||||
aTag.setTagName(ele);
|
aTag.setTagName(ele);
|
||||||
|
@ -306,7 +319,8 @@ public class AdminController extends BaseController {
|
||||||
return tagService.create(aTag);
|
return tagService.create(aTag);
|
||||||
});
|
});
|
||||||
tags.add(tag);
|
tags.add(tag);
|
||||||
} else if ("categories".equals(key)) {
|
break;
|
||||||
|
case "categories":
|
||||||
Category category = Optional.ofNullable(categoryService.findByCateName(ele)).orElseGet(() -> {
|
Category category = Optional.ofNullable(categoryService.findByCateName(ele)).orElseGet(() -> {
|
||||||
Category catg = new Category();
|
Category catg = new Category();
|
||||||
catg.setCateName(ele);
|
catg.setCateName(ele);
|
||||||
|
@ -315,6 +329,9 @@ public class AdminController extends BaseController {
|
||||||
return categoryService.create(catg);
|
return categoryService.create(catg);
|
||||||
});
|
});
|
||||||
categories.add(category);
|
categories.add(category);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -323,7 +340,6 @@ public class AdminController extends BaseController {
|
||||||
post.setPostTitle(file.getOriginalFilename());
|
post.setPostTitle(file.getOriginalFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
post.setPostContentMd(markdown);
|
post.setPostContentMd(markdown);
|
||||||
post.setPostContent(content);
|
post.setPostContent(content);
|
||||||
post.setPostType(PostTypeEnum.POST_TYPE_POST.getDesc());
|
post.setPostType(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||||
|
@ -332,6 +348,9 @@ public class AdminController extends BaseController {
|
||||||
post.setTags(tags);
|
post.setTags(tags);
|
||||||
post.setCategories(categories);
|
post.setCategories(categories);
|
||||||
post.setPostUrl(StrUtil.removeSuffix(file.getOriginalFilename(), ".md"));
|
post.setPostUrl(StrUtil.removeSuffix(file.getOriginalFilename(), ".md"));
|
||||||
|
|
||||||
|
log.debug("Post you imported just now: [{}]", post);
|
||||||
|
|
||||||
postService.create(post);
|
postService.create(post);
|
||||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode());
|
return new JsonResult(ResultCodeEnum.SUCCESS.getCode());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue