feat(api): 新增邮箱注册检查接口
- 新增 /checkEmailRegistered GET 接口,用于检查邮箱是否已注册 - 实现邮箱格式校验,保证输入的邮箱地址有效 - 查询邮箱注册的账户列表,统计账号数量并返回是否已注册 - 返回结果封装在 CheckEmailResult 类中,包含注册状态及账号数量 - 在 SecurityConfig 中添加 /api/checkEmailRegistered 接口白名单配置
This commit is contained in:
@@ -47,6 +47,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
"/api/findAccountByPhone",
|
"/api/findAccountByPhone",
|
||||||
"/api/resetPassword",
|
"/api/resetPassword",
|
||||||
"/api/checkPhoneRegistered",
|
"/api/checkPhoneRegistered",
|
||||||
|
"/api/checkEmailRegistered",
|
||||||
"/api/existence",
|
"/api/existence",
|
||||||
"/api/oss/upload",
|
"/api/oss/upload",
|
||||||
"/druid/**",
|
"/druid/**",
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import com.gxwebsoft.common.system.result.CaptchaResult;
|
|||||||
import com.gxwebsoft.common.system.result.LoginResult;
|
import com.gxwebsoft.common.system.result.LoginResult;
|
||||||
import com.gxwebsoft.common.system.result.TenantOption;
|
import com.gxwebsoft.common.system.result.TenantOption;
|
||||||
import com.gxwebsoft.common.system.result.AccountInfoResult;
|
import com.gxwebsoft.common.system.result.AccountInfoResult;
|
||||||
|
import com.gxwebsoft.common.system.result.CheckEmailResult;
|
||||||
import com.gxwebsoft.common.system.result.CheckPhoneResult;
|
import com.gxwebsoft.common.system.result.CheckPhoneResult;
|
||||||
import com.gxwebsoft.common.system.service.*;
|
import com.gxwebsoft.common.system.service.*;
|
||||||
import com.gxwebsoft.common.system.mapper.UserMapper;
|
import com.gxwebsoft.common.system.mapper.UserMapper;
|
||||||
@@ -1788,6 +1789,20 @@ public class MainController extends BaseController {
|
|||||||
* 检查手机号是否已注册(可选接口)
|
* 检查手机号是否已注册(可选接口)
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "检查手机号是否已注册")
|
@Operation(summary = "检查手机号是否已注册")
|
||||||
|
@GetMapping("/checkEmailRegistered")
|
||||||
|
public ApiResult<?> checkEmailRegistered(@RequestParam("email") String email) {
|
||||||
|
// 邮箱格式校验
|
||||||
|
if (!CommonUtil.isValidEmail(email)) {
|
||||||
|
return fail("请输入有效的邮箱地址");
|
||||||
|
}
|
||||||
|
// 统计该邮箱注册的账号数量(跨租户,复用 findAccountsByEmail)
|
||||||
|
List<User> accounts = userService.findAccountsByEmail(email);
|
||||||
|
CheckEmailResult result = new CheckEmailResult();
|
||||||
|
result.setIsRegistered(accounts != null && !accounts.isEmpty());
|
||||||
|
result.setAccountCount(accounts != null ? accounts.size() : 0);
|
||||||
|
return success(result);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/checkPhoneRegistered")
|
@GetMapping("/checkPhoneRegistered")
|
||||||
public ApiResult<?> checkPhoneRegistered(@RequestParam("phone") String phone) {
|
public ApiResult<?> checkPhoneRegistered(@RequestParam("phone") String phone) {
|
||||||
// 验证手机号
|
// 验证手机号
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.gxwebsoft.common.system.result;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查邮箱返回结果
|
||||||
|
*
|
||||||
|
* @author WebSoft
|
||||||
|
* @since 2026-08-06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "检查邮箱返回结果")
|
||||||
|
public class CheckEmailResult implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "是否已注册")
|
||||||
|
private Boolean isRegistered;
|
||||||
|
|
||||||
|
@Schema(description = "账号数量")
|
||||||
|
private Integer accountCount;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user