👽 修改README

pull/18/head
ruibaby 2018-05-24 15:50:40 +08:00
parent 9314847c2a
commit c1770f12a8
19 changed files with 202 additions and 86 deletions

View File

@ -43,7 +43,7 @@ Let's start: http://localhost:8090
## Demo 演示 ## Demo 演示
[界面预览](https://halo-doc.ryanc.cc/preview) [测试地址](http://39.105.26.52)[测试后台(admin,123456)](http://39.105.26.52/admin)
[Ryan0up'S Blog](https://ryanc.cc) [Ryan0up'S Blog](https://ryanc.cc)

View File

@ -0,0 +1,49 @@
package cc.ryanc.halo.model.dto;
import lombok.Data;
/**
* @author : RYAN0UP
* @version : 1.0
* @date : 2018/5/24
*/
@Data
public class JsonResult {
/**
* 01
*/
private Integer code;
/**
*
*/
private String msg;
/**
*
*/
private Object result;
/**
*
* @param code
* @param msg
*/
public JsonResult(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
/**
*
* @param code
* @param msg
* @param result
*/
public JsonResult(Integer code, String msg, Object result) {
this.code = code;
this.msg = msg;
this.result = result;
}
}

View File

@ -19,6 +19,8 @@ public interface LogsRecord {
String PUSH_POST = "发表文章"; String PUSH_POST = "发表文章";
String PUSH_PAGE = "发表页面";
String REMOVE_POST = "删除文章"; String REMOVE_POST = "删除文章";
String CHANGE_THEME = "更换主题"; String CHANGE_THEME = "更换主题";

View File

@ -3,6 +3,7 @@ package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.Attachment; import cc.ryanc.halo.model.domain.Attachment;
import cc.ryanc.halo.model.domain.Logs; import cc.ryanc.halo.model.domain.Logs;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.dto.LogsRecord; import cc.ryanc.halo.model.dto.LogsRecord;
import cc.ryanc.halo.service.AttachmentService; import cc.ryanc.halo.service.AttachmentService;
import cc.ryanc.halo.service.LogsService; import cc.ryanc.halo.service.LogsService;
@ -68,7 +69,6 @@ public class AttachmentController {
Pageable pageable = PageRequest.of(page, size, sort); Pageable pageable = PageRequest.of(page, size, sort);
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable); Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
model.addAttribute("attachments", attachments); model.addAttribute("attachments", attachments);
return "admin/admin_attachment"; return "admin/admin_attachment";
} }
@ -216,7 +216,7 @@ public class AttachmentController {
*/ */
@GetMapping(value = "/remove") @GetMapping(value = "/remove")
@ResponseBody @ResponseBody
public boolean removeAttachment(@PathParam("attachId") Long attachId, public JsonResult removeAttachment(@PathParam("attachId") Long attachId,
HttpServletRequest request) { HttpServletRequest request) {
Optional<Attachment> attachment = attachmentService.findByAttachId(attachId); Optional<Attachment> attachment = attachmentService.findByAttachId(attachId);
String delFileName = attachment.get().getAttachName(); String delFileName = attachment.get().getAttachName();
@ -249,13 +249,13 @@ public class AttachmentController {
); );
} else { } else {
log.error("删除附件[" + delFileName + "]失败!"); log.error("删除附件[" + delFileName + "]失败!");
return false; return new JsonResult(0,"删除失败!");
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("删除附件[" + delFileName + "]失败!:", e.getMessage()); log.error("删除附件[" + delFileName + "]失败!:", e.getMessage());
return false; return new JsonResult(0,"删除失败!");
} }
return true; return new JsonResult(1,"删除成功!");
} }
} }

View File

