legacyprovisioning: fix reconnect
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"go.mau.fi/util/exhttp"
|
"go.mau.fi/util/exhttp"
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
|
"maunium.net/go/mautrix/bridge/status"
|
||||||
"maunium.net/go/mautrix/bridgev2"
|
"maunium.net/go/mautrix/bridgev2"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
@@ -136,6 +137,7 @@ func legacyProvLoginQR(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
case connector.LoginStepIDComplete:
|
case connector.LoginStepIDComplete:
|
||||||
ws.WriteJSON(map[string]any{"success": true})
|
ws.WriteJSON(map[string]any{"success": true})
|
||||||
|
go handleLoginComplete(ctx, user, nextStep.CompleteParams.UserLogin)
|
||||||
return
|
return
|
||||||
case connector.LoginStepIDPassword:
|
case connector.LoginStepIDPassword:
|
||||||
inflightLegacyLoginsLock.Lock()
|
inflightLegacyLoginsLock.Lock()
|
||||||
@@ -216,6 +218,7 @@ func legacyProvLoginSendCode(w http.ResponseWriter, r *http.Request) {
|
|||||||
return // Don't delete the inflight login yet, we need to submit the password.
|
return // Don't delete the inflight login yet, we need to submit the password.
|
||||||
} else if nextStep.StepID == connector.LoginStepIDComplete {
|
} else if nextStep.StepID == connector.LoginStepIDComplete {
|
||||||
exhttp.WriteJSONResponse(w, http.StatusOK, resp.WithState("logged-in"))
|
exhttp.WriteJSONResponse(w, http.StatusOK, resp.WithState("logged-in"))
|
||||||
|
go handleLoginComplete(ctx, user, nextStep.CompleteParams.UserLogin)
|
||||||
} else {
|
} else {
|
||||||
exhttp.WriteJSONResponse(w, http.StatusInternalServerError, resp.WithError("unexpected_step", fmt.Sprintf("Unexpected step %s", nextStep.StepID)))
|
exhttp.WriteJSONResponse(w, http.StatusInternalServerError, resp.WithError("unexpected_step", fmt.Sprintf("Unexpected step %s", nextStep.StepID)))
|
||||||
}
|
}
|
||||||
@@ -247,6 +250,7 @@ func legacyProvLoginSendPassword(w http.ResponseWriter, r *http.Request) {
|
|||||||
exhttp.WriteJSONResponse(w, http.StatusBadRequest, resp.WithError("send_password_failed", fmt.Sprintf("Failed to send password: %s", err.Error())))
|
exhttp.WriteJSONResponse(w, http.StatusBadRequest, resp.WithError("send_password_failed", fmt.Sprintf("Failed to send password: %s", err.Error())))
|
||||||
} else if nextStep.StepID == connector.LoginStepIDComplete {
|
} else if nextStep.StepID == connector.LoginStepIDComplete {
|
||||||
exhttp.WriteJSONResponse(w, http.StatusOK, resp.WithState("logged-in").WithMessage(nextStep.Instructions))
|
exhttp.WriteJSONResponse(w, http.StatusOK, resp.WithState("logged-in").WithMessage(nextStep.Instructions))
|
||||||
|
go handleLoginComplete(ctx, user, nextStep.CompleteParams.UserLogin)
|
||||||
} else {
|
} else {
|
||||||
exhttp.WriteJSONResponse(w, http.StatusInternalServerError, resp.WithError("unexpected_step", fmt.Sprintf("Unexpected step %s", nextStep.StepID)))
|
exhttp.WriteJSONResponse(w, http.StatusInternalServerError, resp.WithError("unexpected_step", fmt.Sprintf("Unexpected step %s", nextStep.StepID)))
|
||||||
}
|
}
|
||||||
@@ -260,13 +264,27 @@ func legacyProvLoginSendPassword(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func legacyProvLogout(w http.ResponseWriter, r *http.Request) {
|
func legacyProvLogout(w http.ResponseWriter, r *http.Request) {
|
||||||
user := m.Matrix.Provisioning.GetUser(r)
|
user := m.Matrix.Provisioning.GetUser(r)
|
||||||
|
resp := response{Username: user.MXID}
|
||||||
logins := user.GetUserLogins()
|
logins := user.GetUserLogins()
|
||||||
|
if len(logins) == 0 {
|
||||||
|
exhttp.WriteJSONResponse(w, http.StatusOK, resp.WithError("not logged in", "You're not logged in"))
|
||||||
|
return
|
||||||
|
}
|
||||||
for _, login := range logins {
|
for _, login := range logins {
|
||||||
login.Logout(r.Context())
|
login.Client.(*connector.TelegramClient).LogoutRemote(r.Context())
|
||||||
}
|
}
|
||||||
exhttp.WriteEmptyJSONResponse(w, http.StatusOK)
|
exhttp.WriteEmptyJSONResponse(w, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleLoginComplete(ctx context.Context, user *bridgev2.User, newLogin *bridgev2.UserLogin) {
|
||||||
|
allLogins := user.GetUserLogins()
|
||||||
|
for _, login := range allLogins {
|
||||||
|
if login.ID != newLogin.ID {
|
||||||
|
login.Delete(ctx, status.BridgeState{StateEvent: status.StateLoggedOut, Reason: "LOGIN_OVERRIDDEN"}, bridgev2.DeleteOpts{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func legacyProvContacts(w http.ResponseWriter, r *http.Request) {
|
func legacyProvContacts(w http.ResponseWriter, r *http.Request) {
|
||||||
log := zerolog.Ctx(r.Context()).With().
|
log := zerolog.Ctx(r.Context()).With().
|
||||||
Str("prov_method", "contacts").
|
Str("prov_method", "contacts").
|
||||||
|
|||||||
Reference in New Issue
Block a user