feat(auth): 添加账号或密码错误的异常处理
- 在 ErrorCodeEnum 中新增 ACCOUNT_OR_PASSWORD_IS_INCORRECT 错误码 - 修改 LoginServiceImpl 中的登录逻辑,使用新的错误码替代原有错误码 -为 ClientEndExceptions.AuthenticationFailure 添加基于 ErrorCodeEnum 的构建方法 - 更新 AuthenticationFailure 构造函数以支持 ErrorCodeEnum 参数
Showing
3 changed files
with
17 additions
and
7 deletions
| ... | @@ -21,6 +21,10 @@ public class ClientEndExceptions { | ... | @@ -21,6 +21,10 @@ public class ClientEndExceptions { |
| 21 | * 权限登陆未认证异常 | 21 | * 权限登陆未认证异常 |
| 22 | */ | 22 | */ |
| 23 | public static class AuthenticationFailure extends ClientEndException { | 23 | public static class AuthenticationFailure extends ClientEndException { |
| 24 | + private AuthenticationFailure(ErrorCodeEnum errorCodeEnum) { | ||
| 25 | + super(errorCodeEnum.getCode(), errorCodeEnum.getMessage()); | ||
| 26 | + } | ||
| 27 | + | ||
| 24 | private AuthenticationFailure(String message) { | 28 | private AuthenticationFailure(String message) { |
| 25 | super(ErrorCodeEnum.UNAUTHORIZED.getCode(), message); | 29 | super(ErrorCodeEnum.UNAUTHORIZED.getCode(), message); |
| 26 | } | 30 | } |
| ... | @@ -28,6 +32,10 @@ public class ClientEndExceptions { | ... | @@ -28,6 +32,10 @@ public class ClientEndExceptions { |
| 28 | public synchronized static AuthenticationFailure build(String message) { | 32 | public synchronized static AuthenticationFailure build(String message) { |
| 29 | return new AuthenticationFailure(message); | 33 | return new AuthenticationFailure(message); |
| 30 | } | 34 | } |
| 35 | + | ||
| 36 | + public synchronized static AuthenticationFailure build(ErrorCodeEnum errorCodeEnum) { | ||
| 37 | + return new AuthenticationFailure(errorCodeEnum); | ||
| 38 | + } | ||
| 31 | } | 39 | } |
| 32 | 40 | ||
| 33 | /** | 41 | /** | ... | ... |
| ... | @@ -66,7 +66,9 @@ public enum ErrorCodeEnum implements BaseEnum { | ... | @@ -66,7 +66,9 @@ public enum ErrorCodeEnum implements BaseEnum { |
| 66 | 66 | ||
| 67 | MP_ACCOUNT_ALREADY_DISABLED(406000024, "账号已禁用"), | 67 | MP_ACCOUNT_ALREADY_DISABLED(406000024, "账号已禁用"), |
| 68 | 68 | ||
| 69 | - DINER_MEAL_SUSPENDED(406000025, "当前就餐人处于停餐状态") | 69 | + DINER_MEAL_SUSPENDED(406000025, "当前就餐人处于停餐状态"), |
| 70 | + | ||
| 71 | + ACCOUNT_OR_PASSWORD_IS_INCORRECT(406000026, "账号或密码错误") | ||
| 70 | 72 | ||
| 71 | 73 | ||
| 72 | ; | 74 | ; | ... | ... |
| ... | @@ -135,13 +135,13 @@ public class LoginServiceImpl implements LoginService { | ... | @@ -135,13 +135,13 @@ public class LoginServiceImpl implements LoginService { |
| 135 | } else if (loginDto.isShouldLoginWithOperatorPhone()) { | 135 | } else if (loginDto.isShouldLoginWithOperatorPhone()) { |
| 136 | final var operator = operatorServiceRpcClient.getCOperatorByMobileOrEmail(loginDto.getOperatorPhone()); | 136 | final var operator = operatorServiceRpcClient.getCOperatorByMobileOrEmail(loginDto.getOperatorPhone()); |
| 137 | if (operator.getId() == 0) { | 137 | if (operator.getId() == 0) { |
| 138 | - throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name()); | 138 | + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.ACCOUNT_OR_PASSWORD_IS_INCORRECT); |
| 139 | } | 139 | } |
| 140 | if (!operator.getPassword().equals(sha1Hash(loginDto.getPassword()))) { | 140 | if (!operator.getPassword().equals(sha1Hash(loginDto.getPassword()))) { |
| 141 | - throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name()); | 141 | + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.ACCOUNT_OR_PASSWORD_IS_INCORRECT); |
| 142 | } | 142 | } |
| 143 | if (operator.getStatus() != 1) { | 143 | if (operator.getStatus() != 1) { |
| 144 | - throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name()); | 144 | + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.ACCOUNT_OR_PASSWORD_IS_INCORRECT); |
| 145 | } | 145 | } |
| 146 | StpUtil.login(operator.getId(), SaLoginModel.create() | 146 | StpUtil.login(operator.getId(), SaLoginModel.create() |
| 147 | .setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId()) | 147 | .setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId()) |
| ... | @@ -151,13 +151,13 @@ public class LoginServiceImpl implements LoginService { | ... | @@ -151,13 +151,13 @@ public class LoginServiceImpl implements LoginService { |
| 151 | } else { | 151 | } else { |
| 152 | final var operator = wOperatorServiceRpcClient.getWOperatorByEmail(loginDto.getEmail()).getResponse(); | 152 | final var operator = wOperatorServiceRpcClient.getWOperatorByEmail(loginDto.getEmail()).getResponse(); |
| 153 | if (operator.getId() == 0) { | 153 | if (operator.getId() == 0) { |
| 154 | - throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name()); | 154 | + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.ACCOUNT_OR_PASSWORD_IS_INCORRECT); |
| 155 | } | 155 | } |
| 156 | if (!operator.getPassword().equals(sha1Hash(loginDto.getPassword()))) { | 156 | if (!operator.getPassword().equals(sha1Hash(loginDto.getPassword()))) { |
| 157 | - throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name()); | 157 | + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.ACCOUNT_OR_PASSWORD_IS_INCORRECT); |
| 158 | } | 158 | } |
| 159 | if (operator.getStatus() != WOperatorStatus.SHOW) { | 159 | if (operator.getStatus() != WOperatorStatus.SHOW) { |
| 160 | - throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name()); | 160 | + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.ACCOUNT_OR_PASSWORD_IS_INCORRECT); |
| 161 | } | 161 | } |
| 162 | StpUtil.login(operator.getId(), SaLoginModel.create() | 162 | StpUtil.login(operator.getId(), SaLoginModel.create() |
| 163 | .setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId()) | 163 | .setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId()) | ... | ... |
-
Please register or login to post a comment