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.DateUtil;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.undertow.util.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||
* @date : 2017/11/14
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_post")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
|
@ -161,8 +162,13 @@ public class Post implements Serializable {
|
|||
@PrePersist
|
||||
public void prePersist() {
|
||||
DateTime now = DateUtil.date();
|
||||
postDate = now;
|
||||
postUpdate = now;
|
||||
if (postDate == null) {
|
||||
postDate = now;
|
||||
}
|
||||
|
||||
if (postUpdate == null) {
|
||||
postUpdate = now;
|
||||
}
|
||||
postId = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@ public class MarkdownUtils {
|
|||
/**
|
||||
* 渲染 Markdown
|
||||
*
|
||||
* @see https://github.com/otale/tale/blob/master/src/main/java/com/tale/utils/TaleUtils.java
|
||||
* @param content content
|
||||
* @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) {
|
||||
final Node document = PARSER.parse(content);
|
||||
|
|
|
@ -175,11 +175,20 @@ public class AdminController extends BaseController {
|
|||
} else {
|
||||
//更新失败次数
|
||||
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());
|
||||
}
|
||||
|
||||
// Log login error detail
|
||||
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}));
|
||||
}
|
||||
}
|
||||
|
@ -292,29 +301,37 @@ public class AdminController extends BaseController {
|
|||
if (!CollectionUtils.isEmpty(frontMatters)) {
|
||||
// Iterate the map and inner list
|
||||
frontMatters.forEach((key, elementValue) -> elementValue.forEach(ele -> {
|
||||
if ("title".equals(key)) {
|
||||
post.setPostTitle(ele);
|
||||
} else if ("date".equals(key)) {
|
||||
post.setPostDate(DateUtil.parse(ele));
|
||||
} else if ("updated".equals(key)) {
|
||||
post.setPostUpdate(DateUtil.parse(ele));
|
||||
} else if ("tags".equals(key)) {
|
||||
Tag tag = Optional.ofNullable(tagService.findTagByTagName(ele)).orElseGet(() -> {
|
||||
Tag aTag = new Tag();
|
||||
aTag.setTagName(ele);
|
||||
aTag.setTagUrl(ele);
|
||||
return tagService.create(aTag);
|
||||
});
|
||||
tags.add(tag);
|
||||
} else if ("categories".equals(key)) {
|
||||
Category category = Optional.ofNullable(categoryService.findByCateName(ele)).orElseGet(() -> {
|
||||
Category catg = new Category();
|
||||
catg.setCateName(ele);
|
||||
catg.setCateUrl(ele);
|
||||
catg.setCateDesc(ele);
|
||||
return categoryService.create(catg);
|
||||
});
|
||||
categories.add(category);
|
||||
switch (key) {
|
||||
case "title":
|
||||
post.setPostTitle(ele);
|
||||
break;
|
||||
case "date":
|
||||
post.setPostDate(DateUtil.parse(ele));
|
||||
break;
|
||||
case "updated":
|
||||
post.setPostUpdate(DateUtil.parse(ele));
|
||||
break;
|
||||
case "tags":
|
||||
Tag tag = Optional.ofNullable(tagService.findTagByTagName(ele)).orElseGet(() -> {
|
||||
Tag aTag = new Tag();
|
||||
aTag.setTagName(ele);
|
||||
aTag.setTagUrl(ele);
|
||||
return tagService.create(aTag);
|
||||
});
|
||||
tags.add(tag);
|
||||
break;
|
||||
case "categories":
|
||||
Category category = Optional.ofNullable(categoryService.findByCateName(ele)).orElseGet(() -> {
|
||||
Category catg = new Category();
|
||||
catg.setCateName(ele);
|
||||
catg.setCateUrl(ele);
|
||||
catg.setCateDesc(ele);
|
||||
return categoryService.create(catg);
|
||||
});
|
||||
categories.add(category);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -323,7 +340,6 @@ public class AdminController extends BaseController {
|
|||
post.setPostTitle(file.getOriginalFilename());
|
||||
}
|
||||
|
||||
|
||||
post.setPostContentMd(markdown);
|
||||
post.setPostContent(content);
|
||||
post.setPostType(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
|
@ -332,6 +348,9 @@ public class AdminController extends BaseController {
|
|||
post.setTags(tags);
|
||||
post.setCategories(categories);
|
||||
post.setPostUrl(StrUtil.removeSuffix(file.getOriginalFilename(), ".md"));
|
||||
|
||||
log.debug("Post you imported just now: [{}]", post);
|
||||
|
||||
postService.create(post);
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue