注册计时器
This commit is contained in:
parent
165170af97
commit
32ec34633c
@ -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 "验证码不正确";
|
||||
|
@ -5,8 +5,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface UserDao {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user