blob: a1d1bbfd56363e73d4e575445e2231df04abe8a6 (
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
35
36
37
|
package dashboard
import (
"net/http"
"github.com/xlgmokha/x/pkg/log"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/middleware"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/views"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key"
)
type Controller struct {
}
func New() *Controller {
return &Controller{}
}
func (c *Controller) MountTo(mux *http.ServeMux) {
requireUser := middleware.RequireUser(http.StatusFound, "/")
mux.Handle("GET /dashboard", requireUser(http.HandlerFunc(c.Show)))
}
func (c *Controller) Show(w http.ResponseWriter, r *http.Request) {
currentUser := key.CurrentUser.From(r.Context())
w.WriteHeader(http.StatusOK)
w.Header().Add("Content-Type", "text/html")
dto := &ViewDashboardDTO{CurrentUser: currentUser}
if err := views.Render(w, "dashboard/show", dto); err != nil {
log.WithFields(r.Context(), log.Fields{"error": err})
w.WriteHeader(http.StatusInternalServerError)
return
}
}
|