|
@@ -2,16 +2,19 @@ package org.dromara.auth.service.impl;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
|
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
|
|
|
|
+import cn.hutool.crypto.digest.BCrypt;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.dromara.auth.domain.vo.LoginVo;
|
|
import org.dromara.auth.domain.vo.LoginVo;
|
|
|
|
|
+import org.dromara.auth.form.PasswordLoginBody;
|
|
|
import org.dromara.auth.form.SmsLoginBody;
|
|
import org.dromara.auth.form.SmsLoginBody;
|
|
|
import org.dromara.auth.service.IAuthStrategy;
|
|
import org.dromara.auth.service.IAuthStrategy;
|
|
|
import org.dromara.auth.service.SysLoginService;
|
|
import org.dromara.auth.service.SysLoginService;
|
|
|
import org.dromara.common.core.constant.Constants;
|
|
import org.dromara.common.core.constant.Constants;
|
|
|
import org.dromara.common.core.constant.GlobalConstants;
|
|
import org.dromara.common.core.constant.GlobalConstants;
|
|
|
import org.dromara.common.core.enums.LoginType;
|
|
import org.dromara.common.core.enums.LoginType;
|
|
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.exception.user.CaptchaExpireException;
|
|
import org.dromara.common.core.exception.user.CaptchaExpireException;
|
|
|
import org.dromara.common.core.utils.MessageUtils;
|
|
import org.dromara.common.core.utils.MessageUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
@@ -20,11 +23,17 @@ import org.dromara.common.json.utils.JsonUtils;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
|
|
+import org.dromara.customer.api.RemoteCustomerService;
|
|
|
|
|
+import org.dromara.customer.api.RemoteSupplierInfoService;
|
|
|
|
|
+import org.dromara.customer.api.domain.dto.CustomerInfoDTO;
|
|
|
|
|
+import org.dromara.system.api.RemoteClientService;
|
|
|
import org.dromara.system.api.RemoteUserService;
|
|
import org.dromara.system.api.RemoteUserService;
|
|
|
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
|
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
|
|
import org.dromara.system.api.model.LoginUser;
|
|
import org.dromara.system.api.model.LoginUser;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 短信认证策略
|
|
* 短信认证策略
|
|
|
*
|
|
*
|
|
@@ -37,9 +46,19 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
|
|
|
|
|
|
|
private final SysLoginService loginService;
|
|
private final SysLoginService loginService;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@DubboReference
|
|
@DubboReference
|
|
|
private RemoteUserService remoteUserService;
|
|
private RemoteUserService remoteUserService;
|
|
|
|
|
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private RemoteClientService remoteClientService;
|
|
|
|
|
+
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private RemoteCustomerService remoteCustomerService;
|
|
|
|
|
+
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private RemoteSupplierInfoService remoteSupplierInfoService;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public LoginVo login(String body, RemoteClientVo client) {
|
|
public LoginVo login(String body, RemoteClientVo client) {
|
|
|
SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
|
|
SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
|
|
@@ -80,6 +99,52 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public LoginVo clientLogin(String body, RemoteClientVo client) {
|
|
public LoginVo clientLogin(String body, RemoteClientVo client) {
|
|
|
|
|
+ SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
|
|
|
|
|
+
|
|
|
|
|
+ String tenantId = loginBody.getTenantId();
|
|
|
|
|
+ String username = loginBody.getPhonenumber();
|
|
|
|
|
+ boolean b = this.validateSmsCode(tenantId, username, loginBody.getSmsCode());
|
|
|
|
|
+ if (!b) {
|
|
|
|
|
+ throw new ServiceException("验证码错误");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
|
|
|
|
+ LoginUser user = remoteUserService.getUserInfo(username, tenantId);
|
|
|
|
|
+// if(!Objects.equals(user.getUserSonType(), "3")){
|
|
|
|
|
+// throw new ServiceException("不存在该账号");
|
|
|
|
|
+// }
|
|
|
|
|
+ return user;
|
|
|
|
|
+ });
|
|
|
|
|
+ if(Objects.equals(loginUser.getUserSonType(), "3")){
|
|
|
|
|
+ //获取客户信息
|
|
|
|
|
+ Long customerId = remoteCustomerService.selectCustomerIdByUserId(loginUser.getUserId());
|
|
|
|
|
+ if (Objects.isNull(customerId)) {
|
|
|
|
|
+ throw new ServiceException("不存在该账号");
|
|
|
|
|
+ }
|
|
|
|
|
+ CustomerInfoDTO customerInfoDTO = remoteCustomerService.selectCustomerInfoById(customerId);
|
|
|
|
|
+ if (null != customerInfoDTO && "0".equals(customerInfoDTO.getStatus())) {
|
|
|
|
|
+ throw new ServiceException("该企业当前未审核,请审核后再登录");
|
|
|
|
|
+ }
|
|
|
|
|
+ loginUser.setCustomerId(customerId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ loginUser.setClientKey(client.getClientKey());
|
|
|
|
|
+ loginUser.setDeviceType(client.getDeviceType());
|
|
|
|
|
+ SaLoginParameter model = new SaLoginParameter();
|
|
|
|
|
+ model.setDeviceType(client.getDeviceType());
|
|
|
|
|
+ // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
|
|
|
|
+ // 例如: 后台用户30分钟过期 app用户1天过期
|
|
|
|
|
+ model.setTimeout(client.getTimeout());
|
|
|
|
|
+ model.setActiveTimeout(client.getActiveTimeout());
|
|
|
|
|
+ model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
|
|
|
|
+ // 生成token
|
|
|
|
|
+ LoginHelper.login(loginUser, model);
|
|
|
|
|
+
|
|
|
|
|
+ LoginVo loginVo = new LoginVo();
|
|
|
|
|
+ loginVo.setAccessToken(StpUtil.getTokenValue());
|
|
|
|
|
+ loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
|
|
|
|
+ loginVo.setClientId(client.getClientId());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|