|
|
@ -1,11 +1,10 @@ |
|
|
|
package com.cloud.kicc.system.service.impl; |
|
|
|
package com.cloud.kicc.system.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Validator; |
|
|
|
import cn.hutool.core.lang.Validator; |
|
|
|
import cn.hutool.core.text.CharSequenceUtil; |
|
|
|
import cn.hutool.core.text.CharSequenceUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.javaer.aliyun.sms.SmsClient; |
|
|
|
import cn.javaer.aliyun.sms.SmsClient; |
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.cloud.kicc.common.core.api.R; |
|
|
|
import com.cloud.kicc.common.core.api.R; |
|
|
|
import com.cloud.kicc.common.core.constant.CacheConstants; |
|
|
|
import com.cloud.kicc.common.core.constant.CacheConstants; |
|
|
@ -22,7 +21,6 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -65,12 +63,12 @@ public class AppServiceImpl implements AppService { |
|
|
|
} |
|
|
|
} |
|
|
|
int code = smsClient.sendVerificationCode("ali-code", phone); |
|
|
|
int code = smsClient.sendVerificationCode("ali-code", phone); |
|
|
|
log.info("手机号生成验证码成功:{},{}", phone, code); |
|
|
|
log.info("手机号生成验证码成功:{},{}", phone, code); |
|
|
|
redisTemplate.opsForValue().set(CacheConstants.VERIFICATION_CODE + phone, String.valueOf(code), SecurityConstants.CODE_TIME, TimeUnit.SECONDS); |
|
|
|
redisTemplate.opsForValue().set(CacheConstants.VERIFICATION_CODE + phone, String.valueOf(code), SecurityConstants.CODE_TIME * 5, TimeUnit.SECONDS); |
|
|
|
return R.ok(Boolean.TRUE); |
|
|
|
return R.ok(Boolean.TRUE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@DSTransactional |
|
|
|
@DSTransactional |
|
|
|
public SsoUser phoneRegister(String phone, String captcha, String identityProvider, String tenantId) { |
|
|
|
public SsoUser phoneRegister(String phone, String captcha, String identityProvider) { |
|
|
|
// 设置不区分大小写,全部以小写验证
|
|
|
|
// 设置不区分大小写,全部以小写验证
|
|
|
|
Validator.validateMobile(phone, "手机号码不合法"); |
|
|
|
Validator.validateMobile(phone, "手机号码不合法"); |
|
|
|
String code = captcha.toLowerCase(); |
|
|
|
String code = captcha.toLowerCase(); |
|
|
@ -84,14 +82,6 @@ public class AppServiceImpl implements AppService { |
|
|
|
throw new ValidateCodeException("验证码不合法"); |
|
|
|
throw new ValidateCodeException("验证码不合法"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<SsoUser> findSsoUser = iSsoUserService.list(Wrappers.<SsoUser>lambdaQuery() |
|
|
|
|
|
|
|
.eq(SsoUser::getPhone, phone) |
|
|
|
|
|
|
|
.eq(SsoUser::getTenantId, tenantId) |
|
|
|
|
|
|
|
.eq(SsoUser::getIdentityProvider, identityProvider)); |
|
|
|
|
|
|
|
if (!findSsoUser.isEmpty()) { |
|
|
|
|
|
|
|
return findSsoUser.get(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 进行注册用户
|
|
|
|
// 进行注册用户
|
|
|
|
String initDeptId = configService.getValueByKey("app.init.deptId"); |
|
|
|
String initDeptId = configService.getValueByKey("app.init.deptId"); |
|
|
|
Dept dept = deptService.getById(initDeptId); |
|
|
|
Dept dept = deptService.getById(initDeptId); |
|
|
@ -101,6 +91,14 @@ public class AppServiceImpl implements AppService { |
|
|
|
String initRoleIds = configService.getValueByKey("app.init.roleIds"); |
|
|
|
String initRoleIds = configService.getValueByKey("app.init.roleIds"); |
|
|
|
String initPassword = configService.getValueByKey("appid.password"); |
|
|
|
String initPassword = configService.getValueByKey("appid.password"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<SsoUser> findSsoUser = iSsoUserService.list(Wrappers.<SsoUser>lambdaQuery() |
|
|
|
|
|
|
|
.eq(SsoUser::getPhone, phone) |
|
|
|
|
|
|
|
.eq(SsoUser::getTenantId, initTenantId) |
|
|
|
|
|
|
|
.eq(SsoUser::getIdentityProvider, identityProvider)); |
|
|
|
|
|
|
|
if (!findSsoUser.isEmpty()) { |
|
|
|
|
|
|
|
return findSsoUser.get(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 修改扩展用户信息
|
|
|
|
// 修改扩展用户信息
|
|
|
|
SsoUser ssoUser = new SsoUser(); |
|
|
|
SsoUser ssoUser = new SsoUser(); |
|
|
|
ssoUser.setUserName(phone); |
|
|
|
ssoUser.setUserName(phone); |
|
|
@ -108,6 +106,7 @@ public class AppServiceImpl implements AppService { |
|
|
|
ssoUser.setPassword(new BCryptPasswordEncoder().encode(initPassword)); |
|
|
|
ssoUser.setPassword(new BCryptPasswordEncoder().encode(initPassword)); |
|
|
|
ssoUser.setPhone(phone); |
|
|
|
ssoUser.setPhone(phone); |
|
|
|
ssoUser.setIdentityProvider(identityProvider); |
|
|
|
ssoUser.setIdentityProvider(identityProvider); |
|
|
|
|
|
|
|
ssoUser.setTenantId(initTenantId); |
|
|
|
iSsoUserService.save(ssoUser); |
|
|
|
iSsoUserService.save(ssoUser); |
|
|
|
|
|
|
|
|
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|