|
|
|
@ -13,17 +13,9 @@ import ( |
|
|
|
|
|
|
|
|
|
// telegram "git.slaventius.ru/test3k/authPostman/internal/transport/telegram"
|
|
|
|
|
smtp "git.slaventius.ru/test3k/authPostman/internal/transport/smtp" |
|
|
|
|
api "git.slaventius.ru/test3k/umate/pkg/kafka" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
topicRegistrations string = "registrations" // Топик для регистраций
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type msg struct { |
|
|
|
|
Code string |
|
|
|
|
Email string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type AuthPostmanServer struct { |
|
|
|
|
ctx context.Context |
|
|
|
|
kafkaReader *kafka.KafkaReader |
|
|
|
@ -35,7 +27,7 @@ func NewServer(ctx context.Context, config *config.Config) *AuthPostmanServer { |
|
|
|
|
|
|
|
|
|
return &AuthPostmanServer{ |
|
|
|
|
ctx: ctx, |
|
|
|
|
kafkaReader: kafka.NewReader(ctx, config, topicRegistrations, address...), |
|
|
|
|
kafkaReader: kafka.NewReader(ctx, config, api.TopicRegistrations, address...), |
|
|
|
|
config: config, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -56,17 +48,17 @@ func (s *AuthPostmanServer) ReadMessage(offset int64) error { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Декодируем сообщение
|
|
|
|
|
amsg := msg{} |
|
|
|
|
erk := json.Unmarshal(m.Value, &amsg) |
|
|
|
|
msg := api.MessageRegistration{} |
|
|
|
|
erk := json.Unmarshal(m.Value, &msg) |
|
|
|
|
if erk != nil { |
|
|
|
|
return erk |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
log.Printf("send code %s to %s ...", amsg.Code, amsg.Email) |
|
|
|
|
log.Printf("send code %s to %s ...", msg.Code, msg.Email) |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
text := fmt.Sprintf("Confirmation code %v", amsg.Code) |
|
|
|
|
text := fmt.Sprintf("Confirmation code %v", msg.Code) |
|
|
|
|
// postman := telegram.NewService(s.config.Telegram.ChatToken)
|
|
|
|
|
// message := postman.NewMessage(s.config.Telegram.ChatID, text)
|
|
|
|
|
// ers := postman.SendMessage(message)
|
|
|
|
@ -78,7 +70,7 @@ func (s *AuthPostmanServer) ReadMessage(offset int64) error { |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
message := smtp.NewMessage("Confirmation code", text) |
|
|
|
|
message.AppendRecipient(amsg.Email) |
|
|
|
|
message.AppendRecipient(msg.Email) |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
smtpSender := smtp.NewService(s.config.Smtp.Host, s.config.Smtp.Port, s.config.Smtp.Sender, s.config.Smtp.Password) |
|
|
|
@ -86,7 +78,7 @@ func (s *AuthPostmanServer) ReadMessage(offset int64) error { |
|
|
|
|
if ers != nil { |
|
|
|
|
log.Print(ers) |
|
|
|
|
} else { |
|
|
|
|
log.Printf("send code %s to %s completed", amsg.Code, amsg.Email) |
|
|
|
|
log.Printf("send code %s to %s completed", msg.Code, msg.Email) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|