finish debug auth

This commit is contained in:
Pavel 2024-07-01 11:16:47 +03:00
parent 8b00ad820f
commit fec5374964
3 changed files with 21 additions and 12 deletions

2
go.mod

@ -21,7 +21,7 @@ require (
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240607202348-efe5f2bf3e8c
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240627194440-f997b952c31f
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240630165148-3c27e15d9ac1
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075856-1731684c936f
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240615192328-b2f5dffe92ae
)

6
go.sum

@ -291,5 +291,11 @@ penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e0
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990/go.mod h1:zswBuTwmEsFHBVRu1nkG3/Fwylk5Vcm8OUm9iWxccSE=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240630165148-3c27e15d9ac1 h1:fGhu5JuLODJ4pLb4YiyrioFXSQS+UP+KUQhcLwzIeWs=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240630165148-3c27e15d9ac1/go.mod h1:AkE19hcbDwB7hoEASwImm7rUI+cK/8jMVJaTvMK4F+c=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701074825-8eceb99cd2ab h1:axHShcqrVZHx6CTB0OJW8ac3Hqi7DxfJu2e5nuusxE4=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701074825-8eceb99cd2ab/go.mod h1:AkE19hcbDwB7hoEASwImm7rUI+cK/8jMVJaTvMK4F+c=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075500-8c122317a246 h1:FRQfWwaSJB2eyp8eTNdulg5/V2bC1VnmC6YcGm7mYZg=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075500-8c122317a246/go.mod h1:AkE19hcbDwB7hoEASwImm7rUI+cK/8jMVJaTvMK4F+c=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075856-1731684c936f h1:Qli89wgu0T7nG4VECXZOZ40fjE/hVVfxF3hTaSYS008=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075856-1731684c936f/go.mod h1:AkE19hcbDwB7hoEASwImm7rUI+cK/8jMVJaTvMK4F+c=
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240615192328-b2f5dffe92ae h1:vlGInCsQSDA464q7OMv3EWGUviQWQdEcpLc8HIRo+rE=
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240615192328-b2f5dffe92ae/go.mod h1:3ml0dAGT8U8RhpevKBfRgG6yKZum8EI2uJxAb2WCIy4=

@ -49,26 +49,29 @@ func (s *Service) AddingTgAccount(ctx *fiber.Ctx) error {
}
var tdlibClient *client.Client
// todo проверить как завершается
// завершается уже в другом контроллере
var goErr error
go func() {
tdlibClient, err = client.NewClient(authorizer)
if err != nil {
tdlibClient, goErr = client.NewClient(authorizer)
if goErr != nil {
fmt.Println("new client failed", err)
return
}
fmt.Println("i am down")
}()
if goErr != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString(goErr.Error())
}
for {
state, ok := <-authorizer.State
if !ok {
return ctx.SendStatus(fiber.StatusOK)
return ctx.Status(fiber.StatusOK).SendString("state chan is close auth maybe ok")
}
fmt.Println("currnet state:", state)
switch state.AuthorizationStateType() {
case client.TypeAuthorizationStateWaitPhoneNumber:
authorizer.PhoneNumber <- req.PhoneNumber
case client.TypeAuthorizationStateWaitCode:
id := xid.New()
s.telegramClient.AddedToMap(telegram.WaitingClient{
@ -76,10 +79,10 @@ func (s *Service) AddingTgAccount(ctx *fiber.Ctx) error {
PreviousReq: req,
Authorizer: authorizer,
}, id.String())
return ctx.Status(fiber.StatusOK).JSON(id.String())
return ctx.Status(fiber.StatusOK).JSON(fiber.Map{"id": id.String()})
case client.TypeAuthorizationStateLoggingOut, client.TypeAuthorizationStateClosing, client.TypeAuthorizationStateClosed:
return ctx.Status(fiber.StatusForbidden).SendString("auth failed")
return ctx.Status(fiber.StatusForbidden).SendString(fmt.Sprintf("auth failed, last state is %s", state))
}
}
}
@ -101,16 +104,16 @@ func (s *Service) SettingTgCode(ctx *fiber.Ctx) error {
for {
state, ok := <-data.Authorizer.State
if !ok {
return ctx.SendStatus(fiber.StatusOK)
return ctx.Status(fiber.StatusOK).SendString("state chan is close auth maybe ok")
}
fmt.Println("currnet state:", state)
switch state.AuthorizationStateType() {
case client.TypeAuthorizationStateReady:
return ctx.SendStatus(fiber.StatusOK)
return ctx.Status(fiber.StatusOK).SendString("auth success")
case client.TypeAuthorizationStateWaitPassword:
data.Authorizer.Password <- data.PreviousReq.Password
case client.TypeAuthorizationStateLoggingOut, client.TypeAuthorizationStateClosing, client.TypeAuthorizationStateClosed:
return ctx.Status(fiber.StatusForbidden).SendString("auth failed")
return ctx.Status(fiber.StatusForbidden).SendString(fmt.Sprintf("auth failed, last state is %s", state))
}
}
}