Merge remote-tracking branch 'origin/master'

This commit is contained in:
cyk
2023-12-23 16:08:26 +08:00
13 changed files with 120 additions and 26 deletions

View File

@@ -1,6 +1,5 @@
package com.lovenav.controller;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.lovenav.entity.Banners;
import com.lovenav.service.BannersService;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -1,19 +1,10 @@
package com.lovenav.controller;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.entity.Comment;
import com.lovenav.service.CommentService;
import com.lovenav.service.serviceImpl.CommentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashMap;
@RestController
@RequestMapping("/comment")

View File

@@ -10,6 +10,7 @@ import com.lovenav.utils.TokenUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@@ -23,6 +24,9 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@RestController
public class UserController {
@@ -31,15 +35,30 @@ public class UserController {
@Autowired
TokenUtils tokenUtils;
//发送邮箱验证码
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
//这个是我用户Service实现类可以自行替换
//这个是邮件类,必须要导入哦
@GetMapping("/sendActiveCode")
public String sendActiveCode(HttpSession session, User user){
String activecode=userService.sendEmailActivecode(user);
session.setAttribute(user.getUserEmail(),activecode);
scheduledExecutorService.schedule(new Runnable() {
@Override
public void run() {
session.removeAttribute(user.getUserEmail());
System.out.println(session.getAttribute(user.getUserEmail()));
}
},60, TimeUnit.SECONDS);
return "发送验证码成功!";
}
@RequestMapping("/register")
public String userRegister(HttpSession session,User user){
if (session.getAttribute(user.getUserEmail())==null){
return "验证码过期";
}
// 比较验证码
if (!user.getActiveCode().equals((String) session.getAttribute(user.getUserEmail()))) {
return "验证码不正确";