|
@@ -5,7 +5,7 @@ import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.function.Consumer;
|
|
|
+import java.util.function.Function;
|
|
|
|
|
|
import com.chelvc.framework.base.context.ApplicationContextHolder;
|
|
|
import com.chelvc.framework.base.context.SessionContextHolder;
|
|
@@ -119,22 +119,17 @@ public class SwitchableCaptchaSmsHandler implements CaptchaSmsHandler {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void using(@NonNull String mobile, @NonNull Consumer<Captcha> consumer) {
|
|
|
+ public void using(@NonNull String mobile, @NonNull Function<Captcha, Boolean> function) {
|
|
|
Captcha captcha = this.getCaptcha(mobile);
|
|
|
- try {
|
|
|
- consumer.accept(captcha);
|
|
|
- } finally {
|
|
|
- if (captcha != null) {
|
|
|
- this.redisTemplate.delete(this.key(mobile));
|
|
|
- }
|
|
|
+ if (Boolean.TRUE.equals(function.apply(captcha))) {
|
|
|
+ this.redisTemplate.delete(this.key(mobile));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean check(@NonNull String token, @NonNull String mobile, @NonNull String code) {
|
|
|
Captcha captcha = this.getCaptcha(mobile);
|
|
|
- return captcha != null && Objects.equals(token, captcha.getToken())
|
|
|
- && Objects.equals(mobile, captcha.getMobile()) && Objects.equals(code, captcha.getCode());
|
|
|
+ return captcha != null && captcha.check(token, mobile, code);
|
|
|
}
|
|
|
|
|
|
@Override
|