注册---token

hehai
mzh820631607 4 years ago
parent 8048632ec5
commit 178d6f39c3
  1. 14
      src/main/java/com/msdw/tms/api/UserInfoControllerApi.java
  2. 3
      src/main/java/com/msdw/tms/config/CheckCodeUtils.java
  3. 39
      src/main/java/com/msdw/tms/controller/UserInfoController.java
  4. 6
      src/main/java/com/msdw/tms/dao/UserInfoDao.java
  5. 2
      src/main/java/com/msdw/tms/entity/vo/CheckVo.java
  6. 7
      src/main/java/com/msdw/tms/service/UserInfoService.java
  7. 1
      src/main/java/com/msdw/tms/service/UserService.java
  8. 77
      src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java
  9. 15
      src/main/resources/mapper/tms/UserInfoDao.xml

@ -3,11 +3,15 @@ package com.msdw.tms.api;
import com.msdw.tms.common.utils.R; import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserEntity;
import com.msdw.tms.entity.UserInfoEntity; 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.UserEntityVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@Api(value = "用户管理",tags = "用户管理") @Api(value = "用户管理",tags = "用户管理")
public interface UserInfoControllerApi { public interface UserInfoControllerApi {
@ -23,4 +27,14 @@ public interface UserInfoControllerApi {
@ApiOperation(value = "个人中心-信息修改",notes = "个人中心-信息修改") @ApiOperation(value = "个人中心-信息修改",notes = "个人中心-信息修改")
R updateUser(UserProsonalEntityVo userProsonalEntityVo); 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);
} }

