Fix: various bug fix
This commit is contained in:
@@ -5,9 +5,11 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"gitea.konchin.com/ytshih/inp2025/models"
|
||||
"gitea.konchin.com/ytshih/inp2025/handlers/auth"
|
||||
"gitea.konchin.com/ytshih/inp2025/types"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type landingOperationType int
|
||||
@@ -73,14 +75,18 @@ type postLoginMsg struct{}
|
||||
|
||||
func (m *LandingModel) postLogin() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
resp, err := m.BaseModel.client.R().
|
||||
var res auth.PostLoginOutput
|
||||
resp, err := m.client.R().
|
||||
SetResult(&res).
|
||||
ForceContentType("application/json").
|
||||
SetBasicAuth(m.username.Value(), m.password.Value()).
|
||||
Post("/auth/login")
|
||||
if err == nil {
|
||||
switch resp.StatusCode() {
|
||||
case http.StatusOK:
|
||||
m.BaseModel.client.SetBasicAuth(
|
||||
m.client.SetBasicAuth(
|
||||
m.username.Value(), m.password.Value())
|
||||
m.loginCount = res.LoginCount
|
||||
m.info = "login success.\n"
|
||||
m.err = nil
|
||||
case http.StatusUnauthorized:
|
||||
@@ -101,8 +107,8 @@ type postRegisterMsg struct{}
|
||||
|
||||
func (m *LandingModel) postRegister() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
resp, err := m.BaseModel.client.R().
|
||||
SetBody(models.User{
|
||||
resp, err := m.client.R().
|
||||
SetBody(auth.PostRegisterInput{
|
||||
Username: m.username.Value(),
|
||||
Password: m.password.Value(),
|
||||
}).
|
||||
@@ -193,8 +199,22 @@ func (m *LandingModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
case postLoginMsg:
|
||||
if m.err == nil {
|
||||
*m.queue = append(*m.queue,
|
||||
tea.NewProgram(NewLobbyModel(m.BaseModel)))
|
||||
m.Push(types.Program{
|
||||
Run: func() error {
|
||||
m.client.SetBaseURL(viper.GetString("auth-endpoint"))
|
||||
_, err := m.client.R().
|
||||
Post("/auth/logout")
|
||||
return err
|
||||
},
|
||||
Stage: types.StageLanding,
|
||||
})
|
||||
|
||||
program := tea.NewProgram(NewLobbyModel(m.BaseModel))
|
||||
m.Push(types.Program{
|
||||
Run: func() error { _, err := program.Run(); return err },
|
||||
Stage: types.StageLobby,
|
||||
})
|
||||
|
||||
return m, tea.Quit
|
||||
} else {
|
||||
m.reset()
|
||||
|
||||
Reference in New Issue
Block a user