improving otp sec

This commit is contained in:
2026-07-09 18:38:52 +02:00
parent 5d3cfde7f6
commit 94a30633ca
4 changed files with 31 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package zw.qantra.tm.domain.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;
import zw.qantra.tm.domain.enums.Status;
@@ -16,6 +17,7 @@ import zw.qantra.tm.domain.enums.Status;
@NoArgsConstructor
public class Otp extends BaseEntity{
private String username;
@JsonIgnore
private String otp;
@Enumerated(EnumType.STRING)
@Column(name = "otp_status")

View File

@@ -18,6 +18,8 @@ import zw.qantra.tm.rest.RestService;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@@ -35,6 +37,11 @@ public class NotificationService {
@Value("${sms.debug}")
private Boolean smsDebug;
@Value("${wa.api.url}")
private String waApiUrl;
@Value("${wa.api.key}")
private String waApiKey;
@Async
public void sendEmail(String to, String subject, String text) {
sendEmailWithHtml(to, subject, text, null);
@@ -97,6 +104,24 @@ public class NotificationService {
}
}
@Async
public void sendWA(String chatId, String text) {
try {
Map<String, String> payload = new HashMap<>();
payload.put("chatId", chatId);
payload.put("text", text);
HttpHeaders headers = new HttpHeaders();
headers.set("X-API-Key", waApiKey);
restService.postWithExternalAuth(waApiUrl, payload, headers, Object.class);
logger.info("WA message sent to {}: {}", chatId, text);
} catch (Exception e) {
logger.error("Failed to send WA message to {}: {}", chatId, e.getMessage(), e);
}
}
@Async
public void sendSms(String to, String message) {
if(smsDebug) {