|
@@ -3,7 +3,9 @@
|
|
*/
|
|
*/
|
|
package com.jeeplus.sys.controller;
|
|
package com.jeeplus.sys.controller;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
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.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -11,6 +13,7 @@ import com.google.common.collect.Lists;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
import com.jeeplus.aop.demo.annotation.DemoMode;
|
|
import com.jeeplus.aop.demo.annotation.DemoMode;
|
|
import com.jeeplus.aop.logging.annotation.ApiLog;
|
|
import com.jeeplus.aop.logging.annotation.ApiLog;
|
|
|
|
+import com.jeeplus.common.redis.RedisUtils;
|
|
import com.jeeplus.common.utils.ResponseUtil;
|
|
import com.jeeplus.common.utils.ResponseUtil;
|
|
import com.jeeplus.core.excel.ExcelOptions;
|
|
import com.jeeplus.core.excel.ExcelOptions;
|
|
import com.jeeplus.core.excel.annotation.ExportMode;
|
|
import com.jeeplus.core.excel.annotation.ExportMode;
|
|
@@ -29,6 +32,7 @@ import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -38,6 +42,7 @@ import java.io.IOException;
|
|
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.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 用户Controller
|
|
* 用户Controller
|
|
@@ -54,6 +59,9 @@ public class UserController {
|
|
@Autowired
|
|
@Autowired
|
|
private UserService userService;
|
|
private UserService userService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtils redisUtils;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据id查询用户
|
|
* 根据id查询用户
|
|
*
|
|
*
|
|
@@ -281,4 +289,154 @@ public class UserController {
|
|
return ResponseEntity.ok ( res );
|
|
return ResponseEntity.ok ( res );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通过手机号获取验证码(忘记密码)
|
|
|
|
+ * @param mobile 手机号码
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "通过手机号获取验证码(登陆)")
|
|
|
|
+ @GetMapping(value = "/getLoginPhoneCode")
|
|
|
|
+ public ResponseEntity<HashMap<String,Object>> getLoginPhoneCode(@RequestParam("mobile") String mobile) {
|
|
|
|
+ HashMap<String,Object> j = new HashMap<String,Object>();
|
|
|
|
+ //验证该手机号是否已经进行注册
|
|
|
|
+ User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobile, mobile));
|
|
|
|
+ if (ObjectUtil.isNotEmpty( user )) {
|
|
|
|
+ //生成四位随机验证码
|
|
|
|
+ String randomCode = String.valueOf((int) (Math.random() * 9000 + 1000));
|
|
|
|
+ System.out.println(randomCode);
|
|
|
|
+ redisUtils.setEx(mobile+ "loginPassword", randomCode, 300, TimeUnit.SECONDS);
|
|
|
|
+ HashMap<String,Object> result = null;
|
|
|
|
+ j.put("success",true);
|
|
|
|
+ j.put("message","短信发送成功!");
|
|
|
|
+ /*try{
|
|
|
|
+ //调用工具类返回结果
|
|
|
|
+ result = UserUtils.sendRandomCodes(mobile, randomCode);
|
|
|
|
+ String statusCode = (String) result.get("statusCode");
|
|
|
|
+ if (("000000").equals(statusCode)) {
|
|
|
|
+ j.put("success",true);
|
|
|
|
+ j.put("message","短信发送成功!");
|
|
|
|
+ //存放验证码
|
|
|
|
+ //以手机号+为key 五分钟为时效 将验证码进行短期存储
|
|
|
|
+ redisUtils.setEx(mobile+ "loginPassword", randomCode, 300, TimeUnit.SECONDS);
|
|
|
|
+ }else if(statusCode.equals("160040")){
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","手机号获取验证码次数已达每日上限!");
|
|
|
|
+ }else{
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","短信发送失败,错误代码:101,请联系管理员!");
|
|
|
|
+ j.put("ErrorXml",result);
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","短信发送失败!");
|
|
|
|
+ }*/
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","当前手机号未注册!请联系管理员");
|
|
|
|
+ }
|
|
|
|
+ return ResponseEntity.ok(j);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通过手机号获取验证码(忘记密码)
|
|
|
|
+ * @param mobile 手机号码
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "通过手机号获取验证码(忘记密码)")
|
|
|
|
+ @GetMapping(value = "/getPhoneCode")
|
|
|
|
+ public ResponseEntity<HashMap<String,Object>> getPhoneCode(@RequestParam("mobile") String mobile) {
|
|
|
|
+ HashMap<String,Object> j = new HashMap<String,Object>();
|
|
|
|
+ //验证该手机号是否已经进行注册
|
|
|
|
+ User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobile, mobile));
|
|
|
|
+ if (ObjectUtil.isNotEmpty( user )) {
|
|
|
|
+ //生成四位随机验证码
|
|
|
|
+ String randomCode = String.valueOf((int) (Math.random() * 9000 + 1000));
|
|
|
|
+
|
|
|
|
+ j.put("success",true);
|
|
|
|
+ j.put("message","短信发送成功!");
|
|
|
|
+ //存放验证码
|
|
|
|
+ //以手机号+为key 五分钟为时效 将验证码进行短期存储
|
|
|
|
+ redisUtils.setEx(mobile+ "resetPassword", randomCode, 300, TimeUnit.SECONDS);
|
|
|
|
+ HashMap<String,Object> result = null;
|
|
|
|
+ /*try{
|
|
|
|
+ //调用工具类返回结果
|
|
|
|
+ result = UserUtils.sendRandomCodes(mobile, randomCode);
|
|
|
|
+ String statusCode = (String) result.get("statusCode");
|
|
|
|
+ if (("000000").equals(statusCode)) {
|
|
|
|
+ j.put("success",true);
|
|
|
|
+ j.put("message","短信发送成功!");
|
|
|
|
+ //存放验证码
|
|
|
|
+ //以手机号+为key 五分钟为时效 将验证码进行短期存储
|
|
|
|
+ redisUtils.setEx(mobile+ "resetPassword", randomCode, 300, TimeUnit.SECONDS);
|
|
|
|
+ }else if(statusCode.equals("160040")){
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","手机号获取验证码次数已达每日上限!");
|
|
|
|
+ }else{
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","短信发送失败,错误代码:101,请联系管理员!");
|
|
|
|
+ j.put("ErrorXml",result);
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","短信发送失败!");
|
|
|
|
+ }*/
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","当前手机号未注册!请联系管理员");
|
|
|
|
+ }
|
|
|
|
+ return ResponseEntity.ok(j);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改密码
|
|
|
|
+ * @param mobile
|
|
|
|
+ * @param code
|
|
|
|
+ * @param newPassword
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @GetMapping(value = "/saveNewPassword")
|
|
|
|
+ @ApiOperation(value = "保存新密码")
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public ResponseEntity<HashMap<String,Object>> saveNewPassword(@RequestParam("mobile") String mobile,
|
|
|
|
+ @RequestParam("code") String code,
|
|
|
|
+ @RequestParam("newPassword") String newPassword) {
|
|
|
|
+ HashMap<String,Object> j = new HashMap<String,Object>();
|
|
|
|
+ // 判断当前页面输入的验证码是否与redis中存储的验证码匹配
|
|
|
|
+ String redisCode = (String) redisUtils.get(mobile + "resetPassword");
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(redisCode)) {
|
|
|
|
+ if (redisCode.equals( code )) {
|
|
|
|
+ // 进行密码修改操作
|
|
|
|
+ User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobile, mobile));
|
|
|
|
+ if (ObjectUtil.isNotEmpty( user )) {
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank( newPassword )) {
|
|
|
|
+ user.setPassword(SecurityUtils.encryptPassword ( newPassword ));
|
|
|
|
+ userService.updateById( user ); // 修改密码
|
|
|
|
+ redisUtils.delete(mobile + "resetPassword"); // 删除redis中的key
|
|
|
|
+ j.put("success",true);
|
|
|
|
+ j.put("message","密码修改成功!");
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","请输入有效密码!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","当前手机号未注册!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","验证码输入不正确!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","当前手机验证码已失效,请重新发送验证码!");
|
|
|
|
+ }
|
|
|
|
+ return ResponseEntity.ok(j);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|