diff --git a/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java b/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java index 739c8f5..8ca2c5d 100644 --- a/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java +++ b/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java @@ -3,11 +3,15 @@ package com.msdw.tms.api; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserInfoEntity; +import com.msdw.tms.entity.vo.CheckVo; import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; @Api(value = "用户管理",tags = "用户管理") public interface UserInfoControllerApi { @@ -23,4 +27,14 @@ public interface UserInfoControllerApi { @ApiOperation(value = "个人中心-信息修改",notes = "个人中心-信息修改") R updateUser(UserProsonalEntityVo userProsonalEntityVo); + + @ApiOperation(value = "发送验证码",notes = "发送验证码") + R findPassword(@ApiParam(value = "账号",required = true) String account, + @ApiParam(value = "发送类型(1手机,2邮箱)",required = true) Integer type); + + @ApiOperation(value = "校验验证码",notes = "校验验证码") + R checkCode(@ApiParam(value = "用户id和验证码") CheckVo checkVo); + + @ApiOperation(value = "设置新密码",notes = "设置新密码") + R resetPassword(@ApiParam(value = "用户id和密码") CheckVo checkVo); } diff --git a/src/main/java/com/msdw/tms/config/CheckCodeUtils.java b/src/main/java/com/msdw/tms/config/CheckCodeUtils.java index ae4d957..03c15a9 100644 --- a/src/main/java/com/msdw/tms/config/CheckCodeUtils.java +++ b/src/main/java/com/msdw/tms/config/CheckCodeUtils.java @@ -5,6 +5,9 @@ import java.util.Calendar; import java.util.Date; import java.util.Random; +/** + * 验证码工具类 + */ public class CheckCodeUtils { /** diff --git a/src/main/java/com/msdw/tms/controller/UserInfoController.java b/src/main/java/com/msdw/tms/controller/UserInfoController.java index 9982b63..28f31ed 100644 --- a/src/main/java/com/msdw/tms/controller/UserInfoController.java +++ b/src/main/java/com/msdw/tms/controller/UserInfoController.java @@ -7,6 +7,7 @@ import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.UserPersonalFileEntity; +import com.msdw.tms.entity.vo.CheckVo; import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.service.StudentService; @@ -147,4 +148,42 @@ public class UserInfoController implements UserInfoControllerApi { return R.ok(); } } + + /** + * 找回密码---发送验证码 + * @param account + * @param type + * @return + */ + @Override + @GetMapping("/findPassword") + public R findPassword(@RequestParam String account,@RequestParam Integer type){ + R result = userInfoService.findPassword(account,type); + return R.ok(); + } + + /** + * 校验验证码 + * @param checkVo (userId 、 code) + * @return + */ + @Override + @PostMapping("/checkCode") + public R checkCode(@RequestBody CheckVo checkVo){ + R result =userInfoService.checkCode(checkVo); + return result; + } + + /** + * 设置密码 + * @param checkVo (userId 、 password) + * @return + */ + @Override + @PostMapping("/resetPassword") + public R resetPassword(@RequestBody CheckVo checkVo){ + R result = userInfoService.resetPassword(checkVo); + return result; + } + } diff --git a/src/main/java/com/msdw/tms/dao/UserInfoDao.java b/src/main/java/com/msdw/tms/dao/UserInfoDao.java index 02353c3..5ac2c26 100644 --- a/src/main/java/com/msdw/tms/dao/UserInfoDao.java +++ b/src/main/java/com/msdw/tms/dao/UserInfoDao.java @@ -3,6 +3,7 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.msdw.tms.entity.StudentEntity; import com.msdw.tms.entity.UserInfoEntity; +import com.msdw.tms.entity.vo.CheckVo; import com.msdw.tms.entity.vo.StaffVo; import com.msdw.tms.entity.vo.StudentVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo; @@ -53,4 +54,9 @@ public interface UserInfoDao extends BaseMapper { List queryEmail(String email); + List queryUser(String account); + + String checkCode(CheckVo checkVo); + + void resetPassword(CheckVo checkVo); } diff --git a/src/main/java/com/msdw/tms/entity/vo/CheckVo.java b/src/main/java/com/msdw/tms/entity/vo/CheckVo.java index 48491cb..b388ee9 100644 --- a/src/main/java/com/msdw/tms/entity/vo/CheckVo.java +++ b/src/main/java/com/msdw/tms/entity/vo/CheckVo.java @@ -25,5 +25,7 @@ public class CheckVo { // private String emailAddress; //用户设置的新手机号 // private String mobile; + //密码 + private String password; } diff --git a/src/main/java/com/msdw/tms/service/UserInfoService.java b/src/main/java/com/msdw/tms/service/UserInfoService.java index 98dd39d..c4323ff 100644 --- a/src/main/java/com/msdw/tms/service/UserInfoService.java +++ b/src/main/java/com/msdw/tms/service/UserInfoService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.UserInfoEntity; +import com.msdw.tms.entity.vo.CheckVo; import com.msdw.tms.entity.vo.StudentVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo; @@ -34,4 +35,10 @@ public interface UserInfoService extends IService { HashMap queryUserInfo(Integer id); void updateAccount(Integer userId); + + R findPassword(String account,Integer type); + + R checkCode(CheckVo checkVo); + + R resetPassword(CheckVo checkVo); } diff --git a/src/main/java/com/msdw/tms/service/UserService.java b/src/main/java/com/msdw/tms/service/UserService.java index 36f122b..4821d31 100644 --- a/src/main/java/com/msdw/tms/service/UserService.java +++ b/src/main/java/com/msdw/tms/service/UserService.java @@ -50,4 +50,5 @@ public interface UserService extends IService { //清空过期验证码 boolean cleanUp(); + } diff --git a/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java index 66ffad0..12b599a 100644 --- a/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java @@ -4,15 +4,22 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.msdw.tms.common.utils.*; +import com.msdw.tms.config.CheckCodeUtils; +import com.msdw.tms.config.EmailUtils; +import com.msdw.tms.config.SendSMS; +import com.msdw.tms.dao.UserDao; import com.msdw.tms.dao.UserInfoDao; import com.msdw.tms.entity.StudentEntity; import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.response.CommonCode; import com.msdw.tms.entity.response.ResponseResult; import com.msdw.tms.entity.response.ResultCode; +import com.msdw.tms.entity.vo.CheckVo; +import com.msdw.tms.entity.vo.StaffVo; import com.msdw.tms.entity.vo.StudentVo; 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.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,12 +27,15 @@ import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; import java.util.List; import java.util.Map; - +@Slf4j @Service("userInfoService") public class UserInfoServiceImpl extends ServiceImpl implements UserInfoService { @Autowired private UserInfoDao userInfoDao; + @Autowired + private UserDao userDao; + @Override public PageUtils queryPage(Map params) { @@ -42,8 +52,8 @@ public class UserInfoServiceImpl extends ServiceImpl vos = userInfoDao.queryUser(account); + int size = vos.size(); + UserInfoEntity entity = vos.get(0); + if (vos.size()==0){ + return R.error("账号不存在"); + }else if (vos.size()>1){ + log.info("存在多个相同账号"); + return R.error("账号异常,请联系管理员!!!"); + } + CheckCodeUtils utils = new CheckCodeUtils(); + String code = utils.sendCode(); + CheckVo checkVo = new CheckVo(); + + if (type==1){//通过手机验证 + EmailUtils.sendEmail(entity.getEmail(),code); + checkVo.setCheckCode(code).setSetTime(utils.letTimes(5)).setUserId(entity.getUserId()); + 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()); + boolean result = userDao.saveCheckPhoneCode(checkVo); + if (result) { + return R.ok().put("data",entity); + }else { + return R.error("保存验证码异常"); + } + }else { + return R.error("请求验证类型不对!!!"); + } + }catch (RuntimeException e){ + e.printStackTrace(); + return R.error("请求异常!!!"); + } + + } + + @Override + public R checkCode(CheckVo checkVo) { + String checkCode = userInfoDao.checkCode(checkVo); + if (checkCode.equals(checkVo.getCode())){ + return R.ok(); + } + return R.error(); + } + + @Override + @Transactional + public R resetPassword(CheckVo checkVo) { + userInfoDao.resetPassword(checkVo); + return R.ok(); + } } diff --git a/src/main/resources/mapper/tms/UserInfoDao.xml b/src/main/resources/mapper/tms/UserInfoDao.xml index a1ebb18..3b5d3f1 100644 --- a/src/main/resources/mapper/tms/UserInfoDao.xml +++ b/src/main/resources/mapper/tms/UserInfoDao.xml @@ -6,10 +6,10 @@ insert into hr_user_info( userName, uniqueIdentificationAccount, provinceId, - cityId, schoolId, phone,account,password,roleId,creationTime) + cityId, schoolId, phone,account,password,roleId,creationTime,token) values( #{userName}, #{uniqueIdentificationAccount}, #{provinceId}, - #{cityId}, #{schoolId},#{phone}, #{account},#{password},#{roleId},now()) + #{cityId}, #{schoolId},#{phone}, #{account},#{password},#{roleId},now(),token) @@ -207,6 +207,9 @@ u.account = '00',u.phone = null WHERE userId = #{userId} + + update hr_user_info set `password` = #{password} WHERE userId = #{userId} AND isdel = 0 + + + \ No newline at end of file