mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
2019-08-29更新
This commit is contained in:
@@ -5,10 +5,7 @@ import cn.hellohao.pojo.vo.PageResultBean;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.service.impl.ImgServiceImpl;
|
||||
import cn.hellohao.service.impl.UserServiceImpl;
|
||||
import cn.hellohao.utils.GetCurrentSource;
|
||||
import cn.hellohao.utils.LocUpdateImg;
|
||||
import cn.hellohao.utils.Print;
|
||||
import cn.hellohao.utils.StringUtils;
|
||||
import cn.hellohao.utils.*;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
@@ -19,6 +16,7 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -202,12 +200,19 @@ public class AdminController {
|
||||
// 从他的下一条sql开始分页
|
||||
PageHelper.startPage(page, limit);
|
||||
List<User> users = null;
|
||||
List<User> users2 = new ArrayList<>();
|
||||
if (u.getLevel() > 1) { //根据用户等级查询管理员查询所有的信息
|
||||
User user = new User();
|
||||
user.setUsername(username);
|
||||
users = userService.getuserlist(user);// 这是我们的sql
|
||||
for (User user1 : users) {
|
||||
User uu = new User();
|
||||
uu = user1;
|
||||
uu.setPassword(Base64Encryption.decryptBASE64(user1.getPassword()));
|
||||
users2.add(uu);
|
||||
}
|
||||
// 使用pageInfo包装查询
|
||||
PageInfo<User> rolePageInfo = new PageInfo<>(users);//
|
||||
PageInfo<User> rolePageInfo = new PageInfo<>(users2);//
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("code", 0);
|
||||
map.put("msg", "");
|
||||
@@ -335,16 +340,21 @@ public class AdminController {
|
||||
@ResponseBody
|
||||
public String change(HttpSession session, User user) {
|
||||
User u = (User) session.getAttribute("user");
|
||||
User us = new User();
|
||||
//user.setEmail(u.getEmail());
|
||||
user.setUid(u.getUid());
|
||||
us.setEmail(user.getEmail());
|
||||
us.setUsername(user.getUsername());
|
||||
us.setPassword(Base64Encryption.encryptBASE64(user.getPassword().getBytes()));
|
||||
us.setUid(u.getUid());
|
||||
//user.setUid(u.getUid());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Integer ret =0;
|
||||
if(u.getLevel()==1){
|
||||
user.setUsername(null);
|
||||
user.setEmail(null);
|
||||
ret = userService.change(user);
|
||||
us.setUsername(null);
|
||||
us.setEmail(null);
|
||||
ret = userService.change(us);
|
||||
}else{
|
||||
ret = userService.change(user);
|
||||
ret = userService.change(us);
|
||||
}
|
||||
jsonArray.add(ret);
|
||||
if (u.getEmail() != null && u.getPassword() != null) {
|
||||
|
||||
@@ -2,7 +2,9 @@ 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.StringUtils;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
@@ -21,7 +23,8 @@ import java.util.HashMap;
|
||||
@Controller
|
||||
@RequestMapping("/admin/root")
|
||||
public class AdminRootController {
|
||||
|
||||
@Autowired
|
||||
private NOSImageupload nOSImageupload;
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
@Autowired
|
||||
@@ -112,12 +115,36 @@ public class AdminRootController {
|
||||
Config config = new Config();
|
||||
config.setSourcekey(key.getStorageType());
|
||||
Integer val = configService.setSourceype(config);
|
||||
if (val > 0) {
|
||||
Integer ret = keysService.updateKey(key);
|
||||
jsonArray.add(ret);
|
||||
} else {
|
||||
jsonArray.add(0);
|
||||
//if (val > 0) {
|
||||
Integer ret = -2;
|
||||
//修改完初始化
|
||||
if(key.getStorageType()==1){
|
||||
ret =nOSImageupload.Initialize(key);//实例化网易
|
||||
}else if (key.getStorageType()==2){
|
||||
ret = OSSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==3){
|
||||
ret = USSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==4){
|
||||
ret = KODOImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==6){
|
||||
ret = COSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==7){
|
||||
ret = FTPImageupload.Initialize(key);
|
||||
}
|
||||
else{
|
||||
Print.Normal("为获取到存储参数,或者使用存储源是本地的。");
|
||||
}
|
||||
if(ret>0){
|
||||
ret = keysService.updateKey(key);
|
||||
}
|
||||
|
||||
//-1 对象存储有参数为空,初始化失败
|
||||
//0,保存失败
|
||||
//1 正确
|
||||
jsonArray.add(ret);
|
||||
//} else {
|
||||
//jsonArray.add(0);
|
||||
// }
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -224,6 +224,21 @@ public class ClientController {
|
||||
|
||||
return "-1";//-1就是没有公告,客户端不显示
|
||||
}
|
||||
|
||||
//主端接口
|
||||
@PostMapping("/systemupdate")
|
||||
@ResponseBody
|
||||
public String sysupdate(String dates) {
|
||||
Integer i=dates.compareTo(systemupdate);//小于0则需要更新
|
||||
System.out.println(i);
|
||||
return i.toString();
|
||||
}
|
||||
//主端接口
|
||||
@PostMapping("/getdomain")
|
||||
@ResponseBody
|
||||
public String getdomain(String domain) {
|
||||
Integer count = domainService.getDomain(domain);
|
||||
//System.out.println(i);
|
||||
return count.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public class ExceptionHandling {
|
||||
public String test4(SocketException e){
|
||||
ModelAndView modelAndView = new ModelAndView("/index");
|
||||
Print.Normal("存储源配置不正确,初始化失败"+ e.getMessage());
|
||||
e.printStackTrace();
|
||||
modelAndView.addObject("error",e.getMessage());
|
||||
//返回错误信息,并显示给用户
|
||||
return e.getMessage();
|
||||
@@ -43,6 +44,7 @@ public class ExceptionHandling {
|
||||
public String test3(Exception e){
|
||||
ModelAndView modelAndView = new ModelAndView("/index");
|
||||
Print.Normal("系统内部错误:"+ e.getMessage());
|
||||
e.printStackTrace();
|
||||
modelAndView.addObject("error",e.getMessage());
|
||||
//返回错误信息,并显示给用户
|
||||
return e.getMessage();
|
||||
|
||||
@@ -72,33 +72,7 @@ public class UpdateImgController {
|
||||
if(uploadConfig.getImgcounttourists()!=null){imgcounttourists = uploadConfig.getImgcounttourists();}
|
||||
if(uploadConfig.getImgcountuser()!=null){imgcountuser = uploadConfig.getImgcountuser();}
|
||||
//Boolean b =false;
|
||||
Keys key = null;
|
||||
Integer Sourcekey = GetCurrentSource.GetSource(u==null?null:u.getId());
|
||||
if(Sourcekey!=0 && Sourcekey!=5){
|
||||
key= keysService.selectKeys(Sourcekey);//然后根据类型再查询key
|
||||
//b = StringUtils.doNull(key);//判断对象是否有空值
|
||||
if(key.getStorageType()!=0 && key.getStorageType()!=null){
|
||||
int ret =0;
|
||||
if(key.getStorageType()==1){
|
||||
ret =nOSImageupload.Initialize(key);//实例化网易
|
||||
}else if (key.getStorageType()==2){
|
||||
ret =OSSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==3){
|
||||
ret = USSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==4){
|
||||
ret = KODOImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==6){
|
||||
ret = COSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==7){
|
||||
ret = FTPImageupload.Initialize(key);
|
||||
}
|
||||
else{
|
||||
Print.Normal("为获取到存储参数,或者使用存储源是本地的。");
|
||||
}
|
||||
if(ret<1){model.addAttribute("error", "当前存储源参数配置不完整,请联系管理员配置存储源。");}
|
||||
else{model.addAttribute("error", 1);}
|
||||
}
|
||||
}
|
||||
//Integer Sourcekey = GetCurrentSource.GetSource(u==null?null:u.getId());//查询当当前用户或者游客使用的数据源
|
||||
if (email != null) {
|
||||
//登陆成功
|
||||
Integer ret = userService.login(u.getEmail(), u.getPassword());
|
||||
@@ -140,14 +114,12 @@ public class UpdateImgController {
|
||||
, @RequestParam(value = "file", required = false) MultipartFile[] file) throws Exception {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
|
||||
Config config = configService.getSourceype();
|
||||
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
|
||||
User u = (User) session.getAttribute("user");
|
||||
Integer usermemory =0;
|
||||
Integer memory =0;
|
||||
Integer Sourcekey=0;
|
||||
//User tmpuser = userService.getUsers(u.getEmail());
|
||||
//GetCurrentSource getCurrentSource = new GetCurrentSource();
|
||||
if(u==null){
|
||||
Sourcekey = GetCurrentSource.GetSource(null);
|
||||
memory = uploadConfig.getVisitormemory();
|
||||
@@ -526,15 +498,6 @@ public class UpdateImgController {
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getsentence")
|
||||
@ResponseBody
|
||||
public String getsentence(HttpSession session) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String yiyan = Sentence.getURLContent();
|
||||
|
||||
return yiyan;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/err")
|
||||
public String err() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.hellohao.controller;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
@@ -12,6 +13,8 @@ import javax.validation.Valid;
|
||||
|
||||
import cn.hellohao.pojo.*;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.utils.Base64Encryption;
|
||||
import cn.hellohao.utils.Print;
|
||||
import cn.hellohao.utils.SendEmail;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -44,86 +47,97 @@ public class UserController {
|
||||
|
||||
@RequestMapping("/register")
|
||||
@ResponseBody
|
||||
public String Register(@Valid User user) {
|
||||
//取当前时间
|
||||
UploadConfig updateConfig = uploadConfigService.getUpdateConfig();
|
||||
public String Register(@Valid User u,Integer zctmp) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
EmailConfig emailConfig = emailConfigService.getemail();
|
||||
Integer countusername = userService.countusername(user.getUsername());
|
||||
Integer countmail = userService.countmail(user.getEmail());
|
||||
SysConfig sysConfig = sysConfigService.getstate();
|
||||
if(sysConfig.getRegister()==1){
|
||||
if (countusername == 0 && countmail == 0) {
|
||||
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
||||
String birthder = df.format(new Date());// new Date()为获取当前系统时间
|
||||
user.setLevel(1);
|
||||
user.setUid(uid);
|
||||
user.setBirthder(birthder);
|
||||
user.setMemory(updateConfig.getUsermemory());
|
||||
user.setGroupid(1);
|
||||
//查询是否启用了邮箱验证。
|
||||
Config config = configService.getSourceype();
|
||||
System.err.println("是否启用了邮箱激活:"+emailConfig.getUsing());
|
||||
Integer type = 0;
|
||||
if(emailConfig.getUsing()==1){
|
||||
user.setIsok(0);
|
||||
//初始化邮箱
|
||||
MimeMessage message = SendEmail.Emails(emailConfig);
|
||||
//注册完发激活链接
|
||||
Thread thread = new Thread() {
|
||||
public void run() {
|
||||
Integer a = SendEmail.sendEmail(message, user.getUsername(), uid, user.getEmail(),emailConfig,config);
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
type = 1;
|
||||
}else{
|
||||
//直接注册
|
||||
user.setIsok(1);
|
||||
type = 2;
|
||||
}
|
||||
Integer ret = userService.register(user);
|
||||
if(ret>0){
|
||||
if((zctmp-number2)==(istmp2-number2)){
|
||||
//取当前时间
|
||||
User user = new User();
|
||||
UploadConfig updateConfig = uploadConfigService.getUpdateConfig();
|
||||
EmailConfig emailConfig = emailConfigService.getemail();
|
||||
Integer countusername = userService.countusername(u.getUsername());
|
||||
Integer countmail = userService.countmail(u.getEmail());
|
||||
SysConfig sysConfig = sysConfigService.getstate();
|
||||
if(sysConfig.getRegister()==1){
|
||||
if (countusername == 0 && countmail == 0) {
|
||||
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
||||
String birthder = df.format(new Date());// new Date()为获取当前系统时间
|
||||
user.setLevel(1);
|
||||
user.setUid(uid);
|
||||
user.setBirthder(birthder);
|
||||
user.setMemory(updateConfig.getUsermemory());
|
||||
user.setGroupid(1);
|
||||
user.setEmail(u.getEmail());
|
||||
user.setUsername(u.getUsername());
|
||||
user.setPassword(Base64Encryption.encryptBASE64(u.getPassword().getBytes()));
|
||||
//查询是否启用了邮箱验证。
|
||||
Config config = configService.getSourceype();
|
||||
System.err.println("是否启用了邮箱激活:"+emailConfig.getUsing());
|
||||
Integer type = 0;
|
||||
if(emailConfig.getUsing()==1){
|
||||
user.setIsok(0);
|
||||
//初始化邮箱
|
||||
MimeMessage message = SendEmail.Emails(emailConfig);
|
||||
//注册完发激活链接
|
||||
Thread thread = new Thread() {
|
||||
public void run() {
|
||||
Integer a = SendEmail.sendEmail(message, user.getUsername(), uid, user.getEmail(),emailConfig,config);
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
type = 1;
|
||||
}else{
|
||||
//直接注册
|
||||
user.setIsok(1);
|
||||
type = 2;
|
||||
}
|
||||
Integer ret = userService.register(user);
|
||||
if(ret>0){
|
||||
// UserGroup userGroup = new UserGroup();
|
||||
// User user1 = userService.getUsersMail(uid);
|
||||
// userGroup.setUserid(user1.getId());
|
||||
// userGroup.setGroupid(1);
|
||||
// userGroupService.addusergroup(userGroup);
|
||||
}
|
||||
jsonObject.put("ret",ret);
|
||||
jsonObject.put("zctype",type);
|
||||
} else {
|
||||
jsonObject.put("ret",-2);
|
||||
}
|
||||
jsonObject.put("ret",ret);
|
||||
jsonObject.put("zctype",type);
|
||||
} else {
|
||||
jsonObject.put("ret",-2);
|
||||
}else{
|
||||
jsonObject.put("ret",-3); //管理员关闭的注册
|
||||
}
|
||||
}else{
|
||||
jsonObject.put("ret",-3); //管理员关闭的注册
|
||||
jsonObject.put("ret",-4);//非法注册
|
||||
}
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/login.do")
|
||||
@RequestMapping("/login")
|
||||
@ResponseBody
|
||||
public String login( HttpSession httpSession, String email, String password) {
|
||||
public String login( HttpSession httpSession, String email, String password,Integer logotmp) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
Integer ret = userService.login(email, password);
|
||||
if (ret > 0) {
|
||||
User user = userService.getUsers(email);
|
||||
if (user.getIsok() == 1) {
|
||||
httpSession.setAttribute("user", user);
|
||||
httpSession.setAttribute("email", user.getEmail());
|
||||
httpSession.setAttribute("pass", user.getPassword());
|
||||
jsonArray.add(1);
|
||||
} else if(ret==-1){
|
||||
jsonArray.add(-1);
|
||||
}else {
|
||||
jsonArray.add(-2);
|
||||
if((logotmp-number1)==(istmp1-number1)){
|
||||
String basepass = Base64Encryption.encryptBASE64(password.getBytes());
|
||||
Integer ret = userService.login(email, basepass);
|
||||
if (ret > 0) {
|
||||
User user = userService.getUsers(email);
|
||||
if (user.getIsok() == 1) {
|
||||
httpSession.setAttribute("user", user);
|
||||
httpSession.setAttribute("email", user.getEmail());
|
||||
jsonArray.add(1);
|
||||
} else if(ret==-1){
|
||||
jsonArray.add(-1);
|
||||
}else {
|
||||
jsonArray.add(-2);
|
||||
}
|
||||
} else {
|
||||
jsonArray.add(0);
|
||||
}
|
||||
} else {
|
||||
jsonArray.add(0);
|
||||
}else{jsonArray.add(-3);//非法登录
|
||||
}
|
||||
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
@@ -166,5 +180,26 @@ public class UserController {
|
||||
}
|
||||
|
||||
}
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -5,11 +5,14 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface KeysMapper {
|
||||
//查询密钥
|
||||
Keys selectKeys(@Param("storageType") Integer storageType);
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
List<Keys> getKeys();
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ public interface UserMapper {
|
||||
User getUsersMail(@Param("uid") String uid);
|
||||
Integer setisok (User user);
|
||||
|
||||
Integer setisok (User user);
|
||||
Integer setmemory(User user);
|
||||
User getUsersid(@Param("id") Integer id);
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ package cn.hellohao.service;
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface KeysService {
|
||||
//查询密钥
|
||||
Keys selectKeys(Integer storageType);
|
||||
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
|
||||
List<Keys> getKeys();
|
||||
}
|
||||
|
||||
@@ -134,10 +134,10 @@ public class FTPImageupload {
|
||||
}catch (IOException e){
|
||||
System.out.println(e);
|
||||
}
|
||||
Print.warning("连接失败");
|
||||
//Print.warning("连接失败");
|
||||
ret = -1;
|
||||
}
|
||||
Print.Normal("链接成功");
|
||||
//Print.Normal("链接成功");
|
||||
//boolean isUpload = ftp.storeFile("/ftp/upload.jpg", fis);
|
||||
ftpClient1 = ftp;
|
||||
key = k;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.dao.KeysMapper;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.utils.Print;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Hellohao
|
||||
* @version 1.0
|
||||
* @date 2019/8/28 15:33
|
||||
*/
|
||||
|
||||
@Component
|
||||
@Order(2) //通过order值的大小来决定启动的顺序
|
||||
public class InitializationStorage implements CommandLineRunner {
|
||||
@Autowired
|
||||
private KeysMapper keysMapper;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
intiStorage();
|
||||
sout();
|
||||
}
|
||||
public void intiStorage(){
|
||||
List<Keys> keylist = keysMapper.getKeys();
|
||||
for (Keys key : keylist) {
|
||||
if(key.getStorageType()!=0 && key.getStorageType()!=null){
|
||||
int ret =0;
|
||||
if(key.getStorageType()==1){
|
||||
ret =NOSImageupload.Initialize(key);//实例化网易
|
||||
}else if (key.getStorageType()==2){
|
||||
ret =OSSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==3){
|
||||
ret = USSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==4){
|
||||
ret = KODOImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==6){
|
||||
ret = COSImageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==7){
|
||||
ret = FTPImageupload.Initialize(key);
|
||||
}
|
||||
else{
|
||||
//Print.warning("未获取到存储参数,或者使用存储源是本地的。");
|
||||
}
|
||||
// if(ret<1){model.addAttribute("error", "当前存储源参数配置不完整,请联系管理员配置存储源。");}
|
||||
// else{model.addAttribute("error", 1);}
|
||||
}
|
||||
}
|
||||
Print.Normal("初始化完成");
|
||||
}
|
||||
|
||||
public void sout(){
|
||||
Print.Normal("______________________________________________");
|
||||
Print.Normal(" Hellohao-Pro ");
|
||||
Print.Normal(" Successful startup of the program ");
|
||||
Print.Normal(" is OK! Open http://your ip:port ");
|
||||
Print.Normal("______________________________________________");
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import cn.hellohao.dao.KeysMapper;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.service.KeysService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class KeysServiceImpl implements KeysService {
|
||||
|
||||
@@ -26,4 +28,9 @@ public class KeysServiceImpl implements KeysService {
|
||||
return keysMapper.updateKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Keys> getKeys() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,88 +6,71 @@ import cn.hutool.crypto.SecureUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import java.io.*;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Date;
|
||||
|
||||
public class test1 {
|
||||
|
||||
// private static final String KEY = "myMw6qPt&3AD";
|
||||
private static final String KEY = "myMw6qPt&3GHSE";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
java.text.DateFormat format1 = new java.text.SimpleDateFormat("MMddhhmmss");
|
||||
String times = format1.format(new Date());
|
||||
//待加密字段
|
||||
String source = times+"201908111340402000";
|
||||
//加密
|
||||
String result = enCryptAndEncode(source);
|
||||
Print.warning(result);
|
||||
//解密
|
||||
String source_2 = deCryptAndDecode(result);
|
||||
Print.warning(source_2);
|
||||
System.out.println("判断是否相等:"+source.equals(source_2));
|
||||
System.out.println(SecureUtil.md5("200"));
|
||||
//System.out.println(SecureUtil.sha256("201908111340402000"));
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
readFile(File.separator + "HellohaoData"+File.separator+"db.db");
|
||||
//charu();
|
||||
}
|
||||
|
||||
|
||||
public static String enCryptAndEncode(String content) {
|
||||
public static void charu() {
|
||||
String filePath =File.separator + "HellohaoData" ;
|
||||
File file = new File(filePath);
|
||||
File file1 = new File(filePath+File.separator+"db.db");
|
||||
if(!file.exists()){
|
||||
file.mkdirs();
|
||||
}
|
||||
if(!file1.exists()){
|
||||
try {
|
||||
file1.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
byte[] sourceBytes = enCryptAndEncode(content, KEY);
|
||||
return Base64.encodeBase64URLSafeString(sourceBytes);
|
||||
} catch (Exception e) {
|
||||
return content;
|
||||
//如果文件存在,则追加内容;如果文件不存在,则创建文件
|
||||
fw = new FileWriter(file1, true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
PrintWriter pw = new PrintWriter(fw);
|
||||
pw.println("666666");
|
||||
pw.flush();
|
||||
try {
|
||||
fw.flush();
|
||||
pw.close();
|
||||
fw.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密函数
|
||||
*
|
||||
* @param content 加密的内容
|
||||
* @param strKey 密钥
|
||||
* @return 返回二进制字符数组
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] enCryptAndEncode(String content, String strKey) throws Exception {
|
||||
|
||||
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
|
||||
keyGenerator.init(128, new SecureRandom(strKey.getBytes()));
|
||||
|
||||
SecretKey desKey = keyGenerator.generateKey();
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, desKey);
|
||||
return cipher.doFinal(content.getBytes("UTF-8"));
|
||||
// 读取文件内容
|
||||
public static String readFile(String path) {//路径
|
||||
File file = new File(path);
|
||||
StringBuilder result = new StringBuilder();
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GBK"));//构造一个BufferedReader类来读取文件
|
||||
String s = null;
|
||||
while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行
|
||||
result.append(System.lineSeparator() + s);
|
||||
Print.Normal( s);
|
||||
}
|
||||
br.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String deCryptAndDecode(String content) throws Exception {
|
||||
byte[] targetBytes = Base64.decodeBase64(content);
|
||||
return deCryptAndDecode(targetBytes, KEY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解密函数
|
||||
*
|
||||
* @param src 加密过的二进制字符数组
|
||||
* @param strKey 密钥
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String deCryptAndDecode(byte[] src, String strKey) throws Exception {
|
||||
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
|
||||
keyGenerator.init(128, new SecureRandom(strKey.getBytes()));
|
||||
|
||||
SecretKey desKey = keyGenerator.generateKey();
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
cipher.init(Cipher.DECRYPT_MODE, desKey);
|
||||
byte[] cByte = cipher.doFinal(src);
|
||||
return new String(cByte, "UTF-8");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ public class AfterServiceStarted implements ApplicationRunner {
|
||||
*/
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
Print.Normal("================================================");
|
||||
Print.Normal("|| Hellohao-Pro图床启动成功 ||");
|
||||
Print.Normal("|| 作者博客:Http://www.hellohao.cn ||");
|
||||
Print.Normal("|| 也许这将是最好用的图床 ||");
|
||||
Print.Normal("=================================================");
|
||||
// Print.Normal("______________________________________________");
|
||||
// Print.Normal(" Hellohao-Pro ");
|
||||
// Print.Normal(" Successful startup of the program ");
|
||||
// Print.Normal(" is OK! Open http://your ip:port ");
|
||||
// Print.Normal("______________________________________________");
|
||||
//getLinuxLocalIp();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* Created by Hellohao on 2019-08-27.
|
||||
*/
|
||||
public class Base64Encryption {
|
||||
|
||||
public static void main(String[] args) {
|
||||
toBaseCode("admin");
|
||||
}
|
||||
/**
|
||||
* BASE64加密解密
|
||||
*/
|
||||
public static void toBaseCode(String str) {
|
||||
String data = encryptBASE64(str.getBytes());
|
||||
System.out.println("sun.misc.BASE64 加密后:" + data);
|
||||
System.out.println("sun.misc.BASE64 解密后:" + decryptBASE64(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* BASE64解密
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decryptBASE64(String key) {
|
||||
byte[] b =null;
|
||||
try {
|
||||
b = (new BASE64Decoder()).decodeBuffer(key);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* BASE64加密
|
||||
*/
|
||||
public static String encryptBASE64(byte[] key) {
|
||||
|
||||
String string = "SGVsbG9oYW8K";
|
||||
System.out.println(string.replaceAll("\r|\n",""));
|
||||
|
||||
return (new BASE64Encoder()).encodeBuffer(key).replaceAll("\r|\n", "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user