com.thebund1st.daming.redis.RedisSmsVerificationCodeMismatchEventHandler Maven / Gradle / Ivy
package com.thebund1st.daming.redis;
import com.thebund1st.daming.core.MobilePhoneNumber;
import com.thebund1st.daming.core.SmsVerificationScope;
import com.thebund1st.daming.events.EventPublisher;
import com.thebund1st.daming.events.SmsVerificationCodeMismatchEvent;
import com.thebund1st.daming.events.SmsVerificationCodeVerifiedEvent;
import com.thebund1st.daming.events.TooManyFailureSmsVerificationAttemptsEvent;
import com.thebund1st.daming.time.Clock;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
import static java.util.stream.Collectors.joining;
@Slf4j
@RequiredArgsConstructor
public class RedisSmsVerificationCodeMismatchEventHandler {
private static final String DELIMITER = ",";
private final StringRedisTemplate redisTemplate;
private final EventPublisher eventPublisher;
private final Clock clock;
@Setter
private int threshold = 5;
@EventListener
public void on(SmsVerificationCodeMismatchEvent event) {
log.debug("Receiving {}", event.toString());
String key = toKey(event.getMobile(), event.getScope());
List