From 2ef5202b5cfcc03c9716fadb6443f41c43d18d9a Mon Sep 17 00:00:00 2001 From: Jack <46790855@qq.com> Date: Tue, 25 Feb 2025 17:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=AE=B6=E7=89=88=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E4=B8=8E=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/controller/LoginController.java | 26 ++++ .../service/AccountUserBaseService.java | 20 +++ .../AccountUserBindConnectService.java | 23 ++- .../impl/AccountUserBaseServiceImpl.java | 139 +++++++++++++++++- .../AccountUserBindConnectServiceImpl.java | 28 +++- .../mall/common/constant/RedisConstant.java | 2 + .../common/utils/phone/PhoneNumberUtils.java | 18 ++- 7 files changed, 240 insertions(+), 16 deletions(-) diff --git a/mall-account/src/main/java/com/suisung/mall/account/controller/LoginController.java b/mall-account/src/main/java/com/suisung/mall/account/controller/LoginController.java index 43f91244..6d8ca2c7 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/controller/LoginController.java +++ b/mall-account/src/main/java/com/suisung/mall/account/controller/LoginController.java @@ -181,6 +181,32 @@ public class LoginController extends BaseControllerImpl { return accountUserBaseService.doMerchSmsRegisterAndLogin(paramJSON.getStr("user_mobile"), paramJSON.getStr("rand_key"), paramJSON.getStr("verify_code")); } + @ApiOperation(value = "通过(绑定手机的)账号、手机、email 发送短信、邮件验证码") + @RequestMapping(value = "/sendVerifyCode", method = RequestMethod.POST) + public CommonResult sendVerifyCode(@RequestBody JSONObject paramJSON) { + return accountUserBaseService.sendVerifyCode(paramJSON.getStr("number")); + } + + + @ApiOperation(value = "忘记密码后修改密码") + @RequestMapping(value = "/doForgetPassword", method = RequestMethod.POST) + public CommonResult doForgetPassword(@RequestBody JSONObject paramJSON) { + return accountUserBaseService.doForgetPassword(paramJSON.getStr("number"), paramJSON.getStr("verify_code"), paramJSON.getStr("new_password")); + } + + + @ApiOperation(value = "忘记密码-验证短信验证码") + @RequestMapping(value = "/put/forgetPassword", method = RequestMethod.POST) + public CommonResult putForgetPassword(@RequestBody JSONObject paramJSON) { + return accountUserBaseService.doMerchSmsRegisterAndLogin(paramJSON.getStr("user_mobile"), paramJSON.getStr("rand_key"), paramJSON.getStr("verify_code")); + } + + @ApiOperation(value = "忘记密码-更改新密码") + @RequestMapping(value = "/edit/forgetPassword", method = RequestMethod.POST) + public CommonResult editForgetPassword(@RequestBody JSONObject paramJSON) { + return accountUserBaseService.doMerchSmsRegisterAndLogin(paramJSON.getStr("user_mobile"), paramJSON.getStr("rand_key"), paramJSON.getStr("verify_code")); + } + @ApiOperation("退出登录") @RequestMapping(value = "/doLogout", method = RequestMethod.GET) public CommonResult doLogout() { diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBaseService.java b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBaseService.java index 12b7c2a4..c3379867 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBaseService.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBaseService.java @@ -79,6 +79,15 @@ public interface AccountUserBaseService extends IBaseService { boolean getVerifyCode(String number); + /** + * 通过(绑定手机的)账号、手机、email 发送短信、邮件验证码 + * + * @param number 账号(注:绑定过手机号码的账号)或手机号码 或 email + * @return + */ + CommonResult sendVerifyCode(String number); + + boolean getEmailMobileVerifyCode(String number); AccountUserBase getByNickname(String nickname); @@ -168,4 +177,15 @@ public interface AccountUserBaseService extends IBaseService { Boolean existByNickname(String nickname, String storeId); Pair saveOrUpdate2(AccountUserBase entity); + + + /** + * 忘记密码操作 + * + * @param userAccountOrMobile 账号(注:绑定过手机号码的账号)或手机号码 + * @param verifyCode 短信验证码 + * @param newPassword 新密码 + * @return + */ + CommonResult doForgetPassword(String userAccountOrMobile, String verifyCode, String newPassword); } diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java index cab2b139..cfac1a14 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java @@ -15,8 +15,27 @@ import java.util.Map; */ public interface AccountUserBindConnectService extends IBaseService { + /** + * 根据用户 ID 和绑定类型获取一条记录 + * + * @param user_id + * @param bind_type + * @return + */ + AccountUserBindConnect getBindByUserId(Integer user_id, Integer bind_type); + Map getBind(Integer user_id, int bind_type); + /** + * 根据 bind_id 和 bind_type 获取一条记录 + * + * @param bind_id + * @param bind_type + * @return + */ + AccountUserBindConnect getBindByBindId(String bind_id, Integer bind_type); + + boolean checkBind(String bind_id, int bind_type, Integer user_id, AccountUserBindConnect user_info_row); boolean checkAccessToken(Integer bind_type, AccountUserBindConnect bind_data, Integer user_id); @@ -26,8 +45,8 @@ public interface AccountUserBindConnectService extends IBaseService queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("user_account", user_account).orderByAsc("user_account").orderByAsc("user_password"); + queryWrapper.eq("user_account", user_account).orderByAsc("user_id"); AccountUserBase data = findOne(queryWrapper); return data; } /** - * 获取 手机/邮件 验证码 + * 发送 手机/邮件 验证码 * * @param number * @return @@ -2348,6 +2349,62 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("user_id", user_id) + .eq("bind_active", CommonConstant.Enable) + .eq("bind_type", bind_type); + return findOne(queryWrapper); + } + /** * 获取有效绑定 * @@ -52,14 +68,16 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("user_id", user_id) - .eq("bind_active", 1) + queryWrapper.eq("bind_id", bind_id) + .eq("bind_active", CommonConstant.Enable) .eq("bind_type", bind_type); - AccountUserBindConnect bindConnect = findOne(queryWrapper); - - return Convert.toMap(String.class, Object.class, bindConnect); + return findOne(queryWrapper); } @Override diff --git a/mall-common/src/main/java/com/suisung/mall/common/constant/RedisConstant.java b/mall-common/src/main/java/com/suisung/mall/common/constant/RedisConstant.java index 6efff581..e8537f4a 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/constant/RedisConstant.java +++ b/mall-common/src/main/java/com/suisung/mall/common/constant/RedisConstant.java @@ -18,6 +18,8 @@ public class RedisConstant { public static final String Verifycode_NameSpace = ConstantRedis.Cache_NameSpace + "VERIFYCODE:"; + public static final String FORGETPWD_NAMEPACE = ConstantRedis.Cache_NameSpace + "FORGETPWD:"; + public static final String Config_Cache_Key = "config_cache_key"; public static final String Config_Cache_Version = "config_cache_version"; diff --git a/mall-common/src/main/java/com/suisung/mall/common/utils/phone/PhoneNumberUtils.java b/mall-common/src/main/java/com/suisung/mall/common/utils/phone/PhoneNumberUtils.java index a79fa443..3b9e40d7 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/utils/phone/PhoneNumberUtils.java +++ b/mall-common/src/main/java/com/suisung/mall/common/utils/phone/PhoneNumberUtils.java @@ -40,13 +40,13 @@ public class PhoneNumberUtils { private final static int COUNTRY_CODE_CHINA = 86; /** - * 判断手机号是否有效(中国) + * 判断(中国)手机号是否有效 * * @param phoneNumber 手机号码 * @return true-有效 false-无效 */ public static boolean checkPhoneNumber(String phoneNumber) { - return checkPhoneNumber(COUNTRY_CODE_CHINA, phoneNumber); + return checkPhoneNumber(COUNTRY_CODE_CHINA, cleanPhoneNumber(phoneNumber)); } /** @@ -59,6 +59,20 @@ public class PhoneNumberUtils { return StrUtil.startWith(phoneNumber, "+") ? phoneNumber : CommonConstant.IDD_ZH_CN + phoneNumber; } + /** + * 去掉手机的国家码,方法不严谨 + * + * @param phoneNumber + * @return + */ + public static String cleanPhoneNumber(String phoneNumber) { + if (phoneNumber.length() <= 3) { + return phoneNumber; + } + + return StrUtil.startWith(phoneNumber, "+") ? phoneNumber.substring(2) : phoneNumber; + } + /** * 判断手机号是否有效(国际) *