add 新增 RemoteConfigService 配置服务 ;

add 新增 RemoteUserService#checkUserNameUnique 校验用户名称是否唯一 ;
update 更新 TokenController#register 校验注册配置 ;
update 更新 SysLoginService#register 增加验证码校验, 用户名唯一校验 ;
2.X
Michelle.Chung 1 year ago
parent eca76fafd0
commit 3018ea8306

@ -0,0 +1,17 @@
package org.dromara.system.api;
/**
*
*
* @author Michelle.Chung
*/
public interface RemoteConfigService {
/**
*
* @param tenantId id
* @return truefalse
*/
boolean selectRegisterEnabled(String tenantId);
}

@ -57,6 +57,14 @@ public interface RemoteUserService {
*/
XcxLoginUser getUserInfoByOpenid(String openid) throws UserException;
/**
*
*
* @param remoteUserBo
* @return
*/
boolean checkUserNameUnique(RemoteUserBo remoteUserBo);
/**
*
*

@ -26,6 +26,7 @@ import org.dromara.common.social.config.properties.SocialProperties;
import org.dromara.common.social.utils.SocialUtils;
import org.dromara.common.tenant.helper.TenantHelper;
import org.dromara.system.api.RemoteClientService;
import org.dromara.system.api.RemoteConfigService;
import org.dromara.system.api.RemoteSocialService;
import org.dromara.system.api.RemoteTenantService;
import org.dromara.system.api.domain.vo.RemoteClientVo;
@ -52,6 +53,8 @@ public class TokenController {
private final SocialProperties socialProperties;
private final SysLoginService sysLoginService;
@DubboReference
private final RemoteConfigService remoteConfigService;
@DubboReference
private final RemoteTenantService remoteTenantService;
@DubboReference
@ -142,6 +145,9 @@ public class TokenController {
*/
@PostMapping("register")
public R<Void> register(@RequestBody RegisterBody registerBody) {
if (!remoteConfigService.selectRegisterEnabled(registerBody.getTenantId())) {
return R.fail("当前系统没有开启注册功能!");
}
// 用户注册
sysLoginService.register(registerBody);
return R.ok();

@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthUser;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.auth.form.RegisterBody;
import org.dromara.auth.properties.CaptchaProperties;
import org.dromara.auth.properties.UserPasswordProperties;
import org.dromara.common.core.constant.Constants;
import org.dromara.common.core.constant.GlobalConstants;
@ -17,6 +18,8 @@ import org.dromara.common.core.constant.TenantConstants;
import org.dromara.common.core.enums.LoginType;
import org.dromara.common.core.enums.TenantStatus;
import org.dromara.common.core.enums.UserType;
import org.dromara.common.core.exception.CaptchaException;
import org.dromara.common.core.exception.user.CaptchaExpireException;
import org.dromara.common.core.exception.user.UserException;
import org.dromara.common.core.utils.MessageUtils;
import org.dromara.common.core.utils.ServletUtils;
@ -61,6 +64,8 @@ public class SysLoginService {
@Autowired
private UserPasswordProperties userPasswordProperties;
@Autowired
private final CaptchaProperties captchaProperties;
/**
*
@ -119,12 +124,22 @@ public class SysLoginService {
// 校验用户类型是否存在
String userType = UserType.getUserType(registerBody.getUserType()).getUserType();
boolean captchaEnabled = captchaProperties.getEnabled();
// 验证码开关
if (captchaEnabled) {
validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid());
}
// 注册用户信息
RemoteUserBo remoteUserBo = new RemoteUserBo();
remoteUserBo.setUserName(username);
remoteUserBo.setNickName(username);
remoteUserBo.setPassword(BCrypt.hashpw(password));
remoteUserBo.setUserType(userType);
// 校验用户名是否唯一
if (!remoteUserService.checkUserNameUnique(remoteUserBo)) {
throw new UserException("user.register.save.error", username);
}
boolean regFlag = remoteUserService.registerUserInfo(remoteUserBo);
if (!regFlag) {
throw new UserException("user.register.error");
@ -132,6 +147,27 @@ public class SysLoginService {
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
}
/**
*
*
* @param username
* @param code
* @param uuid
*/
public void validateCaptcha(String tenantId, String username, String code, String uuid) {
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, "");
String captcha = RedisUtils.getCacheObject(verifyKey);
RedisUtils.deleteObject(verifyKey);
if (captcha == null) {
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.expire"));
throw new CaptchaExpireException();
}
if (!code.equalsIgnoreCase(captcha)) {
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.error"));
throw new CaptchaException();
}
}
/**
*
*

@ -0,0 +1,29 @@
package org.dromara.system.dubbo;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.system.api.RemoteConfigService;
import org.dromara.system.service.ISysConfigService;
import org.springframework.stereotype.Service;
/**
*
*
* @author Michelle.Chung
*/
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteConfigServiceImpl implements RemoteConfigService {
private final ISysConfigService configService;
/**
*
*/
@Override
public boolean selectRegisterEnabled(String tenantId) {
return configService.selectRegisterEnabled(tenantId);
}
}

@ -143,6 +143,11 @@ public class RemoteUserServiceImpl implements RemoteUserService {
return loginUser;
}
@Override
public boolean checkUserNameUnique(RemoteUserBo remoteUserBo) {
return userService.checkUserNameUnique(MapstructUtils.convert(remoteUserBo, SysUserBo.class));
}
@Override
public Boolean registerUserInfo(RemoteUserBo remoteUserBo) throws UserException, ServiceException {
SysUserBo sysUserBo = MapstructUtils.convert(remoteUserBo, SysUserBo.class);

Loading…
Cancel
Save