summaryrefslogtreecommitdiff
path: root/app/controllers/dashboard/controller.go
blob: cd1c44f8b756e2b6e445e637f2ec2403631c9f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package dashboard

import (
	"net/http"

	"github.com/xlgmokha/x/pkg/context"
	"github.com/xlgmokha/x/pkg/x"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain"
)

var CurrentUserKey context.Key[*domain.User] = context.Key[*domain.User]("current_user")

type Controller struct {
}

func New() *Controller {
	return &Controller{}
}

func (c *Controller) MountTo(mux *http.ServeMux) {
	mux.HandleFunc("GET /dashboard", c.Show)
}

func (c *Controller) Show(w http.ResponseWriter, r *http.Request) {
	currentUser := CurrentUserKey.From(r.Context())

	if x.IsZero(currentUser) {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Header().Add("Content-Type", "text/html")
}