add rec url to env

This commit is contained in:
Pavel 2024-01-18 15:40:15 +03:00
parent 24ba370ccd
commit e7e249a2ba
5 changed files with 24 additions and 25 deletions

1
.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"

@ -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,
}

@ -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"})
}

@ -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,
})
}

@ -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) {