diff --git a/.env b/.env index 4a78021..469a8ab 100644 --- a/.env +++ b/.env @@ -38,6 +38,7 @@ SMTP_SENDER="noreply@mailing.pena.digital" DEFAULT_REDIRECTION_URL = "def.url" AUTH_EXCHANGE_URL = "http://localhost:8000/auth/exchange" DISCOUNT_ADDRESS = "http://CHANGEME:1234" +RECOVERY_URL = "http://127.0.0.1:8080/recover/" # Kafka settings KAFKA_BROKERS="localhost:9092" diff --git a/internal/adapters/client/mail.go b/internal/adapters/client/mail.go index 1522cf8..849d74a 100644 --- a/internal/adapters/client/mail.go +++ b/internal/adapters/client/mail.go @@ -9,17 +9,16 @@ import ( ) type RecoveryEmailSenderDeps struct { - SmtpApiUrl string - SmtpHost string - SmtpPort string - SmtpSender string - Username string - Password string - ApiKey string - FiberClient *fiber.Client - Logger *zap.Logger - CodewordHost string - CodewordPort string + SmtpApiUrl string + SmtpHost string + SmtpPort string + SmtpSender string + Username string + Password string + ApiKey string + FiberClient *fiber.Client + Logger *zap.Logger + RecoveryUrl string } type RecoveryEmailSender struct { @@ -40,7 +39,7 @@ func (r *RecoveryEmailSender) SendRecoveryEmail(email string, signature string) fmt.Println(email, signature) - message := fmt.Sprintf("http://"+r.deps.CodewordHost+":"+r.deps.CodewordPort+"/recover/%s", signature) + message := r.deps.RecoveryUrl + signature form := new(bytes.Buffer) writer := multipart.NewWriter(form) @@ -48,7 +47,7 @@ func (r *RecoveryEmailSender) SendRecoveryEmail(email string, signature string) fields := map[string]string{ "from": r.deps.SmtpSender, - "to": "pashamullin202@gmail.com", + "to": email, "subject": "Восстановление доступа", "html": message, } diff --git a/internal/controller/recovery/recovery_controller.go b/internal/controller/recovery/recovery_controller.go index b55b2b7..f3e9afe 100644 --- a/internal/controller/recovery/recovery_controller.go +++ b/internal/controller/recovery/recovery_controller.go @@ -58,7 +58,6 @@ func (r *RecoveryController) HandleRecoveryRequest(c *fiber.Ctx) error { user, err := r.service.FindUserByEmail(c.Context(), req.Email) if err != nil || user == nil { r.logger.Error("Failed to find user by email", zap.Error(err)) - return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "User not found"}) } diff --git a/internal/initialize/clients.go b/internal/initialize/clients.go index e7851b8..e32051b 100644 --- a/internal/initialize/clients.go +++ b/internal/initialize/clients.go @@ -8,17 +8,16 @@ import ( func RecoveryEmailSender(cfg Config, logger *zap.Logger) *client.RecoveryEmailSender { return client.NewRecoveryEmailSender(client.RecoveryEmailSenderDeps{ - SmtpApiUrl: cfg.SmtpApiUrl, - SmtpHost: cfg.SmtpHost, - SmtpPort: cfg.SmtpPort, - SmtpSender: cfg.SmtpSender, - Username: cfg.SmtpUsername, - Password: cfg.SmtpPassword, - ApiKey: cfg.SmtpApiKey, - FiberClient: &fiber.Client{}, - Logger: logger, - CodewordHost: cfg.HTTPHost, - CodewordPort: cfg.HTTPPort, + SmtpApiUrl: cfg.SmtpApiUrl, + SmtpHost: cfg.SmtpHost, + SmtpPort: cfg.SmtpPort, + SmtpSender: cfg.SmtpSender, + Username: cfg.SmtpUsername, + Password: cfg.SmtpPassword, + ApiKey: cfg.SmtpApiKey, + FiberClient: &fiber.Client{}, + Logger: logger, + RecoveryUrl: cfg.RecoveryUrl, }) } diff --git a/internal/initialize/config.go b/internal/initialize/config.go index 087bfb2..c0c0621 100644 --- a/internal/initialize/config.go +++ b/internal/initialize/config.go @@ -34,6 +34,7 @@ type Config struct { KafkaBrokers string `env:"KAFKA_BROKERS"` KafkaTopic string `env:"KAFKA_TOPIC_TARIFF"` DiscountServiceAddress string `env:"DISCOUNT_ADDRESS"` + RecoveryUrl string `env:"RECOVERY_URL"` } func LoadConfig() (*Config, error) {