重构版功能实现

This commit is contained in:
tiansh
2021-10-28 18:54:05 +08:00
parent 3a03c965e1
commit 551bb6c20a
64 changed files with 881 additions and 6794 deletions
@@ -4,8 +4,7 @@ import cn.hellohao.config.SysName;
import cn.hellohao.pojo.*;
import cn.hellohao.pojo.vo.PageResultBean;
import cn.hellohao.service.*;
import cn.hellohao.service.impl.AlbumServiceImpl;
import cn.hellohao.service.impl.UserServiceImpl;
import cn.hellohao.service.impl.*;
import cn.hellohao.utils.*;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -43,7 +42,7 @@ public class AdminController {
@Autowired
private ImgreviewService imgreviewService;
@Autowired
private ConfigService configService;
private ImgTempService imgTempService;
@Autowired
private UploadConfigService uploadConfigService;
@Autowired
@@ -55,6 +54,22 @@ public class AdminController {
@Autowired
AlbumServiceImpl albumServiceI;
@Autowired
private NOSImageupload nosImageupload;
@Autowired
private OSSImageupload ossImageupload;
@Autowired
private COSImageupload cosImageupload;
@Autowired
private KODOImageupload kodoImageupload;
@Autowired
private USSImageupload ussImageupload;
@Autowired
private UFileImageupload uFileImageupload;
@Autowired
private FTPImageupload ftpImageupload;
@PostMapping(value = "/overviewData") //new
@ResponseBody
public Msg overviewData(@RequestParam(value = "data", defaultValue = "") String data) {
@@ -122,7 +137,7 @@ public class AdminController {
}
@PostMapping(value = "/SpaceExpansion")//new kuorong
@PostMapping(value = "/SpaceExpansion")//new
@ResponseBody
public Msg SpaceExpansion(@RequestParam(value = "data", defaultValue = "") String data) {
final Msg msg = new Msg();
@@ -159,67 +174,6 @@ public class AdminController {
}
@RequestMapping(value = "/tosurvey")
public String admin2(HttpSession session, Model model) {
User u = (User) session.getAttribute("user");
String sysetmname = System.getProperty("os.name");
String isarch = System.getProperty("os.arch");
String jdk = System.getProperty("java.version");
model.addAttribute("username", u.getUsername());
model.addAttribute("levels", u.getLevel());
model.addAttribute("sysetmname",sysetmname);
model.addAttribute("isarch", isarch);
model.addAttribute("jdk", jdk);
//空间大小
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
Long usermemory = imgService.getusermemory(u.getId());
if(usermemory==null){usermemory=0L;}
User user = userService.getUsers(u);
if(u!=null){
if (u.getLevel() == 1) {
model.addAttribute("level", "普通用户");
} else if (u.getLevel() == 2) {
model.addAttribute("level", "管理员");
} else {
model.addAttribute("level", "未 知");
}
model.addAttribute("levels", u.getLevel());
model.addAttribute("username", u.getUsername());
model.addAttribute("api", uploadConfig.getApi());
model.addAttribute("memory",user.getMemory());//单位M
if(usermemory==null){
model.addAttribute("usermemory", 0);//单位M
}else{
float d = (float) (Math.round((usermemory/1024.0F) * 100.0) / 100.0);
model.addAttribute("usermemory", d);//单位M
}
}
return "admin/survey";
}
@RequestMapping(value = "/getwebconfig")
@ResponseBody
public String getwebconfig(HttpSession session) {
JSONObject jsonObject = new JSONObject();
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
User u = (User) session.getAttribute("user");
Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
jsonObject.put("usercount", imgService.countimg(u.getId()));
jsonObject.put("counts", imgService.counts(null) );
jsonObject.put("getusertotal", userService.getUserTotal());
jsonObject.put("imgreviewcount", imgreview.getCount());
if(uploadConfig.getIsupdate()!=1){
jsonObject.put("VisitorUpload", 0);//是否禁用了游客上传
}else{
Long temp = imgService.getusermemory(0);
jsonObject.put("VisitorUpload", uploadConfig.getIsupdate());//是否禁用了游客上传
jsonObject.put("UsedSize", (temp == null ? 0 : temp/1024));//访客已用大小
jsonObject.put("VisitorMemory", uploadConfig.getVisitormemory());//访客共大小
}
return jsonObject.toString();
}
@PostMapping("/getRecently")//new 获取榜单和最近上传
@ResponseBody
public Msg getRecently(@RequestParam(value = "data", defaultValue = "") String data) {
@@ -303,7 +257,7 @@ public class AdminController {
return msg;
}
@PostMapping("/getStorage")//new 获取当前一共有多少种存储源 这是种类
@PostMapping("/getStorage")//new
@ResponseBody
public Msg getStorage() {
Msg msg = new Msg();
@@ -312,7 +266,7 @@ public class AdminController {
return msg;
}
@PostMapping("/getStorageName")//new 获取当前一共有多少个存储源 这是总个数
@PostMapping("/getStorageName")//new
@ResponseBody
public Msg getStorageName() {
Msg msg = new Msg();
@@ -358,7 +312,6 @@ public class AdminController {
}
Images img = new Images();
PageHelper.startPage(pageNum, pageSize);
// img.setUseridlist(user.getId().toString());
if(violation){
img.setViolation("true");
}
@@ -431,7 +384,6 @@ public class AdminController {
msg.setInfo("用户名不得超过20位字符");
return msg;
}
if(subject.hasRole("admin")){
final User userOld = new User();
userOld.setId(u.getId());
@@ -475,9 +427,87 @@ public class AdminController {
}
@PostMapping("/deleImages") //new
@ResponseBody
public Msg deleImages(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
JSONObject jsonObj = JSONObject.parseObject(data);
JSONArray images = jsonObj.getJSONArray("images");
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if(null == user){
msg.setCode("500");
msg.setInfo("当前用户信息不存在");
return msg;
}
if(images.size()==0){
msg.setCode("404");
msg.setInfo("为获取到图像信息");
return msg;
}
for (int i = 0; i < images.size(); i++) {
Integer imgid = images.getInteger(i);
Images image = imgService.selectByPrimaryKey(imgid);
Integer keyid = image.getSource();
String imgname = image.getImgname();
Keys key = keysService.selectKeys(keyid);
if(!subject.hasRole("admin")){
if(image.getUserid()!=user.getId()){
break;
}
}
//删除图片
boolean isDele = false;
try{
if (key.getStorageType() == 1) {
isDele = nosImageupload.delNOS(key.getId(), imgname);
} else if (key.getStorageType() == 2) {
isDele = ossImageupload.delOSS(key.getId(), imgname);
} else if (key.getStorageType() == 3) {
isDele = ussImageupload.delUSS(key.getId(), imgname);
} else if (key.getStorageType() == 4) {
isDele = kodoImageupload.delKODO(key.getId(), imgname);
} else if (key.getStorageType() == 5) {
isDele = LocUpdateImg.deleteLOCImg(imgname);
}else if (key.getStorageType() == 6) {
isDele = cosImageupload.delCOS(key.getId(), imgname);
}else if (key.getStorageType() == 7) {
isDele = ftpImageupload.delFTP(key.getId(), imgname);
}else if (key.getStorageType() == 8) {
isDele = uFileImageupload.delUFile(key.getId(), imgname);
}else {
System.err.println("未获取到对象存储参数,删除失败。");
}
}catch (Exception e){
e.printStackTrace();
}
//删除库
if(isDele){
try {
//删除图像表之前先删除临时数据表,图像表也会删除
imgTempService.delImgAndExp(image.getImguid());
imgService.deleimg(imgid);
imgAndAlbumService.deleteImgAndAlbum(imgname);
} catch (Exception e) {
e.printStackTrace();
msg.setInfo("图片记录删除失败,请重试");
msg.setCode("500");
return msg;
}
msg.setInfo("删除成功");
}else{
imgTempService.delImgAndExp(image.getImguid());
imgService.deleimg(imgid);
imgAndAlbumService.deleteImgAndAlbum(imgname);
msg.setInfo("图片记录已删除,但是图片源删除失败");
}
}
System.out.println("返回的值:"+msg.toString());
return msg;
}
//工具函数
@@ -3,10 +3,7 @@ package cn.hellohao.controller;
import cn.hellohao.pojo.*;
import cn.hellohao.service.*;
import cn.hellohao.service.impl.*;
import cn.hellohao.utils.GetCurrentSource;
import cn.hellohao.utils.Print;
import cn.hellohao.utils.SetFiles;
import cn.hellohao.utils.StringUtils;
import cn.hellohao.utils.*;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
@@ -53,10 +50,11 @@ public class AdminRootController {
private GroupService groupService;
@Autowired
private ImgService imgService;
@Autowired
private ImgreviewService imgreviewService;
@PostMapping(value = "/getUserList")//new selectusertable
@ResponseBody
@PostMapping(value = "/getUserList")//new
public Map<String, Object> getUserList(@RequestParam(value = "data", defaultValue = "") String data) {
JSONObject jsonObj = JSONObject.parseObject(data);
Integer pageNum = jsonObj.getInteger("pageNum");
@@ -181,8 +179,6 @@ public class AdminRootController {
return msg;
}
//获取当前所有的存储策略信息
@PostMapping("/LoadInfo")//new
@ResponseBody
public Msg LoadInfo(@RequestParam(value = "data", defaultValue = "") String data) {
@@ -190,7 +186,6 @@ public class AdminRootController {
try {
JSONObject jsonData = JSONObject.parseObject(data);
Integer keyId = jsonData.getInteger("keyId");
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",keyId);
Keys key = keysService.selectKeys(keyId);
@@ -210,7 +205,6 @@ public class AdminRootController {
}else if(key.getStorageType()==8){
ret = UFileImageupload.Initialize(key);
}
Long l = imgService.getsourcememory(keyId);
jsonObject.put("isok",ret);
jsonObject.put("storagetype",key.getStorageType());
@@ -265,7 +259,7 @@ public class AdminRootController {
}
@PostMapping("/getSettingConfig") //new upload配置表的相关设置
@PostMapping("/getSettingConfig") //new
@ResponseBody
public Msg getSettingConfig(@RequestParam(value = "data", defaultValue = "") String data) {
final Msg msg = new Msg();
@@ -276,9 +270,6 @@ public class AdminRootController {
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
Config config = configService.getSourceype();
SysConfig sysConfig = sysConfigService.getstate();
//把字节换算一下,页面上显示M
// filesizetourists = (filesizetourists*1024*1024) ,filesizeuser=(filesizeuser*1024*1024)
// visitormemory=(visitormemory*1024*1024),usermemory=(usermemory*1024*1024)
uploadConfig.setUsermemory(Long.toString(Long.valueOf(uploadConfig.getUsermemory())/1024/1024));
uploadConfig.setVisitormemory(Long.toString(Long.valueOf(uploadConfig.getVisitormemory())/1024/1024));
uploadConfig.setFilesizetourists(Long.toString(Long.valueOf(uploadConfig.getFilesizetourists())/1024/1024));
@@ -321,11 +312,9 @@ public class AdminRootController {
uploadConfig.setFilesizetourists(Long.toString(Long.valueOf(uploadConfig.getFilesizetourists())*1024*1024));
uploadConfig.setUsermemory(Long.toString(Long.valueOf(uploadConfig.getUsermemory())*1024*1024));
uploadConfig.setFilesizeuser(Long.toString(Long.valueOf(uploadConfig.getFilesizeuser())*1024*1024));
uploadConfigService.setUpdateConfig(uploadConfig);
configService.setSourceype(config);
sysConfigService.setstate(sysConfig);
msg.setInfo("配置保存成功");
}catch (Exception e){
e.printStackTrace();
@@ -336,5 +325,70 @@ public class AdminRootController {
}
@PostMapping(value = "/getOrderConfig")//new
@ResponseBody
public Msg emailconfig() {
final Msg msg = new Msg();
EmailConfig emailConfig = null;
Imgreview imgreview = null;
try {
final JSONObject jsonObject = new JSONObject();
emailConfig = emailConfigService.getemail();
imgreview = imgreviewService.selectByPrimaryKey(1);
jsonObject.put("emailConfig",emailConfig);
jsonObject.put("imgreview",imgreview);
msg.setData(jsonObject);
} catch (Exception e) {
e.printStackTrace();
msg.setCode("110500");
msg.setInfo("获取相关配置信息失败");
}
return msg;
}
@PostMapping("/updateEmailConfig") //new
@ResponseBody
public Msg updateemail(@RequestParam(value = "data", defaultValue = "") String data ) {
final Msg msg = new Msg();
try {
JSONObject jsonObj = JSONObject.parseObject(data);
EmailConfig emailConfig = JSON.toJavaObject(jsonObj,EmailConfig.class);
if(null==emailConfig.getId() || null==emailConfig.getEmailname() || null==emailConfig.getEmailurl() || null==emailConfig.getEmails()
|| null==emailConfig.getEmailkey() || null==emailConfig.getPort() || null==emailConfig.getUsing()
|| emailConfig.getEmailname().equals("") || emailConfig.getEmailurl().equals("") || emailConfig.getEmails().equals("")
|| emailConfig.getEmailkey().equals("") || emailConfig.getPort().equals("")){
msg.setCode("110400");
msg.setInfo("各参数不能为空");
return msg;
}
emailConfigService.updateemail(emailConfig);
msg.setInfo("保存成功");
} catch (Exception e) {
e.printStackTrace();
msg.setCode("110500");
msg.setInfo("保存过程出现错误");
}
return msg;
}
@PostMapping("/mailTest") //new
@ResponseBody
public Msg mailTest(@RequestParam(value = "data", defaultValue = "") String data ) {
Msg msg = new Msg();
JSONObject jsonObj = JSONObject.parseObject(data);
String tomail = jsonObj.getString("tomail");
EmailConfig emailConfig = JSON.toJavaObject(jsonObj,EmailConfig.class);
if(null==emailConfig.getEmails() || null==emailConfig.getEmailkey() || null==emailConfig.getEmailurl()
|| null==emailConfig.getPort() || null==emailConfig.getEmailname() || null==tomail){
// if(jsonObj.size()==0){
msg.setCode("110400");
msg.setInfo("邮箱配置参数不能为空");
}else{
msg = NewSendEmail.sendTestEmail(emailConfig, tomail);
}
return msg;
}
}
@@ -1,6 +1,7 @@
package cn.hellohao.controller;
import cn.hellohao.pojo.*;
import cn.hellohao.pojo.vo.PageResultBean;
import cn.hellohao.service.*;
import cn.hellohao.service.impl.AlbumServiceImpl;
import com.alibaba.fastjson.JSONArray;
@@ -39,7 +40,7 @@ public class AlbumController {
@Autowired
private UserService userService;
@PostMapping("/admin/getGalleryList") //new 获取画廊地址
@PostMapping("/admin/getGalleryList") //new
@ResponseBody
public Map<String, Object> getGalleryList (@RequestParam(value = "data", defaultValue = "") String data){
Subject subject = SecurityUtils.getSubject();
@@ -177,8 +178,82 @@ public class AlbumController {
}
@PostMapping("/checkPass")//new
@ResponseBody
public Msg checkPass(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
JSONObject json = new JSONObject();
JSONObject jsonObject = null;
try {
jsonObject = JSONObject.parseObject(data);
String key = jsonObject.getString("key");
Album album = new Album();
album.setAlbumkey(key);
Album a = albumServiceImpl.selectAlbum(album);
if(a!=null){
json.put("album",a);
json.put("exist",true);
if(a.getPassword()!=null && !a.getPassword().equals("")){
json.put("passType",true);
}else{
json.put("passType",false);
}
msg.setData(json);
}else{
json.put("exist",false);
msg.setData(json);
}
} catch (Exception e) {
e.printStackTrace();
msg.setCode("110500");
msg.setInfo("操作失败");
msg.setData(json);
}
return msg;
}
@PostMapping("/getAlbumList") //new
@ResponseBody
public Msg getAlbumList(@RequestParam(value = "data", defaultValue = "") String data){
Msg msg = new Msg();
JSONObject json = new JSONObject();
JSONObject jsonObject = JSONObject.parseObject(data);
Integer pageNum = jsonObject.getInteger("pageNum");
Integer pageSize = jsonObject.getInteger("pageSize");
String albumkey = jsonObject.getString("albumkey");
String password = jsonObject.getString("password");
if(null!=password){
password = password.replace(" ", "");
}
Album album = new Album();
album.setAlbumkey(albumkey);
Album a = albumServiceImpl.selectAlbum(album);
if(a==null){
msg.setCode("110404");
msg.setInfo("画廊地址不存在");
}else{
PageHelper.startPage(pageNum, pageSize);
if(a.getPassword()==null || (a.getPassword().replace(" ", "")).equals("")){
List<Images> imagesList = imgAndAlbumService.selectImgForAlbumkey(albumkey);
PageInfo<Images> rolePageInfo = new PageInfo<>(imagesList);
PageResultBean<Images> pageResultBean = new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
json.put("imagesList",pageResultBean);
}else{
if(a.getPassword().equals(password)){
List<Images> imagesList = imgAndAlbumService.selectImgForAlbumkey(albumkey);
PageInfo<Images> rolePageInfo = new PageInfo<>(imagesList);
PageResultBean<Images> pageResultBean = new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
json.put("imagesList",pageResultBean);
}else{
msg.setCode("110403");
msg.setInfo("画廊密码错误");
}
}
json.put("titlename",a.getAlbumtitle());
msg.setData(json);
}
return msg;
}
@@ -29,35 +29,17 @@ import java.util.*;
*/
@RestController
public class ClientController {
@Autowired
private NOSImageupload nOSImageupload;
@Autowired
private UserService userService;
@Autowired
private KeysService keysService;
@Autowired
private OSSImageupload ossImageupload;
@Autowired
private ConfigService configService;
@Autowired
private USSImageupload ussImageupload;
@Autowired
private KODOImageupload kodoImageupload;
@Autowired
private UploadConfigService uploadConfigService;
@Autowired
private NoticeService noticeService;
@Autowired
private COSImageupload cosImageupload;
@Autowired
private FTPImageupload ftpImageupload;
@Autowired
private UFileImageupload uFileImageupload;
@Autowired
private ImgService imgService;
@Value("${systemupdate}")
private String systemupdate;
@Autowired
private ClientService clientService;
@PostMapping(value = "/uploadbymail")
@ResponseBody
public Msg uploadbymail(HttpServletRequest request, @RequestParam("file") MultipartFile file, String mail, String pass) {
Msg resultBean = clientService.uploadImg(request, file, mail, pass);
return resultBean;
}
}
@@ -1,13 +1,8 @@
package cn.hellohao.controller;
import cn.hellohao.pojo.Code;
import cn.hellohao.pojo.Config;
import cn.hellohao.pojo.Msg;
import cn.hellohao.pojo.User;
import cn.hellohao.service.CodeService;
import cn.hellohao.service.KeysService;
import cn.hellohao.service.UserService;
import cn.hellohao.service.impl.ImgServiceImpl;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -18,8 +13,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import java.util.*;
/**
@@ -1,44 +0,0 @@
package cn.hellohao.controller;
import cn.hellohao.pojo.Msg;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
/**
* 错误页面拦截
* */
@Controller
class MainsiteErrorController implements ErrorController {
@RequestMapping("/error")
public String handleError(HttpServletRequest request){
//获取statusCode:401,404,500
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
if(statusCode == 401){
return "401";
}else if(statusCode == 404){
return "404";
}else if(statusCode == 403){
return "403";
}else{
return "500";
}
}
//认证失败
@RequestMapping("/jurisError")
@ResponseBody
public Msg jurisError(HttpServletRequest request){
Msg msg = new Msg();
msg.setCode("4031");
msg.setInfo("Authentication request failed");
return msg;
}
}
@@ -67,20 +67,5 @@ public class ExceptionHandling {
// @ExceptionHandler
// public String methodArgumentNotValid(BindException e) {
// List<ObjectError> allErrors = e.getBindingResult().getAllErrors();
// StringBuilder errorMessage = new StringBuilder();
// for (int i = 0; i < allErrors.size(); i++) {
// ObjectError error = allErrors.get(i);
// errorMessage.append(error.getDefaultMessage());
// if (i != allErrors.size() - 1) {
// errorMessage.append(", ");
// }
// }
// // do something
// System.out.println(errorMessage.toString());// 这里面是错误信息
// return errorMessage.toString();
// }
}
@@ -1,26 +1,19 @@
package cn.hellohao.controller;
import cn.hellohao.pojo.Group;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.Msg;
import cn.hellohao.pojo.User;
import cn.hellohao.service.GroupService;
import cn.hellohao.service.KeysService;
import cn.hellohao.service.UserService;
import cn.hellohao.utils.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -52,8 +45,6 @@ public class GroupController {
return msg;
}
//获取code列表
@PostMapping(value = "/getGroupList")//new
@ResponseBody
public Map<String, Object> getgrouplist(@RequestParam(value = "data", defaultValue = "") String data) {
@@ -78,7 +69,6 @@ public class GroupController {
return map;
}
@PostMapping(value = "/addGroup")//new
@ResponseBody
public Msg addisgroup(@RequestParam(value = "data", defaultValue = "") String data) {
@@ -95,7 +85,6 @@ public class GroupController {
@PostMapping("/updateGroup")//new
@ResponseBody
public Msg updategroup(@RequestParam(value = "data", defaultValue = "") String data) {
JSONObject jsonObject = JSONObject.parseObject(data);
Group group = new Group();
group.setId(jsonObject.getInteger("id"));
@@ -1,43 +1,61 @@
package cn.hellohao.controller;
import cn.hellohao.pojo.Imgreview;
import cn.hellohao.pojo.Msg;
import cn.hellohao.service.ImgreviewService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/admin")
@RequestMapping("/admin/root")
public class ImageReviewController {
@Autowired
private ImgreviewService imgreviewService;
@RequestMapping(value = "/root/ImageReview")
public String ForwardImageReview(Model model) {
Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
model.addAttribute("appid", imgreview.getAppId());
model.addAttribute("apikey", imgreview.getApiKey());
model.addAttribute("secretkey", imgreview.getSecretKey());
model.addAttribute("using", imgreview.getUsing());
return "admin/imageIdentify";
}
@RequestMapping(value = "/root/ImgreviewSwitch")
@PostMapping("/updateimgReviewConfig") //new
@ResponseBody
public String ImgreviewSwitch(String appId, String apiKey, String secretKey, Integer using) {
Imgreview imgreview = new Imgreview();
imgreview.setId(1);//目前就一种鉴黄功能所以设死了
imgreview.setUsing(using);
imgreview.setAppId(appId);
imgreview.setApiKey(apiKey);
imgreview.setSecretKey(secretKey);
Integer ret = imgreviewService.updateByPrimaryKeySelective(imgreview);
return ret.toString();
public Msg updateimgReviewConfig(@RequestParam(value = "data", defaultValue = "") String data ) {
final Msg msg = new Msg();
try {
JSONObject jsonObj = JSONObject.parseObject(data);
Imgreview imgreview = JSON.toJavaObject(jsonObj,Imgreview.class);
if(imgreview.getId()==1){
if(null==imgreview.getId() || null==imgreview.getApiKey() || null==imgreview.getUsing() || null==imgreview.getSecretKey()
|| null==imgreview.getAppId() || imgreview.getApiKey().equals("")
|| imgreview.getSecretKey().equals("") || imgreview.getAppId().equals("")){
msg.setCode("110400");
msg.setInfo("各参数不能为空");
return msg;
}
}else{
if(null==imgreview.getId() || null==imgreview.getApiKey() || null==imgreview.getUsing()
|| imgreview.getApiKey().equals("")
){
msg.setCode("110400");
msg.setInfo("各参数不能为空");
return msg;
}
}
if(null == imgreviewService.selectByPrimaryKey(imgreview.getId())){
imgreviewService.insert(imgreview);
}else{
imgreviewService.updateByPrimaryKeySelective(imgreview);
}
msg.setInfo("保存成功");
} catch (Exception e) {
e.printStackTrace();
msg.setCode("110500");
msg.setInfo("保存过程出现错误");
}
return msg;
}
}
@@ -14,62 +14,55 @@ import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
@Controller
public class IndexController {
@Autowired
private ImgService imgService;
@Autowired
private SysConfigService sysConfigService;
@Autowired
IRedisService iRedisService;
@Autowired
private NOSImageupload nOSImageupload;
@Autowired
private UserService userService;
@Autowired
private KeysService keysService;
@Autowired
private ConfigService configService;
@Autowired
private UploadConfigService uploadConfigService;
@Autowired
private USSImageupload ussImageupload;
private UploadServicel uploadServicel;
@Autowired
private KODOImageupload kodoImageupload;
private NOSImageupload nosImageupload;
@Autowired
private OSSImageupload ossImageupload;
@Autowired
private COSImageupload cosImageupload;
@Autowired
private KODOImageupload kodoImageupload;
@Autowired
private USSImageupload ussImageupload;
@Autowired
private UFileImageupload uFileImageupload;
@Autowired
private FTPImageupload ftpImageupload;
@Autowired
private ImgService imgService;
AlbumServiceImpl albumService;
@Autowired
private UploadServicel uploadServicel;
private String[] iparr;
public static String vu;
private KeysService keysService;
@Autowired
private ImgTempService imgTempService;
@Autowired
private ImgAndAlbumService imgAndAlbumService;
@RequestMapping(value = "/webInfo")//upimg new
@RequestMapping(value = "/webInfo")
@ResponseBody
public Msg webInfo(HttpSession httpSession) {
public Msg webInfo() {
final Msg msg = new Msg();
Config config = configService.getSourceype();
UploadConfig updateConfig = uploadConfigService.getUpdateConfig();
@@ -86,8 +79,6 @@ public class IndexController {
jsonObject.put("aboutinfo",config.getAboutinfo());
jsonObject.put("logo",config.getLogo());
jsonObject.put("api",updateConfig.getApi());
// jsonObject.put("watermark",updateConfig.getWatermark());
// jsonObject.put("guidepage",sysConfig.getGuidepage());
jsonObject.put("register",sysConfig.getRegister());
msg.setData(jsonObject);
return msg;
@@ -109,11 +100,6 @@ public class IndexController {
return uploadServicel.uploadForLoc(request,multipartFile,day,null,jsonArray);
}
@RequestMapping(value = "/getUploadInfo")//new
@ResponseBody
public Msg getUploadInfo() {
@@ -148,19 +134,13 @@ public class IndexController {
String token = request.getHeader("Authorization");
if(token != null) {
JSONObject tokenJson = JWTUtil.checkToken(token);
// boolean check = (boolean) result.get("check");
// String password = (String) result.get("password");
if(tokenJson.getBoolean("check")){
//获取当前用户
Subject subject = SecurityUtils.getSubject();
//封装用户的登录数据(shiro认证的时候使用)
UsernamePasswordToken tokenOBJ = new UsernamePasswordToken(tokenJson.getString("email"),tokenJson.getString("password"));
//设置记住我
tokenOBJ.setRememberMe(true);
try {
//执行登录方法,如果没有异常,说明登录成功
subject.login(tokenOBJ);
SecurityUtils.getSubject().getSession().setTimeout(3600000);//一小时
SecurityUtils.getSubject().getSession().setTimeout(3600000);
User u = (User) subject.getPrincipal();
final JSONObject jsonObject = new JSONObject();
jsonObject.put("RoleLevel",u.getLevel()==2?"admin":"user");
@@ -168,7 +148,6 @@ public class IndexController {
msg.setCode("200");
msg.setData(jsonObject);
} catch (Exception e) {
//此异常说明用户名不存在
msg.setCode("40041");
msg.setInfo("登录失效,请重新登录");
System.err.println("登录失效,请重新登录");
@@ -246,8 +225,92 @@ public class IndexController {
}
}
//删除图像
@PostMapping("/deleImagesByUid") //new
@ResponseBody
public Msg deleImagesByUid(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
JSONObject jsonObj = JSONObject.parseObject(data);
String imguid = jsonObj.getString("imguid");
Images image = imgService.selectImgUrlByImgUID(imguid);
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if(null!=user){
if(user.getId()!=image.getUserid()){
msg.setInfo("删除失败,该图片不允许你执行操作");
msg.setCode("100403");
return msg;
}
}
Integer keyid = image.getSource();
String imgname = image.getImgname();
Keys key = keysService.selectKeys(keyid);
//删除图片
boolean isDele = false;
if (key.getStorageType() == 1) {
isDele = nosImageupload.delNOS(key.getId(), imgname);
} else if (key.getStorageType() == 2) {
isDele = ossImageupload.delOSS(key.getId(), imgname);
} else if (key.getStorageType() == 3) {
isDele = ussImageupload.delUSS(key.getId(), imgname);
} else if (key.getStorageType() == 4) {
isDele = kodoImageupload.delKODO(key.getId(), imgname);
} else if (key.getStorageType() == 5) {
isDele = LocUpdateImg.deleteLOCImg(imgname);
}else if (key.getStorageType() == 6) {
isDele = cosImageupload.delCOS(key.getId(), imgname);
}else if (key.getStorageType() == 7) {
isDele = ftpImageupload.delFTP(key.getId(), imgname);
}else if (key.getStorageType() == 8) {
isDele = uFileImageupload.delUFile(key.getId(), imgname);
}else {
System.err.println("未获取到对象存储参数,删除失败。");
}
//删除库
if(isDele){
try {
imgAndAlbumService.deleteImgAndAlbum(imgname);
imgTempService.delImgAndExp(image.getImguid());
imgService.deleimg(image.getId());
} catch (Exception e) {
e.printStackTrace();
msg.setInfo("图片记录时发生错误");
msg.setCode("500");
return msg;
}
msg.setInfo("删除成功");
}else{
imgAndAlbumService.deleteImgAndAlbum(imgname);
imgTempService.delImgAndExp(image.getImguid());
imgService.deleimg(image.getId());
msg.setInfo("图片记录已删除,但是图片源删除失败");
msg.setCode("500");
}
System.out.println("返回的值:"+msg.toString());
return msg;
}
//没有权限
@RequestMapping("/authError")
@ResponseBody
public Msg authError(HttpServletRequest request){
Msg msg = new Msg();
msg.setCode("4031");
msg.setInfo("You don't have authority");
return msg;
}
//认证失败
@RequestMapping("/jurisError")
@ResponseBody
public Msg jurisError(HttpServletRequest request){
Msg msg = new Msg();
msg.setCode("4031");
msg.setInfo("Authentication request failed");
return msg;
}
}
@@ -13,6 +13,7 @@ import cn.hellohao.config.SysName;
import cn.hellohao.pojo.*;
import cn.hellohao.service.*;
import cn.hellohao.utils.*;
import cn.hutool.core.util.HexUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
@@ -54,16 +55,13 @@ public class UserController {
String userIP = GetIPS.getIpAddr(request);
String verifyCodeForRegister = jsonObj.getString("verifyCode");
Object redis_verifyCodeForRegister = iRedisService.getValue(userIP+"_hellohao_verifyCodeForRegister");
if(!SetText.checkEmail(email)){
//邮箱格式不正确
msg.setCode("110403");
msg.setInfo("邮箱格式不正确");
return msg;
}
String regex = "^\\w+$";
if(username.length()>20 || !username.matches (regex)){
//用户名格式不正确
msg.setCode("110403");
msg.setInfo("用户名不得超过20位字符");
return msg;
@@ -135,7 +133,6 @@ public class UserController {
return msg;
}
//shiro登录认证
@PostMapping("/login")//new
@ResponseBody
public Msg login(HttpServletRequest request,@RequestParam(value = "data", defaultValue = "") String data) {
@@ -156,15 +153,10 @@ public class UserController {
return msg;
}
if((redis_VerifyCode.toString().toLowerCase()).compareTo((verifyCode.toLowerCase()))==0){
// if(true){
//获取当前用户
Subject subject = SecurityUtils.getSubject();
//封装用户的登录数据(shiro认证的时候使用)
UsernamePasswordToken tokenOBJ = new UsernamePasswordToken(email,password);
//设置记住我
tokenOBJ.setRememberMe(true);
try {
//执行登录方法,如果没有异常,说明登录成功
subject.login(tokenOBJ);
SecurityUtils.getSubject().getSession().setTimeout(3600000);//一小时
JSONObject jsonObject = new JSONObject();
@@ -179,7 +171,6 @@ public class UserController {
msg.setCode("110403");
return msg;
}
// String token = TokenUtil.sign(user);
String token = JWTUtil.createToken(user);
Subject su = SecurityUtils.getSubject();
System.out.println("当前用户角色:admin:"+su.hasRole("admin"));
@@ -216,8 +207,33 @@ public class UserController {
return msg;
}
//邮箱激活
@RequestMapping(value = "/activation", method = RequestMethod.GET)
public String activation(Model model, HttpServletRequest request, HttpSession session, String activation, String username) {
Config config = configService.getSourceype();
Integer ret = 0;
User u2 = new User();
u2.setUid(activation);
User user = userService.getUsers(u2);
model.addAttribute("webhost",SubjectFilter.WEBHOST);
if (user != null && user.getIsok() == 0) {
userService.uiduser(activation);
model.addAttribute("title","激活成功");
model.addAttribute("name","Hi~"+username);
model.addAttribute("note","您的账号已成功激活看");
return "msg";
} else {
model.addAttribute("title","操作无效");
model.addAttribute("name","该页面为无效页面");
model.addAttribute("note","请返回首页");
return "msg";
}
}
//退出
@PostMapping(value = "/logout")
@PostMapping(value = "/logout")//new
@ResponseBody
public Msg exit(Model model, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
Msg msg = new Msg();
@@ -228,7 +244,8 @@ public class UserController {
return msg;
}
@PostMapping("/retrievePass")
//retrievepass
@PostMapping("/retrievePass") //new
@ResponseBody
public Msg retrievePass(HttpServletRequest request, @RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
@@ -238,6 +255,7 @@ public class UserController {
String retrieveCode = jsonObj.getString("retrieveCode");
String userIP = GetIPS.getIpAddr(request);
Object redis_verifyCodeForEmailRetrieve = iRedisService.getValue(userIP+"_hellohao_verifyCodeForEmailRetrieve");
EmailConfig emailConfig = emailConfigService.getemail();
if(null==redis_verifyCodeForEmailRetrieve){
msg.setCode("4035");
@@ -290,47 +308,43 @@ public class UserController {
}
//邮箱激活
@RequestMapping(value = "/activation", method = RequestMethod.GET)
public String activation(Model model, HttpServletRequest request, HttpSession session, String activation, String username) {
Config config = configService.getSourceype();
@RequestMapping(value = "/retrieve", method = RequestMethod.GET) //new
public String retrieve(Model model, String activation,String cip) {
Integer ret = 0;
User u2 = new User();
u2.setUid(activation);
User user = userService.getUsers(u2);
try {
User u2 = new User();
u2.setUid(activation);
User user = userService.getUsers(u2);
user.setIsok(1);
String new_pass = HexUtil.decodeHexStr(cip);//解密密码
user.setPassword(Base64Encryption.encryptBASE64(new_pass.getBytes()));
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
user.setUid(uid);
if (user != null) {
Integer r = userService.changeUser(user);
model.addAttribute("title","成功");
model.addAttribute("name","新密码:"+new_pass);//
model.addAttribute("note","密码已被系统重置,请即使登录修改你的新密码");
} else {
model.addAttribute("title","抱歉");
model.addAttribute("name","为获取到用户信息");
model.addAttribute("note","操作失败");
}
}catch (Exception e){
e.printStackTrace();
model.addAttribute("title","抱歉");
model.addAttribute("name","系统操作过程中发生错误");
model.addAttribute("note","操作失败");
}
model.addAttribute("webhost", SubjectFilter.WEBHOST);
if (user != null && user.getIsok() == 0) {
userService.uiduser(activation);
model.addAttribute("title","激活成功");
model.addAttribute("name","Hi~"+username);
model.addAttribute("note","您的账号已成功激活看");
return "msg";
} else {
model.addAttribute("title","操作无效");
model.addAttribute("name","该页面为无效页面");
model.addAttribute("note","请返回首页");
return "msg";
}
return "msg";
}
}
@PostMapping(value = "/verification")
@ResponseBody
public Integer verification(HttpSession session,Integer tmp,Integer type) {
Random random = new Random();
if(type==1){
number1 = random.nextInt(100);
istmp1 = tmp;
Print.Normal(tmp-number1);
}
if(type==2){
number2 = random.nextInt(100);
istmp2 = tmp;
Print.Normal(tmp-number2);
}
return 1;
}
private Integer number1;
private Integer istmp1;
private Integer number2;
private Integer istmp2;
}