@ -5,6 +5,9 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Random; import java.util.Random;
/**
* 验证码工具类
*/
public class CheckCodeUtils { public class CheckCodeUtils {
/** /**

@ -7,6 +7,7 @@ import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserEntity;
import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.UserInfoEntity;
import com.msdw.tms.entity.UserPersonalFileEntity; 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.UserEntityVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
import com.msdw.tms.service.StudentService; import com.msdw.tms.service.StudentService;
@ -147,4 +148,42 @@ public class UserInfoController implements UserInfoControllerApi {
return R.ok(); 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;
}
} }

@ -3,6 +3,7 @@ package com.msdw.tms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.msdw.tms.entity.StudentEntity; import com.msdw.tms.entity.StudentEntity;
import com.msdw.tms.entity.UserInfoEntity; 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.StaffVo;
import com.msdw.tms.entity.vo.StudentVo; import com.msdw.tms.entity.vo.StudentVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
@ -53,4 +54,9 @@ public interface UserInfoDao extends BaseMapper<UserInfoEntity> {
List<Integer> queryEmail(String email); List<Integer> queryEmail(String email);
List<UserInfoEntity> queryUser(String account);
String checkCode(CheckVo checkVo);
void resetPassword(CheckVo checkVo);
} }

@ -25,5 +25,7 @@ public class CheckVo {
// private String emailAddress; // private String emailAddress;
//用户设置的新手机号 //用户设置的新手机号
// private String mobile; // private String mobile;
//密码
private String password;
} }

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.R; import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.UserInfoEntity; 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.StudentVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
@ -34,4 +35,10 @@ public interface UserInfoService extends IService<UserInfoEntity> {
HashMap<String, UserProsonalEntityVo> queryUserInfo(Integer id); HashMap<String, UserProsonalEntityVo> queryUserInfo(Integer id);
void updateAccount(Integer userId); void updateAccount(Integer userId);
R findPassword(String account,Integer type);
R checkCode(CheckVo checkVo);
R resetPassword(CheckVo checkVo);
} }

@ -50,4 +50,5 @@ public interface UserService extends IService<UserEntity> {
//清空过期验证码 //清空过期验证码
boolean cleanUp(); boolean cleanUp();
} }

@ -4,15 +4,22 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msdw.tms.common.utils.*; 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.dao.UserInfoDao;
import com.msdw.tms.entity.StudentEntity; import com.msdw.tms.entity.StudentEntity;
import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.UserInfoEntity;
import com.msdw.tms.entity.response.CommonCode; import com.msdw.tms.entity.response.CommonCode;
import com.msdw.tms.entity.response.ResponseResult; import com.msdw.tms.entity.response.ResponseResult;
import com.msdw.tms.entity.response.ResultCode; 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.StudentVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -20,12 +27,15 @@ 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;
@Slf4j
@Service("userInfoService") @Service("userInfoService")
public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity> implements UserInfoService { public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity> implements UserInfoService {
@Autowired @Autowired
private UserInfoDao userInfoDao; private UserInfoDao userInfoDao;
@Autowired
private UserDao userDao;
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
@ -42,8 +52,8 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity
public int add(UserInfoEntity userInfoEntity) { public int add(UserInfoEntity userInfoEntity) {
UserInfoDao userDao = this.getBaseMapper(); UserInfoDao userDao = this.getBaseMapper();
userInfoEntity.setToken(new ConstantUtils().token); userInfoEntity.setToken(new ConstantUtils().token);
int userId = userDao.add(userInfoEntity); int userId = userDao.add(userInfoEntity);
return userId; return userId;
} }
@ -133,4 +143,65 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity
public void updateAccount( Integer userId) { public void updateAccount( Integer userId) {
userInfoDao.setNUM(userId); userInfoDao.setNUM(userId);
} }
@Override
@Transactional
public R findPassword(String account,Integer type) {
try {
List<UserInfoEntity> 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();
}
} }

@ -6,10 +6,10 @@
<insert id="add" useGeneratedKeys="true" keyProperty="userId" keyColumn="userId"> <insert id="add" useGeneratedKeys="true" keyProperty="userId" keyColumn="userId">
insert into hr_user_info( insert into hr_user_info(
userName, uniqueIdentificationAccount, provinceId, userName, uniqueIdentificationAccount, provinceId,
cityId, schoolId, phone,account,password,roleId,creationTime) cityId, schoolId, phone,account,password,roleId,creationTime,token)
values( values(
#{userName}, #{uniqueIdentificationAccount}, #{provinceId}, #{userName}, #{uniqueIdentificationAccount}, #{provinceId},
#{cityId}, #{schoolId},#{phone}, #{account},#{password},#{roleId},now()) #{cityId}, #{schoolId},#{phone}, #{account},#{password},#{roleId},now(),token)
</insert> </insert>
<update id="userInfupdateUserInfoById" parameterType="com.msdw.tms.entity.UserInfoEntity"> <update id="userInfupdateUserInfoById" parameterType="com.msdw.tms.entity.UserInfoEntity">
@ -207,6 +207,9 @@
u.account = '00',u.phone = null u.account = '00',u.phone = null
WHERE userId = #{userId} WHERE userId = #{userId}
</update> </update>
<update id="resetPassword">
update hr_user_info set `password` = #{password} WHERE userId = #{userId} AND isdel = 0
</update>
<select id="queryPersonalFileES" parameterType="com.msdw.tms.entity.UserPersonalFileEntity" <select id="queryPersonalFileES" parameterType="com.msdw.tms.entity.UserPersonalFileEntity"
resultType="hashMap"> resultType="hashMap">
@ -264,7 +267,13 @@
AND s.isdel = 0 AND s.isdel = 0
</select> </select>
<select id="queryEmail" resultType="java.lang.Integer"> <select id="queryEmail" resultType="java.lang.Integer">
select useId from hr_user_info where email = #{email} select useId from hr_user_info where email = #{email} AND isdel = 0
</select>
<select id="queryUser" resultType="com.msdw.tms.entity.UserInfoEntity">
select userId,email,phone from hr_user_info where account = #{account} AND isdel = 0
</select>
<select id="checkCode" resultType="java.lang.String">
SELECT checkCode FROM tms_checkcode WHERE userId = #{userId} AND setTime > now() ORDER BY id DESC LIMIT 1
</select> </select>
</mapper> </mapper>
Loading…
Cancel
Save