@ -1,6 +1,7 @@
package cc.ryanc.halo.web.controller.admin; package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.service.OptionsService; import cc.ryanc.halo.service.OptionsService;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -45,7 +46,7 @@ public class OptionController {
*/ */
@PostMapping(value = "/save") @PostMapping(value = "/save")
@ResponseBody @ResponseBody
public boolean saveOptions(@RequestParam Map<String, String> options) { public JsonResult saveOptions(@RequestParam Map<String, String> options) {
try { try {
optionsService.saveOptions(options); optionsService.saveOptions(options);
//刷新options //刷新options
@ -53,10 +54,10 @@ public class OptionController {
HaloConst.OPTIONS.clear(); HaloConst.OPTIONS.clear();
HaloConst.OPTIONS = optionsService.findAllOptions(); HaloConst.OPTIONS = optionsService.findAllOptions();
log.info("所保存的设置选项列表:" + options); log.info("所保存的设置选项列表:" + options);
return true; return new JsonResult(1,"保存成功!");
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:{0}", e.getMessage());
return false; return new JsonResult(0,"保存失败!");
} }
} }
} }

View File

@ -219,8 +219,16 @@ public class PageController {
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY); User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
post.setUser(user); post.setUser(user);
post.setPostType(HaloConst.POST_TYPE_PAGE); post.setPostType(HaloConst.POST_TYPE_PAGE);
if(null!=post.getPostId()){
post.setPostViews(postService.findByPostId(post.getPostId()).get().getPostViews());
post.setPostDate(postService.findByPostId(post.getPostId()).get().getPostDate());
post.setPostUpdate(new Date());
}else{
post.setPostDate(new Date());
post.setPostUpdate(new Date());
}
postService.saveByPost(post); postService.saveByPost(post);
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST, post.getPostTitle(), HaloUtils.getIpAddr(request), new Date())); logsService.saveByLogs(new Logs(LogsRecord.PUSH_PAGE, post.getPostTitle(), HaloUtils.getIpAddr(request), new Date()));
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:{0}", e.getMessage());
} }

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.Logs; import cc.ryanc.halo.model.domain.Logs;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.dto.LogsRecord; import cc.ryanc.halo.model.dto.LogsRecord;
import cc.ryanc.halo.service.LogsService; import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.service.OptionsService; import cc.ryanc.halo.service.OptionsService;
@ -66,7 +67,7 @@ public class ThemeController extends BaseController {
*/ */
@GetMapping(value = "/set") @GetMapping(value = "/set")
@ResponseBody @ResponseBody
public boolean activeTheme(@PathParam("siteTheme") String siteTheme, public JsonResult activeTheme(@PathParam("siteTheme") String siteTheme,
HttpServletRequest request) { HttpServletRequest request) {
try { try {
//保存主题设置项 //保存主题设置项
@ -77,10 +78,10 @@ public class ThemeController extends BaseController {
logsService.saveByLogs( logsService.saveByLogs(
new Logs(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, HaloUtils.getIpAddr(request), new Date()) new Logs(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, HaloUtils.getIpAddr(request), new Date())
); );
return true; return new JsonResult(1,"主题已设置为"+siteTheme);
} catch (Exception e) { } catch (Exception e) {
log.error("主题设置失败,当前主题为:" + siteTheme); log.error("主题设置失败,当前主题为:" + siteTheme);
return false; return new JsonResult(0,"主题设置失败");
} }
} }
@ -93,7 +94,7 @@ public class ThemeController extends BaseController {
*/ */
@RequestMapping(value = "/upload", method = RequestMethod.POST) @RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public boolean uploadTheme(@RequestParam("file") MultipartFile file, public JsonResult uploadTheme(@RequestParam("file") MultipartFile file,
HttpServletRequest request) { HttpServletRequest request) {
try { try {
if (!file.isEmpty()) { if (!file.isEmpty()) {
@ -109,14 +110,15 @@ public class ThemeController extends BaseController {
HaloUtils.removeFile(themePath.getAbsolutePath()); HaloUtils.removeFile(themePath.getAbsolutePath());
HaloConst.THEMES.clear(); HaloConst.THEMES.clear();
HaloConst.THEMES = HaloUtils.getThemes(); HaloConst.THEMES = HaloUtils.getThemes();
return true;
} else { } else {
log.error("上传主题失败,没有选择文件"); log.error("上传主题失败,没有选择文件");
return new JsonResult(0,"请选择上传的主题!");
} }
} catch (Exception e) { } catch (Exception e) {
log.error("上传主题失败:{0}", e.getMessage()); log.error("上传主题失败:{0}", e.getMessage());
return new JsonResult(0,"主题上传失败!");
} }
return false; return new JsonResult(1,"主题上传成功!");
} }
/** /**
@ -194,10 +196,10 @@ public class ThemeController extends BaseController {
*/ */
@PostMapping(value = "/editor/save") @PostMapping(value = "/editor/save")
@ResponseBody @ResponseBody
public boolean saveTpl(@RequestParam("tplName") String tplName, public JsonResult saveTpl(@RequestParam("tplName") String tplName,
@RequestParam("tplContent") String tplContent) { @RequestParam("tplContent") String tplContent) {
if (StringUtils.isBlank(tplContent)) { if (StringUtils.isBlank(tplContent)) {
return false; return new JsonResult(0,"模板不能为空!");
} }
try { try {
//获取项目根路径 //获取项目根路径
@ -207,9 +209,9 @@ public class ThemeController extends BaseController {
byte[] tplContentByte = tplContent.getBytes("UTF-8"); byte[] tplContentByte = tplContent.getBytes("UTF-8");
Files.write(Paths.get(tplPath.getAbsolutePath()), tplContentByte); Files.write(Paths.get(tplPath.getAbsolutePath()), tplContentByte);
} catch (Exception e) { } catch (Exception e) {
log.error("文件保存失败:{0}", e.getMessage()); log.error("模板保存失败:{0}", e.getMessage());
return false; return new JsonResult(0,"模板保存失败!");
} }
return true; return new JsonResult(1,"模板保存成功!");
} }
} }

View File

@ -1,6 +1,7 @@
package cc.ryanc.halo.web.controller.admin; package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.User; import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.service.UserService; import cc.ryanc.halo.service.UserService;
import cc.ryanc.halo.utils.HaloUtils; import cc.ryanc.halo.utils.HaloUtils;
import freemarker.template.Configuration; import freemarker.template.Configuration;
@ -47,20 +48,20 @@ public class UserController {
*/ */
@PostMapping(value = "save") @PostMapping(value = "save")
@ResponseBody @ResponseBody
public boolean saveProfile(@ModelAttribute User user, HttpSession session) { public JsonResult saveProfile(@ModelAttribute User user, HttpSession session) {
try { try {
if (null != user) { if (null != user) {
userService.saveByUser(user); userService.saveByUser(user);
configuration.setSharedVariable("user", userService.findUser()); configuration.setSharedVariable("user", userService.findUser());
session.invalidate(); session.invalidate();
} else { } else {
return false; return new JsonResult(0,"修改失败!");
} }
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:{0}", e.getMessage());
return false; return new JsonResult(0,"修改失败!");
} }
return true; return new JsonResult(1,"修改成功!");
} }
/** /**
@ -74,7 +75,7 @@ public class UserController {
*/ */
@PostMapping(value = "changePass") @PostMapping(value = "changePass")
@ResponseBody @ResponseBody
public boolean changePass(@ModelAttribute("beforePass") String beforePass, public JsonResult changePass(@ModelAttribute("beforePass") String beforePass,
@ModelAttribute("newPass") String newPass, @ModelAttribute("newPass") String newPass,
@ModelAttribute("userId") Long userId, @ModelAttribute("userId") Long userId,
HttpSession session) { HttpSession session) {
@ -85,12 +86,12 @@ public class UserController {
userService.saveByUser(user); userService.saveByUser(user);
session.invalidate(); session.invalidate();
} else { } else {
return false; return new JsonResult(0,"原密码错误!");
} }
} catch (Exception e) { } catch (Exception e) {
log.error("修改密码:未知错误,{0}", e.getMessage()); log.error("修改密码:未知错误,{0}", e.getMessage());
return false; return new JsonResult(0,"密码修改失败!");
} }
return true; return new JsonResult(1,"修改密码成功!");
} }
} }

