邮箱验证码
This commit is contained in:
@@ -3,7 +3,6 @@ package com.peanut.modules.book.controller;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
@@ -13,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.peanut.common.utils.MD5Utils;
|
||||
import com.peanut.common.utils.MailUtil;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.book.to.PageIdDto;
|
||||
@@ -26,12 +26,10 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -217,6 +215,32 @@ public class MyUserController {
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 常规注册 发送邮箱验证码
|
||||
*/
|
||||
@RequestMapping("/getMailCaptcha")
|
||||
public R getMailCaptcha(String email) throws Exception {
|
||||
//验证一分钟内是否已经发过
|
||||
String redisCode = redisTemplate.opsForValue().get("RegistEMail" + email);
|
||||
if (!StringUtils.isEmpty(redisCode)) {
|
||||
long l = Long.parseLong(redisCode.split("_")[1]);
|
||||
if (System.currentTimeMillis() - l < 60000) {
|
||||
//60s 内不能再发
|
||||
return R.error(500,"邮箱验证码频率过高,请稍后再试!");
|
||||
}
|
||||
}
|
||||
//生成随机五位数
|
||||
Random random = new Random();
|
||||
String code = random.nextInt(99999) + "";
|
||||
String timeCode = code + "_"+System.currentTimeMillis();
|
||||
//redis 缓存验证码
|
||||
redisTemplate.opsForValue().set("RegistEMail"+email,timeCode,5, TimeUnit.MINUTES);
|
||||
//发送
|
||||
MailUtil.sendMail("疯子读书邮箱验证码",code,email);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/register")
|
||||
public R register(@RequestParam("tel") String tel,
|
||||
@RequestParam("code") String code,
|
||||
@@ -298,8 +322,13 @@ public class MyUserController {
|
||||
public R login(@RequestParam("phone") String phone,
|
||||
@RequestParam("password") String password) {
|
||||
|
||||
|
||||
MyUserEntity user = userService.getBaseMapper().selectOne(new QueryWrapper<MyUserEntity>().eq("tel", phone));
|
||||
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper();
|
||||
if (phone.contains("@")) {
|
||||
wrapper.eq(MyUserEntity::getEmail,phone);
|
||||
}else {
|
||||
wrapper.eq(MyUserEntity::getTel,phone);
|
||||
}
|
||||
MyUserEntity user = userService.getBaseMapper().selectOne(wrapper);
|
||||
if (user == null) {
|
||||
return R.error(500,"用户不存在!");
|
||||
}
|
||||
@@ -616,6 +645,9 @@ public class MyUserController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// /**
|
||||
// * @Description: app微信登陆
|
||||
|
||||
Reference in New Issue
Block a user