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