mirror of
https://github.com/pushbits/server.git
synced 2025-04-30 02:36:53 +02:00
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.
32 lines
545 B
Go
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
|
|
}
|