mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 06:53:09 -06:00
Revert back to 2-value returns
This commit is contained in:
parent
4137b6185d
commit
65bb41ca5e
|
|
@ -10,9 +10,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// VerifyAccessToken verifies that an access token was supplied in the given HTTP request
|
// VerifyAccessToken verifies that an access token was supplied in the given HTTP request
|
||||||
// and returns the user ID it corresponds to. Returns err if there was a fatal problem checking
|
// and returns the user ID it corresponds to. Returns resErr (an error response which can be
|
||||||
// the token. Returns resErr (an error response which can be sent to the client) if the token is invalid.
|
// sent to the client) if the token is invalid or there was a problem querying the database.
|
||||||
func VerifyAccessToken(req *http.Request) (userID string, resErr *util.JSONResponse, err error) {
|
func VerifyAccessToken(req *http.Request) (userID string, resErr *util.JSONResponse) {
|
||||||
token, tokenErr := extractAccessToken(req)
|
token, tokenErr := extractAccessToken(req)
|
||||||
if tokenErr != nil {
|
if tokenErr != nil {
|
||||||
resErr = &util.JSONResponse{
|
resErr = &util.JSONResponse{
|
||||||
|
|
@ -22,7 +22,8 @@ func VerifyAccessToken(req *http.Request) (userID string, resErr *util.JSONRespo
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if token == "fail" {
|
if token == "fail" {
|
||||||
err = fmt.Errorf("Fatal error")
|
res := util.ErrorResponse(fmt.Errorf("Fatal error"))
|
||||||
|
resErr = &res
|
||||||
}
|
}
|
||||||
// TODO: Check the token against the database
|
// TODO: Check the token against the database
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,13 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth"
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sync implements /sync
|
// Sync implements /sync
|
||||||
func Sync(req *http.Request) util.JSONResponse {
|
func Sync(req *http.Request) util.JSONResponse {
|
||||||
logger := util.GetLogger(req.Context())
|
logger := util.GetLogger(req.Context())
|
||||||
userID, resErr, err := auth.VerifyAccessToken(req)
|
userID, resErr := auth.VerifyAccessToken(req)
|
||||||
if err != nil {
|
|
||||||
logger.WithError(err).Error("Failed to verify access token")
|
|
||||||
return jsonerror.InternalServerError()
|
|
||||||
}
|
|
||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,13 @@ import (
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth"
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SendMessage implements /rooms/{roomID}/send/{eventType}
|
// SendMessage implements /rooms/{roomID}/send/{eventType}
|
||||||
func SendMessage(req *http.Request, roomID, eventType string) util.JSONResponse {
|
func SendMessage(req *http.Request, roomID, eventType string) util.JSONResponse {
|
||||||
logger := util.GetLogger(req.Context())
|
logger := util.GetLogger(req.Context())
|
||||||
userID, resErr, err := auth.VerifyAccessToken(req)
|
userID, resErr := auth.VerifyAccessToken(req)
|
||||||
if err != nil {
|
|
||||||
logger.WithError(err).Error("Failed to verify access token")
|
|
||||||
return jsonerror.InternalServerError()
|
|
||||||
}
|
|
||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue