48 lines
936 B
Go
48 lines
936 B
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type Permission int
|
|
|
|
const (
|
|
Start Permission = 1 << iota
|
|
Stop
|
|
Browse
|
|
Create
|
|
Delete
|
|
RunCommand
|
|
Admin
|
|
)
|
|
|
|
type User struct {
|
|
Username string `json:"username"`
|
|
Email string `json:"email"`
|
|
MaxOwnedServers int `json:"maxed_owned_servers"`
|
|
Permissions []string `json:"permissions"`
|
|
HashedPass string `json:"HashedPass"`
|
|
}
|
|
|
|
type Connection struct {
|
|
connection *mongo.Client
|
|
}
|
|
|
|
func (con Connection) AuthorizedTo(requiredPermissions Permission) gin.HandlerFunc {
|
|
return func(ctx *gin.Context) {
|
|
authCookie, err := ctx.Request.Cookie("auth")
|
|
if err != nil {
|
|
ctx http.Response{
|
|
Status: "403",
|
|
Body: "Authorization Required",
|
|
}
|
|
}
|
|
con.connection.Database("Backend").Collection("users").Find(context.TODO(), bson.D{})
|
|
}
|
|
}
|