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
|
||||
// and returns the user ID it corresponds to. Returns err if there was a fatal problem checking
|
||||
// the token. Returns resErr (an error response which can be sent to the client) if the token is invalid.
|
||||
func VerifyAccessToken(req *http.Request) (userID string, resErr *util.JSONResponse, err error) {
|
||||
// and returns the user ID it corresponds to. Returns resErr (an error response which can be
|
||||
// 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) {
|
||||
token, tokenErr := extractAccessToken(req)
|
||||
if tokenErr != nil {
|
||||
resErr = &util.JSONResponse{
|
||||
|
|
@ -22,7 +22,8 @@ func VerifyAccessToken(req *http.Request) (userID string, resErr *util.JSONRespo
|
|||
return
|
||||
}
|
||||
if token == "fail" {
|
||||
err = fmt.Errorf("Fatal error")
|
||||
res := util.ErrorResponse(fmt.Errorf("Fatal error"))
|
||||
resErr = &res
|
||||
}
|
||||
// TODO: Check the token against the database
|
||||
return
|
||||
|
|
|
|||
|
|
@ -4,18 +4,13 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// Sync implements /sync
|
||||
func Sync(req *http.Request) util.JSONResponse {
|
||||
logger := util.GetLogger(req.Context())
|
||||
userID, resErr, err := auth.VerifyAccessToken(req)
|
||||
if err != nil {
|
||||
logger.WithError(err).Error("Failed to verify access token")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
userID, resErr := auth.VerifyAccessToken(req)
|
||||
if resErr != nil {
|
||||
return *resErr
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,18 +5,13 @@ import (
|
|||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// SendMessage implements /rooms/{roomID}/send/{eventType}
|
||||
func SendMessage(req *http.Request, roomID, eventType string) util.JSONResponse {
|
||||
logger := util.GetLogger(req.Context())
|
||||
userID, resErr, err := auth.VerifyAccessToken(req)
|
||||
if err != nil {
|
||||
logger.WithError(err).Error("Failed to verify access token")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
userID, resErr := auth.VerifyAccessToken(req)
|
||||
if resErr != nil {
|
||||
return *resErr
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue