pull/1121/head
parent
618ffde9e4
commit
2c12d52897
|
|
@ -57,9 +57,9 @@ public class CaptchaController {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
||||||
ajax.put("captchaEnabled", captchaEnabled);
|
ajax.put("captchaEnabled", captchaEnabled);
|
||||||
if (!captchaEnabled) {
|
// if (!captchaEnabled) {
|
||||||
return ajax;
|
// return ajax;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 保存验证码信息
|
// 保存验证码信息
|
||||||
String uuid = IdUtils.simpleUUID();
|
String uuid = IdUtils.simpleUUID();
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,16 @@ public class SysLoginController {
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "修改密码(忘记密码)")
|
||||||
|
@PostMapping("/changePassword")
|
||||||
|
public R changePassword(@Validated @RequestBody PasswordChangeVO vo) {
|
||||||
|
loginService.validateSmsVerificationCode(vo.getPhoneNumber(), vo.getCode());
|
||||||
|
UserInfo user = userService.getUserByPhoneNumber(vo.getPhoneNumber());
|
||||||
|
userService.resetPassword(user.getUserId(), vo.getNewPassword());
|
||||||
|
tokenService.deleteCacheUser(user.getUserId());
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
package com.ruoyi.web.controller.system;
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.BooleanUtil;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.domain.model.ESystemRole;
|
import com.ruoyi.common.core.domain.model.ESystemRole;
|
||||||
import com.ruoyi.common.core.domain.model.RegisterBody;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.framework.web.service.SysLoginService;
|
||||||
import com.ruoyi.framework.web.service.SysRegisterService;
|
import com.ruoyi.framework.web.service.SysRegisterService;
|
||||||
import com.ruoyi.system.service.ISysConfigService;
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
import com.ruoyi.web.controller.system.vo.LoginSmsReqVO;
|
import com.ruoyi.web.controller.system.vo.LoginSmsReqVO;
|
||||||
|
|
@ -35,9 +36,13 @@ public class SysRegisterController extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysConfigService configService;
|
private ISysConfigService configService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLoginService loginService;
|
||||||
|
|
||||||
@ApiOperation(value = "档口供应商注册")
|
@ApiOperation(value = "档口供应商注册")
|
||||||
@PostMapping("/registerStore")
|
@PostMapping("/registerStore")
|
||||||
public AjaxResult registerStore(@Validated @RequestBody RegisterBySmsCodeVO vo) {
|
public AjaxResult registerStore(@Validated @RequestBody RegisterBySmsCodeVO vo) {
|
||||||
|
checkRegisterAccess();
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
String token = registerService.registerByPhoneNumber(vo.getPhoneNumber(), vo.getPassword(), vo.getCode(),
|
String token = registerService.registerByPhoneNumber(vo.getPhoneNumber(), vo.getPassword(), vo.getCode(),
|
||||||
ESystemRole.SUPPLIER);
|
ESystemRole.SUPPLIER);
|
||||||
|
|
@ -48,6 +53,7 @@ public class SysRegisterController extends BaseController {
|
||||||
@ApiOperation(value = "电商卖家注册")
|
@ApiOperation(value = "电商卖家注册")
|
||||||
@PostMapping("/registerSeller")
|
@PostMapping("/registerSeller")
|
||||||
public AjaxResult registerSeller(@Validated @RequestBody RegisterBySmsCodeVO vo) {
|
public AjaxResult registerSeller(@Validated @RequestBody RegisterBySmsCodeVO vo) {
|
||||||
|
checkRegisterAccess();
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
String token = registerService.registerByPhoneNumber(vo.getPhoneNumber(), vo.getPassword(), vo.getCode(),
|
String token = registerService.registerByPhoneNumber(vo.getPhoneNumber(), vo.getPassword(), vo.getCode(),
|
||||||
ESystemRole.SELLER);
|
ESystemRole.SELLER);
|
||||||
|
|
@ -58,6 +64,7 @@ public class SysRegisterController extends BaseController {
|
||||||
@ApiOperation(value = "代发专员注册")
|
@ApiOperation(value = "代发专员注册")
|
||||||
@PostMapping("/registerAgent")
|
@PostMapping("/registerAgent")
|
||||||
public AjaxResult registerAgent(@Validated @RequestBody RegisterBySmsCodeVO vo) {
|
public AjaxResult registerAgent(@Validated @RequestBody RegisterBySmsCodeVO vo) {
|
||||||
|
checkRegisterAccess();
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
String token = registerService.registerByPhoneNumber(vo.getPhoneNumber(), vo.getPassword(), vo.getCode(),
|
String token = registerService.registerByPhoneNumber(vo.getPhoneNumber(), vo.getPassword(), vo.getCode(),
|
||||||
ESystemRole.AGENT);
|
ESystemRole.AGENT);
|
||||||
|
|
@ -68,16 +75,13 @@ public class SysRegisterController extends BaseController {
|
||||||
@ApiOperation(value = "发送登录短信验证码")
|
@ApiOperation(value = "发送登录短信验证码")
|
||||||
@PostMapping("/sendSmsVerificationCode")
|
@PostMapping("/sendSmsVerificationCode")
|
||||||
public R sendSmsVerificationCode(@Validated @RequestBody LoginSmsReqVO vo) {
|
public R sendSmsVerificationCode(@Validated @RequestBody LoginSmsReqVO vo) {
|
||||||
registerService.sendSmsVerificationCode(vo.getPhoneNumber(), vo.getCode(), vo.getUuid());
|
loginService.sendSmsVerificationCode(vo.getPhoneNumber(), vo.getCode(), vo.getUuid());
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/register")
|
private void checkRegisterAccess() {
|
||||||
public AjaxResult register(@RequestBody RegisterBody user) {
|
if (!BooleanUtil.toBoolean(configService.selectConfigByKey("sys.account.registerUser"))) {
|
||||||
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
|
throw new ServiceException("当前系统没有开启注册功能");
|
||||||
return error("当前系统没有开启注册功能!");
|
|
||||||
}
|
}
|
||||||
String msg = registerService.register(user);
|
|
||||||
return StringUtils.isEmpty(msg) ? success() : error(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public class LoginBySmsCodeVO {
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
|
|
||||||
@NotEmpty(message = "验证码不能为空")
|
@NotEmpty(message = "验证码不能为空")
|
||||||
@ApiModelProperty("验证码")
|
@ApiModelProperty("短信验证码")
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,12 @@ public class LoginByUsernameVO {
|
||||||
/**
|
/**
|
||||||
* 验证码
|
* 验证码
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty("验证码")
|
@ApiModelProperty("图形验证码")
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 唯一标识
|
* 唯一标识
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty("唯一标识")
|
@ApiModelProperty("图形验证码唯一标识")
|
||||||
private String uuid;
|
private String uuid;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ public class LoginSmsReqVO {
|
||||||
@ApiModelProperty("手机号")
|
@ApiModelProperty("手机号")
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
|
|
||||||
@ApiModelProperty("验证码")
|
@ApiModelProperty("图形验证码")
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
@ApiModelProperty("唯一标识")
|
@ApiModelProperty("图形验证码唯一标识")
|
||||||
private String uuid;
|
private String uuid;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.ruoyi.web.controller.system.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liangyq
|
||||||
|
* @date 2025-06-05 15:41
|
||||||
|
*/
|
||||||
|
@ApiModel
|
||||||
|
@Data
|
||||||
|
public class PasswordChangeVO {
|
||||||
|
|
||||||
|
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
|
||||||
|
@NotEmpty(message = "手机号不能为空")
|
||||||
|
@ApiModelProperty("手机号")
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
@NotEmpty(message = "短信验证码不能为空")
|
||||||
|
@ApiModelProperty("短信验证码")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@NotEmpty(message = "新密码不能为空")
|
||||||
|
@ApiModelProperty("新密码")
|
||||||
|
private String newPassword;
|
||||||
|
}
|
||||||
|
|
@ -27,6 +27,11 @@ public class CacheConstants {
|
||||||
*/
|
*/
|
||||||
public static final String SMS_LOGIN_CAPTCHA_CODE_KEY = "sms_login_captcha_codes:";
|
public static final String SMS_LOGIN_CAPTCHA_CODE_KEY = "sms_login_captcha_codes:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信验证码CD中号码
|
||||||
|
*/
|
||||||
|
public static final String SMS_CAPTCHA_CODE_CD_PHONE_NUM_KEY = "sms_captcha_code_cd_phone_nums:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 扫码登录浏览器ID
|
* 扫码登录浏览器ID
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ import com.ruoyi.system.service.ISysUserService;
|
||||||
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.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
@ -189,7 +187,7 @@ public class SysLoginService {
|
||||||
throw new CaptchaExpireException();
|
throw new CaptchaExpireException();
|
||||||
}
|
}
|
||||||
redisCache.deleteObject(verifyKey);
|
redisCache.deleteObject(verifyKey);
|
||||||
if (!code.equalsIgnoreCase(captcha)) {
|
if (!StrUtil.emptyIfNull(code).equalsIgnoreCase(captcha)) {
|
||||||
if (username != null) {
|
if (username != null) {
|
||||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
||||||
}
|
}
|
||||||
|
|
@ -247,8 +245,14 @@ public class SysLoginService {
|
||||||
* @param uuid 图形验证码uuid
|
* @param uuid 图形验证码uuid
|
||||||
*/
|
*/
|
||||||
public void sendSmsVerificationCode(String phoneNumber, String code, String uuid) {
|
public void sendSmsVerificationCode(String phoneNumber, String code, String uuid) {
|
||||||
|
String k = CacheConstants.SMS_CAPTCHA_CODE_CD_PHONE_NUM_KEY + phoneNumber;
|
||||||
|
String v = redisCache.getCacheObject(k);
|
||||||
|
if (StrUtil.isNotEmpty(v)) {
|
||||||
|
throw new ServiceException("验证码发送间隔需大于60S");
|
||||||
|
}
|
||||||
validateCaptcha(null, code, uuid);
|
validateCaptcha(null, code, uuid);
|
||||||
sendSmsVerificationCode(phoneNumber);
|
sendSmsVerificationCode(phoneNumber);
|
||||||
|
redisCache.setCacheObject(k, "1", 60, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.ruoyi.framework.web.service;
|
package com.ruoyi.framework.web.service;
|
||||||
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.ruoyi.common.constant.CacheConstants;
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
|
|
@ -14,7 +13,6 @@ import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.framework.manager.AsyncManager;
|
import com.ruoyi.framework.manager.AsyncManager;
|
||||||
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||||
import com.ruoyi.framework.sms.SmsClientWrapper;
|
|
||||||
import com.ruoyi.system.service.ISysConfigService;
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -23,7 +21,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,9 +47,6 @@ public class SysRegisterService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisCache redisCache;
|
private RedisCache redisCache;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SmsClientWrapper smsClient;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysLoginService loginService;
|
private SysLoginService loginService;
|
||||||
|
|
||||||
|
|
@ -68,7 +62,7 @@ public class SysRegisterService {
|
||||||
public String registerByPhoneNumber(String phoneNumber, String password, String smsVerificationCode,
|
public String registerByPhoneNumber(String phoneNumber, String password, String smsVerificationCode,
|
||||||
ESystemRole... roles) {
|
ESystemRole... roles) {
|
||||||
// 短信验证
|
// 短信验证
|
||||||
validateSmsVerificationCode(phoneNumber, smsVerificationCode);
|
loginService.validateSmsVerificationCode(phoneNumber, smsVerificationCode);
|
||||||
UserInfoEdit userEdit = new UserInfoEdit();
|
UserInfoEdit userEdit = new UserInfoEdit();
|
||||||
userEdit.setUserName(phoneNumber);
|
userEdit.setUserName(phoneNumber);
|
||||||
userEdit.setNickName(phoneNumber);
|
userEdit.setNickName(phoneNumber);
|
||||||
|
|
@ -97,7 +91,7 @@ public class SysRegisterService {
|
||||||
// 验证码开关
|
// 验证码开关
|
||||||
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
||||||
if (captchaEnabled) {
|
if (captchaEnabled) {
|
||||||
validateCaptcha(username, registerBody.getCode(), registerBody.getUuid());
|
validateCaptcha(registerBody.getCode(), registerBody.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isEmpty(username)) {
|
if (StringUtils.isEmpty(username)) {
|
||||||
|
|
@ -134,65 +128,20 @@ public class SysRegisterService {
|
||||||
/**
|
/**
|
||||||
* 校验验证码
|
* 校验验证码
|
||||||
*
|
*
|
||||||
* @param username 用户名
|
* @param code 验证码
|
||||||
* @param code 验证码
|
* @param uuid 唯一标识
|
||||||
* @param uuid 唯一标识
|
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public void validateCaptcha(String username, String code, String uuid) {
|
public void validateCaptcha(String code, String uuid) {
|
||||||
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
|
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
|
||||||
String captcha = redisCache.getCacheObject(verifyKey);
|
String captcha = redisCache.getCacheObject(verifyKey);
|
||||||
redisCache.deleteObject(verifyKey);
|
redisCache.deleteObject(verifyKey);
|
||||||
if (captcha == null) {
|
if (captcha == null) {
|
||||||
throw new CaptchaExpireException();
|
throw new CaptchaExpireException();
|
||||||
}
|
}
|
||||||
if (!code.equalsIgnoreCase(captcha)) {
|
if (!StrUtil.emptyIfNull(code).equalsIgnoreCase(captcha)) {
|
||||||
throw new CaptchaException();
|
throw new CaptchaException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送登录/注册短信验证码
|
|
||||||
*
|
|
||||||
* @param phoneNumber 电话号码
|
|
||||||
* @param code 图形验证码code
|
|
||||||
* @param uuid 图形验证码uuid
|
|
||||||
*/
|
|
||||||
public void sendSmsVerificationCode(String phoneNumber, String code, String uuid) {
|
|
||||||
validateCaptcha(null, code, uuid);
|
|
||||||
sendSmsVerificationCode(phoneNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送登录/注册短信验证码
|
|
||||||
*
|
|
||||||
* @param phoneNumber 电话号码
|
|
||||||
*/
|
|
||||||
public void sendSmsVerificationCode(String phoneNumber) {
|
|
||||||
String code = RandomUtil.randomNumbers(6);
|
|
||||||
boolean success = smsClient.sendVerificationCode(phoneNumber, code);
|
|
||||||
if (success) {
|
|
||||||
String rk = CacheConstants.SMS_LOGIN_CAPTCHA_CODE_KEY + phoneNumber;
|
|
||||||
redisCache.setCacheObject(rk, code, 5, TimeUnit.MINUTES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证登录/注册短信验证码
|
|
||||||
*
|
|
||||||
* @param phoneNumber 电话号码
|
|
||||||
* @param code 验证码
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public void validateSmsVerificationCode(String phoneNumber, String code) {
|
|
||||||
String rk = CacheConstants.SMS_LOGIN_CAPTCHA_CODE_KEY + phoneNumber;
|
|
||||||
String cacheCode = redisCache.getCacheObject(rk);
|
|
||||||
if (cacheCode == null) {
|
|
||||||
throw new CaptchaExpireException();
|
|
||||||
}
|
|
||||||
redisCache.deleteObject(rk);
|
|
||||||
if (!StrUtil.equals(cacheCode, code)) {
|
|
||||||
throw new CaptchaException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue