|
|
|
@ -21,12 +21,17 @@ import com.msdw.tms.entity.vo.UserProsonalEntityVo; |
|
|
|
|
import com.msdw.tms.service.UserInfoService; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
|
import org.springframework.data.redis.core.ValueOperations; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.UUID; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
@Service("userInfoService") |
|
|
|
|
public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity> implements UserInfoService { |
|
|
|
@ -36,6 +41,9 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity |
|
|
|
|
@Autowired |
|
|
|
|
private UserDao userDao; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private StringRedisTemplate stringRedisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public PageUtils queryPage(Map<String, Object> params) { |
|
|
|
@ -160,25 +168,37 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity |
|
|
|
|
CheckCodeUtils utils = new CheckCodeUtils(); |
|
|
|
|
String code = utils.sendCode(); |
|
|
|
|
CheckVo checkVo = new CheckVo(); |
|
|
|
|
String key = account+UUID.randomUUID().toString().replace("-", ""); |
|
|
|
|
|
|
|
|
|
if (type==1){//通过邮箱验证
|
|
|
|
|
EmailUtils.sendEmail(entity.getEmail(),code); |
|
|
|
|
checkVo.setCheckCode(code).setSetTime(utils.letTimes(5)).setUserId(entity.getUserId()).setTypes(1); |
|
|
|
|
boolean result = userDao.saveCheckCode(checkVo); |
|
|
|
|
if (result) { |
|
|
|
|
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue(); |
|
|
|
|
ops.set(account, code, 5*60, TimeUnit.SECONDS);//5分钟
|
|
|
|
|
return R.ok().put("data",entity); |
|
|
|
|
}else { |
|
|
|
|
return R.error("保存验证码异常"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// checkVo.setCheckCode(code).setSetTime(utils.letTimes(5)).setUserId(entity.getUserId()).setTypes(1);
|
|
|
|
|
// boolean result = userDao.saveCheckCode(checkVo);
|
|
|
|
|
//
|
|
|
|
|
// if (result) {
|
|
|
|
|
// return R.ok().put("data",entity);
|
|
|
|
|
// }else {
|
|
|
|
|
// return R.error("保存验证码异常");
|
|
|
|
|
// }
|
|
|
|
|
}else if (type==2){//通过手机验证
|
|
|
|
|
SendSMS.sendCode(entity.getPhone(),code); |
|
|
|
|
checkVo.setCheckCode(code).setSetTime(utils.letTimes(5)).setUserId(entity.getUserId()).setTypes(2); |
|
|
|
|
boolean result = userDao.saveCheckPhoneCode(checkVo); |
|
|
|
|
if (result) { |
|
|
|
|
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue(); |
|
|
|
|
ops.set(account, code, 5*60, TimeUnit.SECONDS);//5分钟
|
|
|
|
|
return R.ok().put("data",entity); |
|
|
|
|
}else { |
|
|
|
|
return R.error("保存验证码异常"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// checkVo.setCheckCode(code).setSetTime(utils.letTimes(5)).setUserId(entity.getUserId()).setTypes(2);
|
|
|
|
|
// boolean result = userDao.saveCheckPhoneCode(checkVo);
|
|
|
|
|
// if (result) {
|
|
|
|
|
// return R.ok().put("data",entity);
|
|
|
|
|
// }else {
|
|
|
|
|
// return R.error("保存验证码异常");
|
|
|
|
|
// }
|
|
|
|
|
}else { |
|
|
|
|
return R.error("请求验证类型不对!!!"); |
|
|
|
|
} |
|
|
|
@ -192,10 +212,12 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity |
|
|
|
|
@Override |
|
|
|
|
public R checkCode(CheckVo checkVo) { |
|
|
|
|
|
|
|
|
|
String checkCode = userInfoDao.checkCode(checkVo); |
|
|
|
|
if (checkCode==null){ |
|
|
|
|
return R.error("验证码已过期或不存在"); |
|
|
|
|
}else if (checkCode.equals(checkVo.getCode())){ |
|
|
|
|
// String checkCode = userInfoDao.checkCode(checkVo);
|
|
|
|
|
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue(); |
|
|
|
|
String opener = ops.get(checkVo.getAccount()); |
|
|
|
|
if (opener==null){ |
|
|
|
|
return R.error("验证码已过期或不存在,请重新发送验证码"); |
|
|
|
|
}else if (opener.equals(checkVo.getCode())){ |
|
|
|
|
return R.ok(); |
|
|
|
|
}else { |
|
|
|
|
return R.error("failure"); |
|
|
|
|