忘记密码

hehai
mzh820631607 4 years ago
parent 04314fcb8c
commit f466eba1d8
  1. 1
      src/main/java/com/msdw/tms/api/UserInfoControllerApi.java
  2. 6
      src/main/java/com/msdw/tms/controller/EvaluationRecordController.java
  3. 4
      src/main/java/com/msdw/tms/controller/UserInfoController.java
  4. 2
      src/main/java/com/msdw/tms/dao/FractionEntityDao.java
  5. 8
      src/main/java/com/msdw/tms/entity/vo/CheckVo.java
  6. 2
      src/main/java/com/msdw/tms/service/FractionEntityService.java
  7. 4
      src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java
  8. 54
      src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java
  9. 2
      src/main/resources/mapper/tms/FractionEntityDao.xml

@ -33,6 +33,7 @@ public interface UserInfoControllerApi {
@ApiParam(value = "发送类型(1邮箱,2手机)",required = true) Integer type); @ApiParam(value = "发送类型(1邮箱,2手机)",required = true) Integer type);
@ApiOperation(value = "校验验证码",notes = "校验验证码") @ApiOperation(value = "校验验证码",notes = "校验验证码")
// R checkCode(@ApiParam(value = "用户id和验证码") String code,@ApiParam(value = "用户id和验证码")String opener);
R checkCode(@ApiParam(value = "用户id和验证码") CheckVo checkVo); R checkCode(@ApiParam(value = "用户id和验证码") CheckVo checkVo);
@ApiOperation(value = "设置新密码",notes = "设置新密码") @ApiOperation(value = "设置新密码",notes = "设置新密码")

@ -130,7 +130,8 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi
@Override @Override
@GetMapping("/openExercise") @GetMapping("/openExercise")
public R isOpenExercise(Integer userId){ public R isOpenExercise(Integer userId){
Integer id = fractionEntityService.queryScore(userId); Integer type = 2;
Integer id = fractionEntityService.queryScore(userId,type);
if (id>0){ if (id>0){
Integer score = fractionEntityService.queryExerciseRecord(userId); Integer score = fractionEntityService.queryExerciseRecord(userId);
if (score>=60){ if (score>=60){
@ -147,7 +148,8 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi
@Override @Override
@GetMapping("/openTeaching") @GetMapping("/openTeaching")
public R isOpenTeaching(Integer userId){ public R isOpenTeaching(Integer userId){
Integer id = fractionEntityService.queryScore(userId); Integer type = 3;
Integer id = fractionEntityService.queryScore(userId,type);
if (id>0){ if (id>0){
Integer score = fractionEntityService.queryTeachingRecord(userId); Integer score = fractionEntityService.queryTeachingRecord(userId);
if (score>=60){ if (score>=60){

@ -158,12 +158,12 @@ public class UserInfoController implements UserInfoControllerApi {
@GetMapping("/findPassword") @GetMapping("/findPassword")
public R findPassword(@RequestParam String account,@RequestParam Integer type){ public R findPassword(@RequestParam String account,@RequestParam Integer type){
R result = userInfoService.findPassword(account,type); R result = userInfoService.findPassword(account,type);
return R.ok(); return result;
} }
/** /**
* 校验验证码 * 校验验证码
* @param checkVo userId code * @param checkVo opener code
* @return * @return
*/ */
@Override @Override

@ -12,5 +12,5 @@ public interface FractionEntityDao {
Integer queryTeachingRecord(Integer userId); Integer queryTeachingRecord(Integer userId);
Integer queryScore( Integer userId); Integer queryScore( Integer userId,Integer type);
} }

@ -1,11 +1,15 @@
package com.msdw.tms.entity.vo; package com.msdw.tms.entity.vo;
import io.swagger.annotations.ApiParam;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.io.Serializable;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class CheckVo { public class CheckVo implements Serializable {
private static final long serialVersionUID = 1L;
//用户id //用户id
private Integer userId; private Integer userId;
//用户的邮箱地址 //用户的邮箱地址
@ -27,5 +31,7 @@ public class CheckVo {
// private String mobile; // private String mobile;
//密码 //密码
private String password; private String password;
@ApiParam(value = "用户账号")
private String account;
} }

@ -10,5 +10,5 @@ public interface FractionEntityService {
Integer queryTeachingRecord(Integer userId); Integer queryTeachingRecord(Integer userId);
Integer queryScore(Integer userId); Integer queryScore(Integer userId,Integer type);
} }

@ -33,8 +33,8 @@ public class FractionEntityServiceImpl implements FractionEntityService {
} }
@Override @Override
public Integer queryScore(Integer userId){ public Integer queryScore(Integer userId,Integer type){
Integer id = fractionMapper.queryScore(userId); Integer id = fractionMapper.queryScore(userId,type);
return id; return id;
} }
} }

@ -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 {
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 { }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");

@ -15,6 +15,6 @@
</select> </select>
<select id="queryScore" resultType="int"> <select id="queryScore" resultType="int">
SELECT count(userId) FROM tms_evaluation_fraction WHERE userId = #{userId} SELECT count(userId) FROM tms_evaluation_fraction WHERE userId = #{userId} AND types = #{type}
</select> </select>
</mapper> </mapper>
Loading…
Cancel
Save