From 067b18227644def0f23b76d6de538880d4c4b051 Mon Sep 17 00:00:00 2001 From: Hellohao <923453645@qq.com> Date: Wed, 12 Jun 2019 21:48:51 +0800 Subject: [PATCH] =?UTF-8?q?Hellohao=E5=9B=BE=E5=BA=8A6-12=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../hellohao/controller/AdminController.java | 135 ++++++++-------- .../controller/UpdateImgController.java | 50 ++---- .../hellohao/controller/UserController.java | 9 +- src/main/java/cn/hellohao/pojo/Config.java | 12 +- .../java/cn/hellohao/utils/ImageReview.java | 12 -- .../hellohao/{ => utils}/JianHuangThread.java | 5 +- .../java/cn/hellohao/utils/SendEmail.java | 21 +-- src/main/resources/application.properties | 13 +- src/main/resources/mapper/ConfigMapper.xml | 6 +- src/main/resources/templates/admin/index.html | 50 +----- .../resources/templates/admin/webconfig.html | 16 +- src/main/resources/templates/footer.html | 1 + src/main/resources/templates/header.html | 5 +- src/main/resources/templates/index.html | 148 ++++++++---------- 15 files changed, 208 insertions(+), 277 deletions(-) rename src/main/java/cn/hellohao/{ => utils}/JianHuangThread.java (91%) diff --git a/pom.xml b/pom.xml index 056e65e..a674e9f 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ Tbed 0.0.1-SNAPSHOT Tbed - Demo project for Spring Boot + Hellohao Picture Bed for Spring Boot 1.8 diff --git a/src/main/java/cn/hellohao/controller/AdminController.java b/src/main/java/cn/hellohao/controller/AdminController.java index 286e60c..421d9d6 100644 --- a/src/main/java/cn/hellohao/controller/AdminController.java +++ b/src/main/java/cn/hellohao/controller/AdminController.java @@ -77,20 +77,9 @@ public class AdminController { model.addAttribute("level", u.getLevel()); model.addAttribute("email", u.getEmail()); model.addAttribute("loginid", 100); - model.addAttribute("source", key.getStorageType()); - - //key信息 -// model.addAttribute("AccessKey", key.getAccessKey()); -// model.addAttribute("AccessSecret", key.getAccessSecret()); -// model.addAttribute("Endpoint", key.getEndpoint()); -// model.addAttribute("Bucketname", key.getBucketname()); -// model.addAttribute("RequestAddress", key.getRequestAddress()); -// model.addAttribute("StorageType", storageType); -// if (u.getLevel() > 1) { -//// model.addAttribute("htgl", -//// "系统配置"); -//// -//// } + if(key!=null){ + model.addAttribute("source", key.getStorageType()); + } return "admin/table"; } @@ -171,13 +160,15 @@ public class AdminController { public String tostorage(HttpSession session, Model model, HttpServletRequest request) { Config config = configService.getSourceype();//查询当前系统使用的存储源类型。 Keys key = keysService.selectKeys(config.getSourcekey()); - //key信息 - model.addAttribute("AccessKey", key.getAccessKey()); - model.addAttribute("AccessSecret", key.getAccessSecret()); - model.addAttribute("Endpoint", key.getEndpoint()); - model.addAttribute("Bucketname", key.getBucketname()); - model.addAttribute("RequestAddress", key.getRequestAddress()); - model.addAttribute("StorageType", config.getSourcekey()); + if(key!=null){ + //key信息 + model.addAttribute("AccessKey", key.getAccessKey()); + model.addAttribute("AccessSecret", key.getAccessSecret()); + model.addAttribute("Endpoint", key.getEndpoint()); + model.addAttribute("Bucketname", key.getBucketname()); + model.addAttribute("RequestAddress", key.getRequestAddress()); + model.addAttribute("StorageType", config.getSourcekey()); + } return "admin/storageconfig"; } @@ -214,43 +205,9 @@ public class AdminController { User u = (User) session.getAttribute("user"); Images images = imgService.selectByPrimaryKey(id); Keys key = keysService.selectKeys(sourcekey); - ImgServiceImpl de = new ImgServiceImpl(); + if(key!=null){ + ImgServiceImpl de = new ImgServiceImpl(); - if (key.getStorageType() == 1) { - de.delect(key, images.getImgname()); - } else if (key.getStorageType() == 2) { - de.delectOSS(key, images.getImgname()); - } else if (key.getStorageType() == 3) { - //初始化腾讯云 - } else if (key.getStorageType() == 4) { - //初始化七牛云 - } else { - System.err.println("未获取到对象存储参数,删除失败。"); - } - Integer ret = imgService.deleimg(id); - Integer count = 0; - if (ret > 0) { - jsonObject.put("usercount", imgService.countimg(u.getId())); - jsonObject.put("count", imgService.counts(null) + 1000); - count = 1; - } else { - count = 0; - } - jsonObject.put("val", count); - return jsonObject.toString(); - } - - //批量删除图片 - @PostMapping("/deleallimg") - @ResponseBody - public String deleallimg(HttpSession session, @RequestParam("ids[]") Integer[] ids) { - JSONObject jsonObject = new JSONObject(); - Integer v = 0; - ImgServiceImpl de = new ImgServiceImpl(); - User u = (User) session.getAttribute("user"); - for (int i = 0; i < ids.length; i++) { - Images images = imgService.selectByPrimaryKey(ids[i]); - Keys key = keysService.selectKeys(images.getSource()); if (key.getStorageType() == 1) { de.delect(key, images.getImgname()); } else if (key.getStorageType() == 2) { @@ -262,16 +219,61 @@ public class AdminController { } else { System.err.println("未获取到对象存储参数,删除失败。"); } - Integer ret = imgService.deleimg(ids[i]); - if (ret < 1) { - v = 0; + Integer ret = imgService.deleimg(id); + Integer count = 0; + if (ret > 0) { + jsonObject.put("usercount", imgService.countimg(u.getId())); + jsonObject.put("count", imgService.counts(null) + 1000); + count = 1; } else { - v = 1; + count = 0; + } + jsonObject.put("val", count); + }else{ + jsonObject.put("val", 0); + } + + return jsonObject.toString(); + } + + //批量删除图片 + @PostMapping("/deleallimg") + @ResponseBody + public String deleallimg(HttpSession session, @RequestParam("ids[]") Integer[] ids) { + JSONObject jsonObject = new JSONObject(); + Integer v = 0; + ImgServiceImpl de = new ImgServiceImpl(); + User u = (User) session.getAttribute("user"); + + for (int i = 0; i < ids.length; i++) { + Images images = imgService.selectByPrimaryKey(ids[i]); + Keys key = keysService.selectKeys(images.getSource()); + if(key!=null){ + if (key.getStorageType() == 1) { + de.delect(key, images.getImgname()); + } else if (key.getStorageType() == 2) { + de.delectOSS(key, images.getImgname()); + } else if (key.getStorageType() == 3) { + //初始化腾讯云 + } else if (key.getStorageType() == 4) { + //初始化七牛云 + } else { + System.err.println("未获取到对象存储参数,删除失败。"); + } + Integer ret = imgService.deleimg(ids[i]); + if (ret < 1) { + v = 0; + } else { + v = 1; + } + }else { + v = 0; } } + jsonObject.put("val", v); jsonObject.put("usercount", imgService.countimg(u.getId())); jsonObject.put("count", imgService.counts(null) + 1000); - jsonObject.put("val", v); + return jsonObject.toString(); } @@ -303,7 +305,6 @@ public class AdminController { User u = (User) session.getAttribute("user"); user.setEmail(u.getEmail()); JSONArray jsonArray = new JSONArray(); - //if(count==0) { Integer ret = userService.change(user); jsonArray.add(ret); if (u.getEmail() != null && u.getPassword() != null) { @@ -311,9 +312,6 @@ public class AdminController { //刷新view session.invalidate(); } - //}else { - // jsonArray.add("-1"); - //} // -1 用户名重复 return jsonArray.toString(); } @@ -350,8 +348,8 @@ public class AdminController { @PostMapping("/root/updateconfig") @ResponseBody public Integer updateconfig(HttpSession session, String webname,String explain, String logos, - String footed, String links, String notice,String baidu ) { - System.err.println(links); + String footed, String links, String notice,String baidu,String domain ) { + System.err.println("域名=="+domain); Config config = new Config(); config.setWebname(webname); config.setExplain(explain); @@ -360,6 +358,7 @@ public class AdminController { config.setLinks(links); config.setNotice(notice); config.setBaidu(baidu); + config.setDomain(domain); Integer ret = configService.setSourceype(config); return ret; } diff --git a/src/main/java/cn/hellohao/controller/UpdateImgController.java b/src/main/java/cn/hellohao/controller/UpdateImgController.java index 6870bb4..7ca67c8 100644 --- a/src/main/java/cn/hellohao/controller/UpdateImgController.java +++ b/src/main/java/cn/hellohao/controller/UpdateImgController.java @@ -41,18 +41,23 @@ public class UpdateImgController { public String indexImg(Model model, HttpServletRequest request, HttpSession httpSession) throws Exception { Config config = configService.getSourceype();//查询当前系统使用的存储源类型。 Keys key = keysService.selectKeys(config.getSourcekey());//然后根据类型再查询key - if(key.getStorageType()==1){ - nOSImageupload.Initialize(key);//实例化网易 - System.out.println("NOS初始化成功。"); - }else if (key.getStorageType()==2){ - OSSImageupload.Initialize(key); - System.out.println("OSS初始化成功。"); - }else if(key.getStorageType()==3){ - //初始化腾讯云 - }else if(key.getStorageType()==4){ - //初始化七牛云 - }else{ - System.err.println("未获取到对象存储参数,初始化失败。"); + if(key!=null) + { + if(key.getStorageType()!=0 || key.getStorageType()!=null){ + if(key.getStorageType()==1){ + nOSImageupload.Initialize(key);//实例化网易 + System.out.println("NOS初始化成功。"); + }else if (key.getStorageType()==2){ + OSSImageupload.Initialize(key); + System.out.println("OSS初始化成功。"); + }else if(key.getStorageType()==3){ + //初始化腾讯云 + }else if(key.getStorageType()==4){ + //初始化七牛云 + }else{ + System.err.println("未获取到对象存储参数,初始化失败。"); + } + } } User u = (User) httpSession.getAttribute("user"); @@ -79,27 +84,6 @@ public class UpdateImgController { } model.addAttribute("config", config); - -// AipContentCensor client = ImageReview.Initialize(); -// String url = "https://hellohao.nos-eastchina1.126.net/Hellohao/huangse.png"; -// JSONObject res = client.antiPorn(url); -// res = client.imageCensorUserDefined(url, EImgType.URL, null); -// System.out.println(res.toString()); - -// -// CronTrigger cron = (CronTrigger) scheduler.getTrigger(cronTrigger.getKey()); -// String currentCron = cron.getCronExpression();// 当前Trigger使用的 -// System.err.println("当前trigger使用的-"+currentCron); -// -// //修改每隔?秒执行任务 -// CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 09 07 * * ?"); -// -// // 按新的cronExpression表达式重新构建trigger -// cron = cron.getTriggerBuilder().withIdentity(cronTrigger.getKey()) -// .withSchedule(scheduleBuilder).build(); -// -// scheduler.rescheduleJob(cronTrigger.getKey(),cron); - return "index"; } diff --git a/src/main/java/cn/hellohao/controller/UserController.java b/src/main/java/cn/hellohao/controller/UserController.java index d731d01..6041454 100644 --- a/src/main/java/cn/hellohao/controller/UserController.java +++ b/src/main/java/cn/hellohao/controller/UserController.java @@ -8,7 +8,9 @@ import javax.mail.internet.MimeMessage; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import cn.hellohao.pojo.Config; import cn.hellohao.pojo.EmailConfig; +import cn.hellohao.service.ConfigService; import cn.hellohao.service.EmailConfigService; import cn.hellohao.utils.SendEmail; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +34,8 @@ public class UserController { private UserService userService; @Autowired private EmailConfigService emailConfigService; - + @Autowired + private ConfigService configService; @RequestMapping("/register") @ResponseBody @@ -51,6 +54,7 @@ public class UserController { user.setBirthder(birthder); //查询是否启用了邮箱验证。 EmailConfig emailConfig1 = emailConfigService.getemail(); + Config config = configService.getSourceype(); Integer type = 0; if(emailConfig1.getUsing()==1){ user.setIsok(0); @@ -59,7 +63,7 @@ public class UserController { //注册完发激活链接 Thread thread = new Thread() { public void run() { - Integer a = SendEmail.sendEmail(message, user.getUsername(), uid, user.getEmail(),emailConfig); + Integer a = SendEmail.sendEmail(message, user.getUsername(), uid, user.getEmail(),emailConfig,config); } }; thread.start(); @@ -93,7 +97,6 @@ public class UserController { } else { jsonArray.add(-1); } - //登录成功之后把账号密码存入session } else { jsonArray.add(0); } diff --git a/src/main/java/cn/hellohao/pojo/Config.java b/src/main/java/cn/hellohao/pojo/Config.java index 0f9bd4a..be16aaf 100644 --- a/src/main/java/cn/hellohao/pojo/Config.java +++ b/src/main/java/cn/hellohao/pojo/Config.java @@ -11,11 +11,12 @@ public class Config { private String links; private String notice; private String baidu; + private String domain; public Config() { } - public Config(Integer id, Integer sourcekey, Integer emails, String webname, String explain, String logos, String footed, String links, String notice, String baidu) { + public Config(Integer id, Integer sourcekey, Integer emails, String webname, String explain, String logos, String footed, String links, String notice, String baidu, String domain) { this.id = id; this.sourcekey = sourcekey; this.emails = emails; @@ -26,6 +27,7 @@ public class Config { this.links = links; this.notice = notice; this.baidu = baidu; + this.domain = domain; } public Integer getId() { @@ -107,4 +109,12 @@ public class Config { public void setBaidu(String baidu) { this.baidu = baidu; } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } } diff --git a/src/main/java/cn/hellohao/utils/ImageReview.java b/src/main/java/cn/hellohao/utils/ImageReview.java index 3c814bf..65f8308 100644 --- a/src/main/java/cn/hellohao/utils/ImageReview.java +++ b/src/main/java/cn/hellohao/utils/ImageReview.java @@ -16,16 +16,10 @@ import java.util.Map; @Component public class ImageReview { - //设置APPID/AK/SK -// private static final String APP_ID = "15434135"; -// private static final String API_KEY = "yDdHaeMf0FfFAxupXFkoxoPG"; -// private static final String SECRET_KEY = "QGRXTy8QNDMr0dWuWS6bj7rNcwtEddKe"; private static AipContentCensor client; private ImageReview() { } - - private static void Initializes(Imgreview imgreview) { client = new AipContentCensor(imgreview.getAppId(), imgreview.getApiKey(), imgreview.getSecretKey()); client.setConnectionTimeoutInMillis(2000); @@ -74,21 +68,15 @@ public class ImageReview { }else{ System.err.println("未获取到对象存储参数,上传失败。"); } - if (ret == 1) { System.out.println("存在色情图片,删除成功。"); } else { System.out.println("存在色情图片,删除失败"); } } - } } - } - - - } } diff --git a/src/main/java/cn/hellohao/JianHuangThread.java b/src/main/java/cn/hellohao/utils/JianHuangThread.java similarity index 91% rename from src/main/java/cn/hellohao/JianHuangThread.java rename to src/main/java/cn/hellohao/utils/JianHuangThread.java index 9f32b4d..ab63fa7 100644 --- a/src/main/java/cn/hellohao/JianHuangThread.java +++ b/src/main/java/cn/hellohao/utils/JianHuangThread.java @@ -1,12 +1,9 @@ -package cn.hellohao; +package cn.hellohao.utils; import cn.hellohao.pojo.Imgreview; import cn.hellohao.pojo.Keys; import cn.hellohao.pojo.User; import cn.hellohao.service.ImgreviewService; -import cn.hellohao.utils.ImageReview; - -import java.util.HashMap; import java.util.Map; public class JianHuangThread extends Thread { diff --git a/src/main/java/cn/hellohao/utils/SendEmail.java b/src/main/java/cn/hellohao/utils/SendEmail.java index e6a5b5f..f0775cb 100644 --- a/src/main/java/cn/hellohao/utils/SendEmail.java +++ b/src/main/java/cn/hellohao/utils/SendEmail.java @@ -1,12 +1,8 @@ package cn.hellohao.utils; +import cn.hellohao.pojo.Config; import cn.hellohao.pojo.EmailConfig; -import cn.hellohao.service.EmailConfigService; -import cn.hellohao.test.asdf; -import org.springframework.beans.factory.annotation.Autowired; - import javax.mail.*; -import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.io.UnsupportedEncodingException; @@ -14,13 +10,6 @@ import java.util.Date; import java.util.Properties; public class SendEmail { - // 发件人 账号和密码 -// private static String MY_EMAIL_NAME = "Hellohao图床"; -// private static String MY_EMAIL_ACCOUNT = "helloshihao@163.com"; -// private static String MY_EMAIL_PASSWORD = "hellohao950504";// 密码,是你自己的设置的授权码 -// // SMTP服务器(这里用的163 SMTP服务器) -// public static String MEAIL_163_SMTP_HOST = "smtp.163.com"; -// public static String SMTP_163_PORT = "25";// 端口号,这个是163使用到的;QQ的应该是465或者875 public static MimeMessage Emails(EmailConfig emailConfig) { Properties p = new Properties(); @@ -43,7 +32,9 @@ public class SendEmail { return message; } - public static Integer sendEmail(MimeMessage message, String username, String Url, String email,EmailConfig emailConfig) { + public static Integer sendEmail(MimeMessage message, String username, String Url, String email, EmailConfig emailConfig, Config config) { + String webname=config.getWebname(); + String domain = config.getDomain(); String body = "\n" + "\n" + " \n" + @@ -64,8 +55,8 @@ public class SendEmail { " \n" + " \n" + "
\n" + - "
您正在注册Hellohao图床
\n" + - "

点击  激活链接  进行账号激活

\n" + + "
您正在注册"+webname+"
\n" + + "

点击  激活链接  进行账号激活

\n" + "
\n" + " \n" + " \n" + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0c1494f..52e4604 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,12 +5,13 @@ mybatis.mapper-locations=classpath:mapper/*.xml logging.level.cn.hellohao.dao=debug spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.time-zone=GMT+8 -spring.datasource.username=picturebed -spring.datasource.password=hellohao -#spring.datasource.username=root -#spring.datasource.password=root -#spring.datasource.url=jdbc:mysql://localhost:3306/picturebed?useUnicode=true&characterEncoding=utf8 -spring.datasource.url=jdbc:mysql://hellohao.cn:3306/picturebed?useUnicode=true&characterEncoding=utf8 +spring.datasource.username=root +spring.datasource.password=root +spring.datasource.url=jdbc:mysql://localhost:3306/picturebed?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8 + +#spring.datasource.username=picturebed +#spring.datasource.password=hellohao +#spring.datasource.url=jdbc:mysql://hellohao.cn:3306/picturebed?useUnicode=true&characterEncoding=utf8 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.thymeleaf.cache=false diff --git a/src/main/resources/mapper/ConfigMapper.xml b/src/main/resources/mapper/ConfigMapper.xml index 5a43b0f..87c3301 100644 --- a/src/main/resources/mapper/ConfigMapper.xml +++ b/src/main/resources/mapper/ConfigMapper.xml @@ -34,8 +34,12 @@ `notice` = #{notice}, - `baidu` = #{baidu} + `baidu` = #{baidu}, + + `domain` = #{domain} + + where id=1 diff --git a/src/main/resources/templates/admin/index.html b/src/main/resources/templates/admin/index.html index 0b3ad34..756d725 100644 --- a/src/main/resources/templates/admin/index.html +++ b/src/main/resources/templates/admin/index.html @@ -5,26 +5,20 @@ - 后台管理 - Hellohao图床 - + 图床后台管理 - - -
-
- -
  • -
  • 头像 -
    - - - - - - -
    退出
    @@ -92,13 +76,6 @@
    - - - - - - -
  • @@ -144,14 +121,6 @@
  • - - - - - - - -
@@ -198,19 +167,6 @@ , layer = layui.layer }); - // $(function () { - // //parent.location.reload();//刷新父元素 - // now = new Date(),hour = now.getHours() - // if(hour < 6){document.write("凌晨好!")} - // else if (hour < 9){$("#istime").text("早上好!")} - // else if (hour < 12){$("#istime").text("上午好!")} - // else if (hour < 14){$("#istime").text("中午好!")} - // else if (hour < 17){$("#istime").text("下午好!")} - // else if (hour < 19){$("#istime").text("傍晚好!")} - // else if (hour < 22){$("#istime").text("晚上好!")} - // else {$("#istime").text("夜里好!")} - // }); - function exit() { $.ajax({ @@ -219,8 +175,6 @@ dataType: "json", success: function (data) { layer.msg('账号已退出'); - //toastr.success("账号已退出。"); - //window.location.reload();//刷新当前页面 parent.location.reload();//刷新父元素 } diff --git a/src/main/resources/templates/admin/webconfig.html b/src/main/resources/templates/admin/webconfig.html index f7e2a14..92bcf02 100644 --- a/src/main/resources/templates/admin/webconfig.html +++ b/src/main/resources/templates/admin/webconfig.html @@ -45,6 +45,14 @@
+
+ +
+ 填写访问本站的域名或IP,否则开启邮箱激活不能正常使用。 +
+
+
@@ -116,19 +124,19 @@ }); function updateconfig() { - //修改百度图片鉴别 var webname = $("#webname").val(); var explain = $("#explain").val(); var logos = $("#logos").val(); var footed = $("#footed").val(); var links = $("#links").val(); var notice = $("#notice").val(); - if (webname != "") { + var domain = $("#domain").val(); + if (webname != "" && domain!="" ) { $.ajax({ type: "POST", url: "/admin/root/updateconfig", dataType: "json", - data: {webname: webname, explain: explain, logos: logos,footed:footed,links:links,notice:notice}, + data: {webname: webname, explain: explain, logos: logos,footed:footed,links:links,notice:notice,domain:domain}, success: function (data) { var vals = Number(data); if (vals > 0) { @@ -140,7 +148,7 @@ } }); } else { - layer.msg("网站名称内容均不能为空", {icon: 2}); + layer.msg("网站名称或站点域名均不能为空", {icon: 2}); } } function updatebaidu() { diff --git a/src/main/resources/templates/footer.html b/src/main/resources/templates/footer.html index 77b4f42..b73bd4b 100644 --- a/src/main/resources/templates/footer.html +++ b/src/main/resources/templates/footer.html @@ -49,6 +49,7 @@