Initialize repository

This commit is contained in:
eikendev 2020-07-26 00:28:38 +02:00
commit 1d758fcfd0
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
28 changed files with 1107 additions and 0 deletions

30
authentication/context.go Normal file
View file

@ -0,0 +1,30 @@
package authentication
import (
"errors"
"net/http"
"github.com/eikendev/pushbits/model"
"github.com/gin-gonic/gin"
)
// GetApplication returns the application which was previously registered by the authentication middleware.
func GetApplication(ctx *gin.Context) *model.Application {
app, ok := ctx.MustGet("app").(*model.Application)
if app == nil || !ok {
ctx.AbortWithError(http.StatusInternalServerError, errors.New("an error occured while retrieving application from context"))
}
return app
}
// GetUser returns the user which was previously registered by the authentication middleware.
func GetUser(ctx *gin.Context) *model.User {
user, ok := ctx.MustGet("user").(*model.User)
if user == nil || !ok {
ctx.AbortWithError(http.StatusInternalServerError, errors.New("an error occured while retrieving user from context"))
}
return user
}