feat: update
This commit is contained in:
@@ -455,4 +455,14 @@ public class SchisandraAuthUserController {
|
|||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("checkUserName")
|
||||||
|
public Result checkUserName(@RequestParam("userName") String userName) {
|
||||||
|
SchisandraAuthUserBO schisandraAuthUserBO = schisandraAuthUserDomainService.checkUserName(userName);
|
||||||
|
if (ObjectUtils.isEmpty(schisandraAuthUserBO)) {
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
return Result.fail("用户名已存在!");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
package com.schisandra.auth.common.utils;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname RandomNameUtils
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.auth.common.utils
|
||||||
|
* @Author: landaiqing
|
||||||
|
* @CreateTime: 2024-07-23 14:59
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class RandomNameUtils {
|
||||||
|
/**
|
||||||
|
* 随机获取英文+数字(用户名)
|
||||||
|
*
|
||||||
|
* @param engCode 小写英文的数量
|
||||||
|
* @param numCode 数字的数量
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String verifyUserName(int engCode, int numCode) {
|
||||||
|
//声明一个StringBuffer存储随机数
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
char[] englishCodeArray = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||||
|
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
|
||||||
|
char[] numCodeArray = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
|
||||||
|
Random random = new Random();
|
||||||
|
//获取英文
|
||||||
|
for (int i = 0; i < engCode; i++) {
|
||||||
|
char num = englishCodeArray[random.nextInt(englishCodeArray.length)];
|
||||||
|
sb.append(num);
|
||||||
|
}
|
||||||
|
//获取数字
|
||||||
|
for (int i = 0; i < numCode; i++) {
|
||||||
|
char num = numCodeArray[random.nextInt(numCodeArray.length)];
|
||||||
|
sb.append(num);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -110,5 +110,7 @@ public interface SchisandraAuthUserDomainService {
|
|||||||
SchisandraAuthUser queryByPhone(String phone);
|
SchisandraAuthUser queryByPhone(String phone);
|
||||||
|
|
||||||
Boolean wechatRegister(String appId, String openId, String clientId, HttpServletRequest httpServletRequest);
|
Boolean wechatRegister(String appId, String openId, String clientId, HttpServletRequest httpServletRequest);
|
||||||
|
|
||||||
|
SchisandraAuthUserBO checkUserName(String userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,16 +21,20 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import me.zhyd.oauth.model.AuthToken;
|
import me.zhyd.oauth.model.AuthToken;
|
||||||
import me.zhyd.oauth.model.AuthUser;
|
import me.zhyd.oauth.model.AuthUser;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.*;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.schisandra.auth.common.utils.RandomNameUtils.verifyUserName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 领域service实现了
|
* 领域service实现了
|
||||||
*
|
*
|
||||||
@@ -104,6 +108,7 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
@Override
|
@Override
|
||||||
public Boolean register(SchisandraAuthUserBO schisandraAuthUserBO) {
|
public Boolean register(SchisandraAuthUserBO schisandraAuthUserBO) {
|
||||||
SchisandraAuthUser authUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
|
SchisandraAuthUser authUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
|
||||||
|
authUser.setNickName(verifyUserName(4, 6));
|
||||||
Boolean insert = schisandraAuthUserService.insert(authUser);
|
Boolean insert = schisandraAuthUserService.insert(authUser);
|
||||||
if (insert) {
|
if (insert) {
|
||||||
SchisandraAuthUserRoleBO schisandraAuthUserRoleBO = new SchisandraAuthUserRoleBO();
|
SchisandraAuthUserRoleBO schisandraAuthUserRoleBO = new SchisandraAuthUserRoleBO();
|
||||||
@@ -356,6 +361,15 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraAuthUserBO checkUserName(String userName) {
|
||||||
|
if (StringUtils.isEmpty(userName)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SchisandraAuthUser authUser = schisandraAuthUserService.checkUserName(userName);
|
||||||
|
SchisandraAuthUserBO schisandraAuthUserBO = SchisandraAuthUserBOConverter.INSTANCE.convertEntityToBO(authUser);
|
||||||
|
return schisandraAuthUserBO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -57,4 +57,5 @@ public interface SchisandraAuthUserService {
|
|||||||
boolean updateUserPasswordByPhone(SchisandraAuthUser schisandraAuthUser);
|
boolean updateUserPasswordByPhone(SchisandraAuthUser schisandraAuthUser);
|
||||||
|
|
||||||
|
|
||||||
|
SchisandraAuthUser checkUserName(String userName);
|
||||||
}
|
}
|
||||||
|
@@ -105,5 +105,10 @@ public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraAuthUser checkUserName(String userName) {
|
||||||
|
return this.schisandraAuthUserDao.selectOneByCondition(SchisandraAuthUserTableDef.SCHISANDRA_AUTH_USER.USER_NAME.eq(userName));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user