View File

@ -3,6 +3,7 @@ package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Comment; import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.MailService; import cc.ryanc.halo.service.MailService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
@ -90,9 +91,10 @@ public class FrontCommentController {
*/ */
@PostMapping(value = "/newComment") @PostMapping(value = "/newComment")
@ResponseBody @ResponseBody
public boolean newComment(@ModelAttribute("comment") Comment comment, public JsonResult newComment(@ModelAttribute("comment") Comment comment,
@ModelAttribute("post") Post post, @ModelAttribute("post") Post post,
HttpServletRequest request) { HttpServletRequest request) {
try{
Comment lastComment = null; Comment lastComment = null;
post = postService.findByPostId(post.getPostId()).get(); post = postService.findByPostId(post.getPostId()).get();
comment.setCommentAuthorEmail(comment.getCommentAuthorEmail().toLowerCase()); comment.setCommentAuthorEmail(comment.getCommentAuthorEmail().toLowerCase());
@ -116,7 +118,10 @@ public class FrontCommentController {
}else{ }else{
new EmailToAdmin(comment,post).start(); new EmailToAdmin(comment,post).start();
} }
return true; return new JsonResult(1,"你的评论已经提交,待博主审核之后可显示。");
}catch (Exception e){
return new JsonResult(0,"评论失败!");
}
} }
/** /**

View File

@ -44,8 +44,12 @@ function saveOptions(option) {
type: 'post', type: 'post',
url: '/admin/option/save', url: '/admin/option/save',
data: param, data: param,
success: function (result) { success: function (data) {
showMsg("保存成功!","success",1000); if(data.code==1){
showMsg(data.msg,"success",1000);
}else {
showMsg(data.msg,"error",1000);
}
} }
}); });
} }

View File

@ -232,7 +232,11 @@
}, },
success: function (data) { success: function (data) {
$.toast({ $.toast({
text: "发布成功!", <#if post??>
text: "更新成功!",
<#else>
text: "发表成功!",
</#if>
heading: '提示', heading: '提示',
icon: 'success', icon: 'success',
showHideTransition: 'fade', showHideTransition: 'fade',

View File

@ -324,7 +324,11 @@
}, },
success: function (data) { success: function (data) {
$.toast({ $.toast({
text: "发布成功!", <#if post??>
text: "更新成功!",
<#else>
text: "发表成功!",
</#if>
heading: '提示', heading: '提示',
icon: 'success', icon: 'success',
showHideTransition: 'fade', showHideTransition: 'fade',

View File

@ -155,10 +155,10 @@
type: 'post', type: 'post',
url: '/admin/profile/save', url: '/admin/profile/save',
data: param, data: param,
success: function (result) { success: function (data) {
if(result==true){ if(data.code==1){
$.toast({ $.toast({
text: "保存成功!", text: data.msg,
heading: '提示', heading: '提示',
icon: 'success', icon: 'success',
showHideTransition: 'fade', showHideTransition: 'fade',
@ -174,7 +174,7 @@
} }
}); });
}else{ }else{
showMsg("保存失败!","error",2000); showMsg(data.msg,"error",2000);
} }
} }
}); });
@ -196,10 +196,10 @@
type: 'post', type: 'post',
url: '/admin/profile/changePass', url: '/admin/profile/changePass',
data: param, data: param,
success: function (result) { success: function (data) {
if(result==true){ if(data.code==1){
$.toast({ $.toast({
text: "修改密码成功!", text: data.msg,
heading: '提示', heading: '提示',
icon: 'success', icon: 'success',
showHideTransition: 'fade', showHideTransition: 'fade',
@ -215,7 +215,7 @@
} }
}); });
}else{ }else{
showMsg("原密码错误!","error",2000); showMsg(data.msg,"error",2000);
} }
} }
}); });

View File

@ -127,9 +127,9 @@
'tplContent': editor.getValue() 'tplContent': editor.getValue()
}, },
success: function (data) { success: function (data) {
if(data==true){ if(data.code==1){
$.toast({ $.toast({
text: "保存成功!", text: data.msg,
heading: '提示', heading: '提示',
icon: 'success', icon: 'success',
showHideTransition: 'fade', showHideTransition: 'fade',
@ -143,7 +143,7 @@
}); });
}else{ }else{
$.toast({ $.toast({
text: "保存失败!", text: data.msg,
heading: '提示', heading: '提示',
icon: 'error', icon: 'error',
showHideTransition: 'fade', showHideTransition: 'fade',

View File

@ -146,11 +146,10 @@
dropZoneTitle: '拖拽主题压缩包到这里 &hellip;<br>不支持多个主题同时上传', dropZoneTitle: '拖拽主题压缩包到这里 &hellip;<br>不支持多个主题同时上传',
showClose: false showClose: false
}).on("fileuploaded",function (event,data,previewId,index) { }).on("fileuploaded",function (event,data,previewId,index) {
var data = data.jqXHR.responseJSON; if(data.code==1){
if(data==true){
$("#uploadForm").hide(400); $("#uploadForm").hide(400);
$.toast({ $.toast({
text: "上传成功!", text: data.msg,
heading: '提示', heading: '提示',
icon: 'success', icon: 'success',
showHideTransition: 'fade', showHideTransition: 'fade',
@ -165,6 +164,20 @@
window.location.reload(); window.location.reload();
} }
}); });
}else{
$.toast({
text: data.msg,
heading: '提示',
icon: 'error',
showHideTransition: 'fade',
allowToastClose: true,
hideAfter: 1000,
stack: 1,
position: 'top-center',
textAlign: 'left',
loader: true,
loaderBg: '#ffffff'
});
} }
}); });
}); });
@ -189,11 +202,11 @@
'siteTheme': site_theme 'siteTheme': site_theme
}, },
success: function (data) { success: function (data) {
if(data==true){ if(data.code==1){
$.toast({ $.toast({
text: "设置中...", text: data.msg,
heading: '提示', heading: '提示',
icon: 'info', icon: 'success',
showHideTransition: 'fade', showHideTransition: 'fade',
allowToastClose: true, allowToastClose: true,
hideAfter: 1000, hideAfter: 1000,
@ -206,6 +219,20 @@
window.location.reload(); window.location.reload();
} }
}); });
}else{
$.toast({
text: data.msg,
heading: '提示',
icon: 'error',
showHideTransition: 'fade',
allowToastClose: true,
hideAfter: 2000,
stack: 1,
position: 'top-center',
textAlign: 'left',
loader: true,
loaderBg: '#ffffff'
});
} }
} }
}); });

View File

@ -94,9 +94,9 @@
attachId : ${attachment.attachId?c} attachId : ${attachment.attachId?c}
}, },
success: function (data) { success: function (data) {
if(data==true){ if(data.code==1){
$.toast({ $.toast({
text: "删除成功!", text: data.msg,
heading: '提示', heading: '提示',
icon: 'success', icon: 'success',
showHideTransition: 'fade', showHideTransition: 'fade',
@ -112,7 +112,7 @@
} }
}); });
}else{ }else{
showMsg("删除失败","error",2000); showMsg(data.msg,"error",2000);
} }
} }
}); });

View File

@ -284,14 +284,15 @@
'commentParent': $('input[name=commentParent]').val() 'commentParent': $('input[name=commentParent]').val()
}, },
success: function (data) { success: function (data) {
if (data == true) { if(data.code==1){
$(".native-message").html("<span>你的评论已经提交,待博主审核之后可显示。</span>"); $('.comment-input-content').val("");
}
$(".native-message").html("<span>"+data.msg+"</span>");
$(".native-message").fadeIn(1000); $(".native-message").fadeIn(1000);
setTimeout(function () { setTimeout(function () {
window.location.reload(); window.location.reload();
},1500); },1500);
} }
}
}); });
}); });
$('.native-list-one-footer-reback').click(function () { $('.native-list-one-footer-reback').click(function () {

View File

@ -214,7 +214,11 @@
url: '/admin/option/save', url: '/admin/option/save',
data: param, data: param,
success: function (data) { success: function (data) {
showMsg("保存成功!","success",1000); if(data.code==1){
showMsg(data.msg,"success",1000);
}else{
showMsg(data.msg,"error",1000);
}
} }
}); });
} }

View File

@ -543,7 +543,11 @@
url: '/admin/option/save', url: '/admin/option/save',
data: param, data: param,
success: function (data) { success: function (data) {
showMsg("保存成功!","success",1000); if(data.code==1){
showMsg(data.msg,"success",1000);
}else{
showMsg(data.msg,"error",1000);
}
} }
}); });
} }