:snail:优化了一些功能

This commit is contained in:
hello-hao
2023-09-18 17:17:21 +08:00
parent 86ae47e632
commit fc53e4c8ac
7 changed files with 102 additions and 338 deletions
@@ -10,10 +10,12 @@ import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
/**
* @author Hellohao
@@ -139,11 +141,16 @@ public class SubjectFilter extends BasicHttpAuthenticationFilter {
info = "用户未找到";
}
System.err.println("拦截器False-"+info);
response.setContentType("application/json;charset=UTF-8");
final JSONObject jsonObject = new JSONObject();
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
httpServletResponse.setCharacterEncoding("UTF-8");
httpServletResponse.setContentType("application/json");
PrintWriter writer = httpServletResponse.getWriter();
JSONObject jsonObject = new JSONObject();
jsonObject.put("code",this.CODE);
jsonObject.put("info",info);
response.getWriter().write(jsonObject.toJSONString());
writer.write(jsonObject.toJSONString());
writer.flush();
} catch (Exception e) {
System.out.println("返回token验证失败403请求,报异常了");
}
@@ -31,6 +31,7 @@ public class ShiroConfig {
filterMap.put("/verifyCode","anon");
filterMap.put("/verifyCodeForRegister","anon");
filterMap.put("/verifyCodeForRetrieve","anon");
filterMap.put("/verifyCodeFortowSendEmail","anon");
filterMap.put("/api/**","anon");
filterMap.put("/user/**","anon");
filterMap.put("/ota/**","anon");
@@ -47,7 +47,7 @@ public class IndexController {
@RequestMapping(value = "/")
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
model.addAttribute("name", "服务端程序(开源版)");
model.addAttribute("version", "20230622");
model.addAttribute("version", "20230918");
model.addAttribute("ip", GetIPS.getIpAddr(httpServletRequest));
model.addAttribute("links", "https://github.com/Hello-hao/tbed");
return "welcome";
@@ -320,6 +320,29 @@ public class IndexController {
}
}
@PostMapping(value = {"/verifyCodeFortowSendEmail","/wechat/verifyCodeFortowSendEmail"})
@ResponseBody
public Msg verifyCodeFortowSendEmail() {
Msg msg = new Msg();
try {
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(90, 35, 2, 2);
// 自定义验证码内容为四则运算方式
captcha.setGenerator(new MathGenerator(1));
String code = getVerifyCodeOperator(captcha.getCode());
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
iRedisService.setValue("verifyCodeFortowSendEmail_"+uid,code);
JSONObject jsonObject = new JSONObject();
jsonObject.put("codeKey",uid);
jsonObject.put("codeImg",captcha.getImageBase64());
msg.setData(jsonObject);
return msg;
} catch (Exception e) {
e.printStackTrace();
msg.setCode("500");
return msg;
}
}
public static String getVerifyCodeOperator(String str) {
int a = Integer.valueOf(str.substring(0, 1));
String yxf = str.substring(1, 2);
@@ -16,6 +16,8 @@ import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -44,6 +46,7 @@ public class UserController {
private SysConfigService sysConfigService;
@Autowired
IRedisService iRedisService;
private Logger logger = LoggerFactory.getLogger(UserController.class);
@PostMapping("/register")
@ResponseBody
@@ -143,6 +146,57 @@ public class UserController {
return msg;
}
@PostMapping(value = {"/validateEmail","/wechat/validateEmail"})
@ResponseBody
public Msg validateEmail(HttpServletRequest httpServletRequest,@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
try {
JSONObject jsonObj = JSONObject.parseObject(data);
String email = jsonObj.getString("email");
String towSendEmailCode = jsonObj.getString("towSendEmailCode");
Object verifyCodeFortowSendEmail =iRedisService.getValue("verifyCodeFortowSendEmail_"+httpServletRequest.getHeader("verifyCodeFortowSendEmail"));
User u = new User();
u.setEmail(email);
User user = userService.getUsers(u);
if(user.getIsok()!=0){
msg.setInfo("不知细叶谁裁出,二月春风似剪刀");
return msg;
}
if(null==verifyCodeFortowSendEmail){
msg.setCode("4035");
msg.setInfo("验证码已失效,请重新弄获取。");
return msg;
}else if(null==towSendEmailCode){
msg.setCode("4036");
msg.setInfo("验证码不能为空。");
return msg;
}
if((verifyCodeFortowSendEmail.toString().toLowerCase()).compareTo((towSendEmailCode.toLowerCase()))==0){
//注册完发激活链接
final Confdata dataJson = confdataService.selectConfdata("config");
JSONObject confdata = JSONObject.parseObject(dataJson.getJsondata());
EmailConfig emailConfig = emailConfigService.getemail();
Thread thread = new Thread() {
public void run() {
Integer a = NewSendEmail.sendEmail(emailConfig,user.getUsername(), user.getUid(), user.getEmail(),confdata);
}
};
thread.start();
msg.setInfo("邮件已发送,请注意查收邮箱尽快激活账户(如果没收到,请检查垃圾邮件)");
}else{
msg.setCode("110408");
msg.setInfo("验证码不正确");
return msg;
}
}catch (Exception e){
logger.error("报错位置:/validateEmail",e);
msg.setCode("500");
msg.setInfo("邮件发送失败");
}
return msg;
}
@PostMapping("/login")//new
@ResponseBody
public Msg login(HttpServletRequest httpServletRequest,@RequestParam(value = "data", defaultValue = "") String data) {
@@ -184,7 +238,8 @@ public class UserController {
User user = (User) SecurityUtils.getSubject().getPrincipal();
if(user.getIsok()==0){
msg.setInfo("你的账号暂未激活");
msg.setCode("110403");
msg.setData(user.getEmail());
msg.setCode("110402");
return msg;
}
if(user.getIsok()<0){
-322
View File
@@ -4,8 +4,6 @@ import lombok.Data;
@Data
public class Images {
// 默认的时间字符串格式
//id, imgname, imgurl, userid
private Long id;
private String imgname;
@@ -42,326 +40,6 @@ public class Images {
private Integer isRepeat;//如果没有开启查重的时候他是0,开启为1
private String searchname;
private String order;
//
// public Images() {
// super();
// }
//
// public Images(String imgurl, String sizes, String abnormal, String updatetime, String username, String md5key, String imguid) {
// this.imgurl = imgurl;
// this.sizes = sizes;
// this.abnormal = abnormal;
// this.updatetime = updatetime;
// this.username = username;
// this.md5key = md5key;
// this.imguid = imguid;
// }
//
// public Images(Long id, String imgname, String imgurl, Integer userid, String sizes, String abnormal, Integer source,
// Integer imgtype, String updatetime, String username, Integer storageType, String starttime, String stoptime,
// String explains, String md5key, String notes, String useridlist, String imguid, String albumtitle,
// String password, Integer selecttype,Long countNum,Integer monthNum,String yyyy,
// String format,String about,Integer great,String[] classifuidlist,String classificationuid,String violation,
// String idname,Integer isRepeat,String searchname) {
// this.id = id;
// this.imgname = imgname;
// this.imgurl = imgurl;
// this.userid = userid;
// this.sizes = sizes;
// this.abnormal = abnormal;
// this.source = source;
// this.imgtype = imgtype;
// this.updatetime = updatetime;
// this.username = username;
// this.storageType = storageType;
// this.starttime = starttime;
// this.stoptime = stoptime;
// this.explains = explains;
// this.md5key = md5key;
// this.notes = notes;
// this.useridlist = useridlist;
// this.imguid = imguid;
// this.albumtitle = albumtitle;
// this.password = password;
// this.selecttype = selecttype;
// this.countNum = countNum;
// this.monthNum = monthNum;
// this.yyyy = yyyy;
// this.format = format;
// this.about = about;
// this.great = great;
// this.classifuidlist = classifuidlist;
// this.classificationuid = classificationuid;
// this.violation = violation;
// this.idname = idname;
// this.isRepeat = isRepeat;
// this.searchname = searchname;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getImgname() {
// return imgname;
// }
//
// public void setImgname(String imgname) {
// this.imgname = imgname;
// }
//
// public String getImgurl() {
// return imgurl;
// }
//
// public void setImgurl(String imgurl) {
// this.imgurl = imgurl;
// }
//
// public Integer getUserid() {
// return userid;
// }
//
// public void setUserid(Integer userid) {
// this.userid = userid;
// }
//
// public String getSizes() {
// return sizes;
// }
//
// public void setSizes(String sizes) {
// this.sizes = sizes;
// }
//
// public String getAbnormal() {
// return abnormal;
// }
//
// public void setAbnormal(String abnormal) {
// this.abnormal = abnormal;
// }
//
// public Integer getSource() {
// return source;
// }
//
// public void setSource(Integer source) {
// this.source = source;
// }
//
// public Integer getImgtype() {
// return imgtype;
// }
//
// public void setImgtype(Integer imgtype) {
// this.imgtype = imgtype;
// }
//
// public String getUpdatetime() {
// return updatetime;
// }
//
// public void setUpdatetime(String updatetime) {
// this.updatetime = updatetime;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public Integer getStorageType() {
// return storageType;
// }
//
// public void setStorageType(Integer storageType) {
// this.storageType = storageType;
// }
//
// public String getStarttime() {
// return starttime;
// }
//
// public void setStarttime(String starttime) {
// this.starttime = starttime;
// }
//
// public String getStoptime() {
// return stoptime;
// }
//
// public void setStoptime(String stoptime) {
// this.stoptime = stoptime;
// }
//
// public String getExplains() {
// return explains;
// }
//
// public void setExplains(String explains) {
// this.explains = explains;
// }
//
// public String getMd5key() {
// return md5key;
// }
//
// public void setMd5key(String md5key) {
// this.md5key = md5key;
// }
//
// public String getNotes() {
// return notes;
// }
//
// public void setNotes(String notes) {
// this.notes = notes;
// }
//
// public String getUseridlist() {
// return useridlist;
// }
//
// public void setUseridlist(String useridlist) {
// this.useridlist = useridlist;
// }
//
// public String getImguid() {
// return imguid;
// }
//
// public void setImguid(String imguid) {
// this.imguid = imguid;
// }
//
//
// public String getAlbumtitle() {
// return albumtitle;
// }
//
// public void setAlbumtitle(String albumtitle) {
// this.albumtitle = albumtitle;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public Integer getSelecttype() {
// return selecttype;
// }
//
// public void setSelecttype(Integer selecttype) {
// this.selecttype = selecttype;
// }
//
// public Long getCountNum() {
// return countNum;
// }
//
// public void setCountNum(Long countNum) {
// this.countNum = countNum;
// }
//
// public Integer getMonthNum() {
// return monthNum;
// }
//
// public void setMonthNum(Integer monthNum) {
// this.monthNum = monthNum;
// }
//
// public String getYyyy() {
// return yyyy;
// }
//
// public void setYyyy(String yyyy) {
// this.yyyy = yyyy;
// }
//
// public String getFormat() {
// return format;
// }
//
// public void setFormat(String format) {
// this.format = format;
// }
//
// public String getAbout() {
// return about;
// }
//
// public void setAbout(String about) {
// this.about = about;
// }
//
// public Integer getGreat() {
// return great;
// }
//
// public void setGreat(Integer great) {
// this.great = great;
// }
//
// public String[] getClassifuidlist() {
// return classifuidlist;
// }
//
// public void setClassifuidlist(String[] classifuidlist ) {
// this.classifuidlist = classifuidlist;
// }
//
// public String getClassificationuid() {
// return classificationuid;
// }
//
// public void setClassificationuid(String classificationuid) {
// this.classificationuid = classificationuid;
// }
//
// public String getViolation() {
// return violation;
// }
//
// public void setViolation(String violation) {
// this.violation = violation;
// }
//
// public String getIdname() {
// return idname;
// }
//
// public void setIdname(String idname) {
// this.idname = idname;
// }
//
// public Integer getIsRepeat() {
// return isRepeat;
// }
//
// public void setIsRepeat(Integer isRepeat) {
// this.isRepeat = isRepeat;
// }
//
// public String getSearchname() {
// return searchname;
// }
//
// public void setSearchname(String searchname) {
// this.searchname = searchname;
// }
}