pushbits/internal/api/util.go
eikendev d7721e827b
Add option to enforce strict compatibility
Some plugins check for token length. Since PushBits uses longer tokens by default for better security, these plugins are
incompatible. With this patch, users can decide if they want an application to have a short token, so that said plugins
can talk to PushBits again.
2021-02-08 00:34:33 +01:00

32 lines
545 B
Go

package api
import (
"errors"
"net/http"
"github.com/pushbits/server/internal/authentication"
"github.com/gin-gonic/gin"
)
func successOrAbort(ctx *gin.Context, code int, err error) bool {
if err != nil {
ctx.AbortWithError(code, err)
}
return err == nil
}
func isCurrentUser(ctx *gin.Context, ID uint) bool {
user := authentication.GetUser(ctx)
if user == nil {
return false
}
if user.ID != ID {
ctx.AbortWithError(http.StatusForbidden, errors.New("only owner can delete application"))
return false
}
return true
}