|
|
|
|
@ -19,6 +19,7 @@ import org.springblade.core.redis.cache.BladeRedis; |
|
|
|
|
import org.springblade.core.secure.BladeUser; |
|
|
|
|
import org.springblade.core.secure.annotation.PreAuth; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.sms.model.SmsCode; |
|
|
|
|
import org.springblade.core.tenant.annotation.NonDS; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.constant.BladeConstant; |
|
|
|
|
@ -27,12 +28,14 @@ import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.core.tool.utils.StringPool; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springblade.modules.resource.utils.SmsUtil; |
|
|
|
|
import org.springblade.modules.system.entity.User; |
|
|
|
|
import org.springblade.modules.system.excel.UserExcel; |
|
|
|
|
import org.springblade.modules.system.excel.UserImporter; |
|
|
|
|
import org.springblade.modules.system.service.IUserService; |
|
|
|
|
import org.springblade.modules.system.vo.UserVO; |
|
|
|
|
import org.springblade.modules.system.wrapper.UserWrapper; |
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
import springfox.documentation.annotations.ApiIgnore; |
|
|
|
|
@ -42,6 +45,7 @@ import javax.validation.Valid; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE; |
|
|
|
|
|
|
|
|
|
@ -60,6 +64,8 @@ public class UserController { |
|
|
|
|
private final IUserService userService; |
|
|
|
|
private final BladeRedis bladeRedis; |
|
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询单条 |
|
|
|
|
*/ |
|
|
|
|
@ -309,4 +315,54 @@ public class UserController { |
|
|
|
|
return R.data(users); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 发送注册短信验证码 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@PostMapping("/regist/sendSmsCode") |
|
|
|
|
@ApiOperation(value = "发送注册短信验证码", notes = "传入手机号") |
|
|
|
|
public R sendSmsCode(@ApiParam(value = "手机号", required = true) String phone) { |
|
|
|
|
// 生成code
|
|
|
|
|
String code = SmsUtil.getValidateParams().get(SmsUtil.PARAM_KEY); |
|
|
|
|
|
|
|
|
|
// 发送短信
|
|
|
|
|
SmsCode smsCode = SmsUtil.sendValidate(code, phone); |
|
|
|
|
if (smsCode.isSuccess()) { |
|
|
|
|
String redisKey = UserCache.USER_REGISTER_CODE + phone; |
|
|
|
|
// 缓存设置60s有效
|
|
|
|
|
redisTemplate.opsForValue().set(redisKey, smsCode, 60, TimeUnit.SECONDS); |
|
|
|
|
|
|
|
|
|
return R.success("验证码发送成功"); |
|
|
|
|
} else { |
|
|
|
|
return R.fail("验证码发送失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 保存注册用户 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@PostMapping("/regist/saveUser") |
|
|
|
|
@ApiOperation(value = "保存注册用户", notes = "用户信息和短信验证码") |
|
|
|
|
public R saveUser(@ApiParam(value = "用户信息", required = true) @RequestBody User user, @ApiParam(value = "短信验证码", required = true) String code) { |
|
|
|
|
String phone = user.getPhone(); |
|
|
|
|
if (StringUtil.isBlank(phone)) { |
|
|
|
|
return R.fail("手机号为空"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 从缓存中获取验证码
|
|
|
|
|
String redisKey = UserCache.USER_REGISTER_CODE + phone; |
|
|
|
|
SmsCode smsCode = (SmsCode) redisTemplate.opsForValue().get(redisKey); |
|
|
|
|
|
|
|
|
|
// 判断验证码是否正确
|
|
|
|
|
if (!SmsUtil.validateMessage(code, smsCode.getId(), smsCode.getValue(), smsCode.getPhone())) { |
|
|
|
|
return R.fail("验证码错误"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
userService.save(user); |
|
|
|
|
|
|
|
|
|
return R.data(user, "注册成功"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|