mirror of
https://github.com/mautrix/telegram.git
synced 2026-05-17 07:25:46 +03:00
legacyprovisioning: fix getting user ID from request
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -174,10 +174,7 @@ func legacyProvLoginRequestCode(w http.ResponseWriter, r *http.Request) {
|
||||
exhttp.WriteJSONResponse(w, http.StatusInternalServerError, resp.WithError("unexpected_step", fmt.Sprintf("Unexpected step %s", nextStep.StepID)))
|
||||
} else {
|
||||
inflightLegacyLoginsLock.Lock()
|
||||
inflightLegacyLogins[user.MXID] = &legacyLogin{
|
||||
Process: loginProcess,
|
||||
NextStep: nextStep,
|
||||
}
|
||||
inflightLegacyLogins[user.MXID] = &legacyLogin{Process: loginProcess, NextStep: nextStep}
|
||||
inflightLegacyLoginsLock.Unlock()
|
||||
exhttp.WriteJSONResponse(w, http.StatusOK, resp.
|
||||
WithState("code").
|
||||
@@ -207,10 +204,7 @@ func legacyProvLoginSendCode(w http.ResponseWriter, r *http.Request) {
|
||||
} else if nextStep.StepID == connector.LoginStepIDPassword {
|
||||
inflightLegacyLoginsLock.Lock()
|
||||
defer inflightLegacyLoginsLock.Unlock()
|
||||
inflightLegacyLogins[user.MXID] = &legacyLogin{
|
||||
Process: inflightLogin.Process,
|
||||
NextStep: nextStep,
|
||||
}
|
||||
inflightLegacyLogins[user.MXID].NextStep = nextStep
|
||||
exhttp.WriteJSONResponse(w, http.StatusAccepted, resp.
|
||||
WithState("password").
|
||||
WithMessage("Code accepted, but you have 2-factor authentication enabled. Please enter your password."),
|
||||
@@ -248,7 +242,7 @@ func legacyProvLoginSendPassword(w http.ResponseWriter, r *http.Request) {
|
||||
} else if nextStep, err := inflightLogin.Process.(bridgev2.LoginProcessUserInput).SubmitUserInput(ctx, map[string]string{connector.LoginStepIDPassword: password}); err != nil {
|
||||
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 {
|
||||
exhttp.WriteJSONResponse(w, http.StatusOK, resp.WithState("logged-in"))
|
||||
exhttp.WriteJSONResponse(w, http.StatusOK, resp.WithState("logged-in").WithMessage(nextStep.Instructions))
|
||||
} else {
|
||||
exhttp.WriteJSONResponse(w, http.StatusInternalServerError, resp.WithError("unexpected_step", fmt.Sprintf("Unexpected step %s", nextStep.StepID)))
|
||||
}
|
||||
|
||||
@@ -23,10 +23,12 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"go.mau.fi/util/dbutil/litestream"
|
||||
"go.mau.fi/util/exerrors"
|
||||
"maunium.net/go/mautrix/bridgev2/bridgeconfig"
|
||||
"maunium.net/go/mautrix/bridgev2/matrix/mxmain"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/connector"
|
||||
"go.mau.fi/mautrix-telegram/pkg/connector/store/upgrades"
|
||||
@@ -77,6 +79,9 @@ func main() {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
m.Matrix.Provisioning.GetUserIDFromRequest = func(r *http.Request) id.UserID {
|
||||
return id.UserID(mux.Vars(r)["userID"])
|
||||
}
|
||||
m.Matrix.Provisioning.Router.HandleFunc("/v1/user/{userID}/login/qr", legacyProvLoginQR)
|
||||
m.Matrix.Provisioning.Router.HandleFunc("/v1/user/{userID}/login/request_code", legacyProvLoginRequestCode)
|
||||
m.Matrix.Provisioning.Router.HandleFunc("/v1/user/{userID}/login/send_code", legacyProvLoginSendCode)
|
||||
|
||||
Reference in New Issue
Block a user