@@ -0,0 +1,59 @@
|
||||
package screens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
"github.com/TelegramExchange/tgex-backend/tg_bot/bot"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Login struct{}
|
||||
|
||||
const msgHelloLogin = `
|
||||
Привет, %s!
|
||||
Нажми кнопку для входа на сайт. 👇
|
||||
`
|
||||
|
||||
func (s *Login) Enter(b *bot.Bot, mode bot.RenderMode) {
|
||||
token, err := b.Backend.CreateLoginToken(context.Background(), b.ChatID)
|
||||
if err != nil {
|
||||
b.SendNew("❌ Произошла ошибка при создании токена входа. Попробуйте позже.", emptyKeyboard)
|
||||
return
|
||||
}
|
||||
|
||||
loginURL := b.Backend.LoginURL(token)
|
||||
|
||||
usernameDisplay := "аноним"
|
||||
if b.Session.FirstName != "" {
|
||||
usernameDisplay = b.Session.FirstName
|
||||
}
|
||||
|
||||
kb := Keyboard(Row(URLButton("Войти на сайт", loginURL)))
|
||||
|
||||
res, err := b.SendMessage(fmt.Sprintf(msgHelloLogin, usernameDisplay), b.ChatID, &echotron.MessageOptions{
|
||||
ReplyMarkup: kb,
|
||||
ParseMode: echotron.HTML,
|
||||
LinkPreviewOptions: echotron.LinkPreviewOptions{IsDisabled: true},
|
||||
})
|
||||
if err != nil {
|
||||
log.Err(err).Msg("SendMessage error")
|
||||
return
|
||||
}
|
||||
|
||||
if res.Result != nil {
|
||||
if err := b.Backend.AttachLoginTokenMessage(context.Background(), token, res.Result.ID); err != nil {
|
||||
log.Err(err).Msg("AttachLoginTokenMessage error")
|
||||
}
|
||||
}
|
||||
|
||||
b.SetState(&MainMenu{}, bot.NewMessage)
|
||||
}
|
||||
func (s *Login) HandleCallback(b *bot.Bot, u *echotron.Update) {}
|
||||
|
||||
func (s *Login) HandleMessage(b *bot.Bot, u *echotron.Update) {}
|
||||
|
||||
func (s *Login) Handle(b *bot.Bot, u *echotron.Update) {}
|
||||
|
||||
func (s *Login) Exit() {}
|
||||
Reference in New Issue
Block a user