feat: 记录ip逻辑修复
This commit is contained in:
@@ -149,11 +149,21 @@ public class SchisandraAuthUserController {
|
|||||||
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
||||||
schisandraAuthAddressBO.setUserId(result.getId());
|
schisandraAuthAddressBO.setUserId(result.getId());
|
||||||
schisandraAuthAddressBO.setIp(ip);
|
schisandraAuthAddressBO.setIp(ip);
|
||||||
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
if(userAgent.getBrowser() != null) {
|
||||||
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().getVersion());
|
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
||||||
|
}
|
||||||
|
if(userAgent.getBrowserVersion() != null){
|
||||||
|
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString());
|
||||||
|
}
|
||||||
schisandraAuthAddressBO.setLocation(ip2region);
|
schisandraAuthAddressBO.setLocation(ip2region);
|
||||||
Boolean add = schisandraAuthAddressDomainService.add(schisandraAuthAddressBO);
|
SchisandraAuthAddressBO authAddressBO = schisandraAuthAddressDomainService.queryByUserId(result.getId());
|
||||||
assert add;
|
if(ObjectUtils.isNotEmpty(authAddressBO)){
|
||||||
|
schisandraAuthAddressBO.setId(authAddressBO.getId());
|
||||||
|
schisandraAuthAddressDomainService.update(schisandraAuthAddressBO);
|
||||||
|
}else{
|
||||||
|
Boolean add = schisandraAuthAddressDomainService.add(schisandraAuthAddressBO);
|
||||||
|
assert add;
|
||||||
|
}
|
||||||
map.put("user", result);
|
map.put("user", result);
|
||||||
if (login != null) {
|
if (login != null) {
|
||||||
if (StpUtil.isLogin(result.getId())) {
|
if (StpUtil.isLogin(result.getId())) {
|
||||||
@@ -211,12 +221,21 @@ public class SchisandraAuthUserController {
|
|||||||
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
||||||
schisandraAuthAddressBO.setUserId(result.getId());
|
schisandraAuthAddressBO.setUserId(result.getId());
|
||||||
schisandraAuthAddressBO.setIp(ip);
|
schisandraAuthAddressBO.setIp(ip);
|
||||||
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
if(userAgent.getBrowser() != null) {
|
||||||
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().getVersion());
|
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
||||||
|
}
|
||||||
|
if(userAgent.getBrowserVersion() != null){
|
||||||
|
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString());
|
||||||
|
}
|
||||||
schisandraAuthAddressBO.setLocation(ip2region);
|
schisandraAuthAddressBO.setLocation(ip2region);
|
||||||
Boolean add = schisandraAuthAddressDomainService.add(schisandraAuthAddressBO);
|
SchisandraAuthAddressBO authAddressBO = schisandraAuthAddressDomainService.queryByUserId(result.getId());
|
||||||
assert add;
|
if(ObjectUtils.isNotEmpty(authAddressBO)){
|
||||||
|
schisandraAuthAddressBO.setId(authAddressBO.getId());
|
||||||
|
schisandraAuthAddressDomainService.update(schisandraAuthAddressBO);
|
||||||
|
}else{
|
||||||
|
Boolean add = schisandraAuthAddressDomainService.add(schisandraAuthAddressBO);
|
||||||
|
assert add;
|
||||||
|
}
|
||||||
map.put("user", result);
|
map.put("user", result);
|
||||||
if (loginByPhone != null) {
|
if (loginByPhone != null) {
|
||||||
if (StpUtil.isLogin(result.getId())) {
|
if (StpUtil.isLogin(result.getId())) {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public interface SchisandraAuthUserDomainService {
|
|||||||
* @author: landaiqing
|
* @author: landaiqing
|
||||||
* @date: 2024/5/26 17:28
|
* @date: 2024/5/26 17:28
|
||||||
*/
|
*/
|
||||||
SchisandraAuthUserBO login(SchisandraAuthUserBO schisandraAuthUserBO);
|
SchisandraAuthUserBO login(SchisandraAuthUserBO schisandraAuthUserB);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 通过手机号登录
|
* @description: 通过手机号登录
|
||||||
|
|||||||
@@ -235,10 +235,14 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean wechatRegister(String appId, String openId,String clientId, HttpServletRequest httpServletRequest) {
|
public Boolean wechatRegister(String appId, String openId,String clientId, HttpServletRequest httpServletRequest) {
|
||||||
SchisandraSocialUser socialUser = schisandraSocialUserService.selectByOpenId(openId);
|
SchisandraSocialUser socialUser = schisandraSocialUserService.selectByOpenId(appId,openId);
|
||||||
if (ObjectUtils.isNotEmpty(socialUser)) {
|
if (ObjectUtils.isNotEmpty(socialUser)) {
|
||||||
String userId = socialUser.getId();
|
String SocialUserId = socialUser.getId();
|
||||||
|
SchisandraSocialUserAuth schisandraSocialUserAuth= schisandraSocialUserAuthService.queryBySocialUserId(SocialUserId);
|
||||||
|
if(ObjectUtils.isEmpty(schisandraSocialUserAuth)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String userId = schisandraSocialUserAuth.getUserId();
|
||||||
|
|
||||||
// 加入登录IP地址
|
// 加入登录IP地址
|
||||||
String ip = IPUtil.getIp(httpServletRequest);
|
String ip = IPUtil.getIp(httpServletRequest);
|
||||||
@@ -250,8 +254,12 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
||||||
schisandraAuthAddressBO.setUserId(userId);
|
schisandraAuthAddressBO.setUserId(userId);
|
||||||
schisandraAuthAddressBO.setIp(ip);
|
schisandraAuthAddressBO.setIp(ip);
|
||||||
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
if(userAgent.getBrowser() != null) {
|
||||||
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().getVersion());
|
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
||||||
|
}
|
||||||
|
if(userAgent.getBrowserVersion() != null){
|
||||||
|
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString());
|
||||||
|
}
|
||||||
schisandraAuthAddressBO.setLocation(ip2region);
|
schisandraAuthAddressBO.setLocation(ip2region);
|
||||||
SchisandraAuthAddress schisandraAuthAddress = SchisandraAuthAddressBOConverter.INSTANCE.convertBOToEntity(schisandraAuthAddressBO);
|
SchisandraAuthAddress schisandraAuthAddress = SchisandraAuthAddressBOConverter.INSTANCE.convertBOToEntity(schisandraAuthAddressBO);
|
||||||
int insert = schisandraAuthAddressService.update(schisandraAuthAddress);
|
int insert = schisandraAuthAddressService.update(schisandraAuthAddress);
|
||||||
@@ -268,6 +276,7 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
}else{
|
}else{
|
||||||
// 插入社会用户信息表
|
// 插入社会用户信息表
|
||||||
SchisandraSocialUserBO socialUserBO = new SchisandraSocialUserBO();
|
SchisandraSocialUserBO socialUserBO = new SchisandraSocialUserBO();
|
||||||
|
socialUserBO.setUuid(appId);
|
||||||
socialUserBO.setOpenId(openId);
|
socialUserBO.setOpenId(openId);
|
||||||
SchisandraSocialUser schisandraSocialUser = SchisandraSocialUserBOConverter.INSTANCE.convertBOToEntity(socialUserBO);
|
SchisandraSocialUser schisandraSocialUser = SchisandraSocialUserBOConverter.INSTANCE.convertBOToEntity(socialUserBO);
|
||||||
int result = schisandraSocialUserService.insertSocialUser(schisandraSocialUser);
|
int result = schisandraSocialUserService.insertSocialUser(schisandraSocialUser);
|
||||||
@@ -299,8 +308,12 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
||||||
schisandraAuthAddressBO.setUserId(authUserId);
|
schisandraAuthAddressBO.setUserId(authUserId);
|
||||||
schisandraAuthAddressBO.setIp(ip);
|
schisandraAuthAddressBO.setIp(ip);
|
||||||
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
if(userAgent.getBrowser() != null) {
|
||||||
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().getVersion());
|
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
||||||
|
}
|
||||||
|
if(userAgent.getBrowserVersion() != null){
|
||||||
|
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString());
|
||||||
|
}
|
||||||
schisandraAuthAddressBO.setLocation(ip2region);
|
schisandraAuthAddressBO.setLocation(ip2region);
|
||||||
SchisandraAuthAddress schisandraAuthAddress = SchisandraAuthAddressBOConverter.INSTANCE.convertBOToEntity(schisandraAuthAddressBO);
|
SchisandraAuthAddress schisandraAuthAddress = SchisandraAuthAddressBOConverter.INSTANCE.convertBOToEntity(schisandraAuthAddressBO);
|
||||||
int insertIp = schisandraAuthAddressService.insert(schisandraAuthAddress);
|
int insertIp = schisandraAuthAddressService.insert(schisandraAuthAddress);
|
||||||
@@ -359,6 +372,12 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
AuthToken token = data.getToken();
|
AuthToken token = data.getToken();
|
||||||
SchisandraSocialUser socialUser = schisandraSocialUserService.selectByUuidAndType(uuid, type);
|
SchisandraSocialUser socialUser = schisandraSocialUserService.selectByUuidAndType(uuid, type);
|
||||||
if (ObjectUtils.isNotEmpty(socialUser)) {
|
if (ObjectUtils.isNotEmpty(socialUser)) {
|
||||||
|
|
||||||
|
SchisandraSocialUserAuth schisandraSocialUserAuth= schisandraSocialUserAuthService.queryBySocialUserId(socialUser.getId());
|
||||||
|
if(ObjectUtils.isEmpty(schisandraSocialUserAuth)){
|
||||||
|
return Result.fail();
|
||||||
|
}
|
||||||
|
String userId = schisandraSocialUserAuth.getUserId();
|
||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
SchisandraSocialUserBO socialUserBO = new SchisandraSocialUserBO();
|
SchisandraSocialUserBO socialUserBO = new SchisandraSocialUserBO();
|
||||||
socialUserBO.setAccessToken(token.getAccessToken());
|
socialUserBO.setAccessToken(token.getAccessToken());
|
||||||
@@ -383,7 +402,6 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
}
|
}
|
||||||
return Result.fail("Social User update fail");
|
return Result.fail("Social User update fail");
|
||||||
}
|
}
|
||||||
String userId = socialUser.getId();
|
|
||||||
|
|
||||||
// 加入登录IP地址
|
// 加入登录IP地址
|
||||||
String ip = IPUtil.getIp(httpServletRequest);
|
String ip = IPUtil.getIp(httpServletRequest);
|
||||||
@@ -395,8 +413,12 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
||||||
schisandraAuthAddressBO.setUserId(userId);
|
schisandraAuthAddressBO.setUserId(userId);
|
||||||
schisandraAuthAddressBO.setIp(ip);
|
schisandraAuthAddressBO.setIp(ip);
|
||||||
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
if(userAgent.getBrowser() != null) {
|
||||||
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().getVersion());
|
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
||||||
|
}
|
||||||
|
if(userAgent.getBrowserVersion() != null){
|
||||||
|
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString());
|
||||||
|
}
|
||||||
schisandraAuthAddressBO.setLocation(ip2region);
|
schisandraAuthAddressBO.setLocation(ip2region);
|
||||||
SchisandraAuthAddress schisandraAuthAddress = SchisandraAuthAddressBOConverter.INSTANCE.convertBOToEntity(schisandraAuthAddressBO);
|
SchisandraAuthAddress schisandraAuthAddress = SchisandraAuthAddressBOConverter.INSTANCE.convertBOToEntity(schisandraAuthAddressBO);
|
||||||
int insert = schisandraAuthAddressService.update(schisandraAuthAddress);
|
int insert = schisandraAuthAddressService.update(schisandraAuthAddress);
|
||||||
@@ -463,8 +485,12 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
schisandraAuthAddressBO.setAgent(userAgent.toString());
|
||||||
schisandraAuthAddressBO.setUserId(authUserId);
|
schisandraAuthAddressBO.setUserId(authUserId);
|
||||||
schisandraAuthAddressBO.setIp(ip);
|
schisandraAuthAddressBO.setIp(ip);
|
||||||
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
if(userAgent.getBrowser() != null) {
|
||||||
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().getVersion());
|
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
|
||||||
|
}
|
||||||
|
if(userAgent.getBrowserVersion() != null){
|
||||||
|
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString());
|
||||||
|
}
|
||||||
schisandraAuthAddressBO.setLocation(ip2region);
|
schisandraAuthAddressBO.setLocation(ip2region);
|
||||||
SchisandraAuthAddress schisandraAuthAddress = SchisandraAuthAddressBOConverter.INSTANCE.convertBOToEntity(schisandraAuthAddressBO);
|
SchisandraAuthAddress schisandraAuthAddress = SchisandraAuthAddressBOConverter.INSTANCE.convertBOToEntity(schisandraAuthAddressBO);
|
||||||
int insertIp = schisandraAuthAddressService.insert(schisandraAuthAddress);
|
int insertIp = schisandraAuthAddressService.insert(schisandraAuthAddress);
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ public interface SchisandraSocialUserAuthService {
|
|||||||
boolean deleteById(String id);
|
boolean deleteById(String id);
|
||||||
|
|
||||||
|
|
||||||
|
SchisandraSocialUserAuth queryBySocialUserId(String socialUserId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,5 +53,5 @@ public interface SchisandraSocialUserService {
|
|||||||
|
|
||||||
int insertSocialUser(SchisandraSocialUser schisandraSocialUser);
|
int insertSocialUser(SchisandraSocialUser schisandraSocialUser);
|
||||||
|
|
||||||
SchisandraSocialUser selectByOpenId(String openId);
|
SchisandraSocialUser selectByOpenId(String appId,String openId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package com.schisandra.auth.infra.basic.service.impl;
|
package com.schisandra.auth.infra.basic.service.impl;
|
||||||
|
|
||||||
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUserAuth;
|
|
||||||
import com.schisandra.auth.infra.basic.dao.SchisandraSocialUserAuthDao;
|
import com.schisandra.auth.infra.basic.dao.SchisandraSocialUserAuthDao;
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUserAuth;
|
||||||
|
import com.schisandra.auth.infra.basic.entity.table.SchisandraSocialUserAuthTableDef;
|
||||||
import com.schisandra.auth.infra.basic.service.SchisandraSocialUserAuthService;
|
import com.schisandra.auth.infra.basic.service.SchisandraSocialUserAuthService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表服务实现类
|
* 表服务实现类
|
||||||
*
|
*
|
||||||
* @author landaiqing
|
* @author landaiqing
|
||||||
* @since 2024-06-24 11:10:08
|
* @since 2024-06-24 11:10:08
|
||||||
@@ -49,7 +50,7 @@ public class SchisandraSocialUserAuthServiceImpl implements SchisandraSocialUser
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int update(SchisandraSocialUserAuth schisandraSocialUserAuth) {
|
public int update(SchisandraSocialUserAuth schisandraSocialUserAuth) {
|
||||||
return this.schisandraSocialUserAuthDao.update(schisandraSocialUserAuth,true);
|
return this.schisandraSocialUserAuthDao.update(schisandraSocialUserAuth, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,5 +64,10 @@ public class SchisandraSocialUserAuthServiceImpl implements SchisandraSocialUser
|
|||||||
return this.schisandraSocialUserAuthDao.deleteById(id) > 0;
|
return this.schisandraSocialUserAuthDao.deleteById(id) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraSocialUserAuth queryBySocialUserId(String socialUserId) {
|
||||||
|
return this.schisandraSocialUserAuthDao.selectOneByCondition(SchisandraSocialUserAuthTableDef.SCHISANDRA_SOCIAL_USER_AUTH.SOCIAL_USER_ID.eq(socialUserId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ public class SchisandraSocialUserServiceImpl implements SchisandraSocialUserServ
|
|||||||
* @date: 2024/6/27 下午3:05
|
* @date: 2024/6/27 下午3:05
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SchisandraSocialUser selectByOpenId(String openId) {
|
public SchisandraSocialUser selectByOpenId(String appId,String openId) {
|
||||||
return schisandraSocialUserDao.selectOneByCondition(SchisandraSocialUserTableDef.SCHISANDRA_SOCIAL_USER.OPEN_ID.eq(openId));
|
return schisandraSocialUserDao.selectOneByCondition(SchisandraSocialUserTableDef.SCHISANDRA_SOCIAL_USER.OPEN_ID.eq(openId).and(SchisandraSocialUserTableDef.SCHISANDRA_SOCIAL_USER.UUID.eq(appId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
server:
|
server:
|
||||||
port: 80
|
port: 3010
|
||||||
spring:
|
spring:
|
||||||
# redis配置
|
# redis配置
|
||||||
redis:
|
redis:
|
||||||
|
|||||||
Reference in New Issue
Block a user