mirror of
https://github.com/pushbits/server.git
synced 2025-06-10 14:42:01 +02:00
Initialize repository
This commit is contained in:
commit
1d758fcfd0
28 changed files with 1107 additions and 0 deletions
30
authentication/context.go
Normal file
30
authentication/context.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue