Add Telegram notifications for admin on user login
- Create Telegram service for sending notifications - Send silent notification to @wakeren_bot when user logs in - Include: username, email, nombre, timestamp - Notifications only visible to admin (chat ID: 692714536) - Users are not aware of this feature
This commit is contained in:
@@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
@@ -11,11 +12,15 @@ import (
|
||||
)
|
||||
|
||||
type AuthHandler struct {
|
||||
authService *services.AuthService
|
||||
authService *services.AuthService
|
||||
telegramService *services.TelegramService
|
||||
}
|
||||
|
||||
func NewAuthHandler(authService *services.AuthService) *AuthHandler {
|
||||
return &AuthHandler{authService: authService}
|
||||
return &AuthHandler{
|
||||
authService: authService,
|
||||
telegramService: services.NewTelegramService(),
|
||||
}
|
||||
}
|
||||
|
||||
// Login godoc
|
||||
@@ -48,6 +53,16 @@ func (h *AuthHandler) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Notificación silenciosa a Telegram (solo para admin)
|
||||
go func() {
|
||||
_ = h.telegramService.SendLoginNotification(
|
||||
resp.User.Username,
|
||||
resp.User.Email,
|
||||
resp.User.Nombre,
|
||||
time.Now(),
|
||||
)
|
||||
}()
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user