aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/admin
diff options
context:
space:
mode:
Diffstat (limited to 'backend/admin')
-rw-r--r--backend/admin/handler.go42
-rw-r--r--backend/admin/templates/base.html6
-rw-r--r--backend/admin/templates/dashboard.html10
-rw-r--r--backend/admin/templates/game_edit.html4
-rw-r--r--backend/admin/templates/games.html2
-rw-r--r--backend/admin/templates/online_qualifying_ranking.html2
-rw-r--r--backend/admin/templates/user_edit.html2
-rw-r--r--backend/admin/templates/users.html2
8 files changed, 34 insertions, 36 deletions
diff --git a/backend/admin/handler.go b/backend/admin/handler.go
index 81ea2b7..f7fd63e 100644
--- a/backend/admin/handler.go
+++ b/backend/admin/handler.go
@@ -14,33 +14,31 @@ import (
"github.com/nsfisis/phperkaigi-2025-albatross/backend/account"
"github.com/nsfisis/phperkaigi-2025-albatross/backend/auth"
+ "github.com/nsfisis/phperkaigi-2025-albatross/backend/config"
"github.com/nsfisis/phperkaigi-2025-albatross/backend/db"
)
-const (
- basePath = "/phperkaigi/2025/code-battle"
-)
-
var jst = time.FixedZone("Asia/Tokyo", 9*60*60)
type Handler struct {
- q *db.Queries
+ q *db.Queries
+ conf *config.Config
}
-func NewHandler(q *db.Queries) *Handler {
- return &Handler{q: q}
+func NewHandler(q *db.Queries, conf *config.Config) *Handler {
+ return &Handler{q: q, conf: conf}
}
-func newAdminMiddleware() echo.MiddlewareFunc {
+func (h *Handler) newAdminMiddleware() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
jwt, err := c.Cookie("albatross_token")
if err != nil {
- return c.Redirect(http.StatusSeeOther, basePath+"/login")
+ return c.Redirect(http.StatusSeeOther, h.conf.BasePath+"login")
}
claims, err := auth.ParseJWT(jwt.Value)
if err != nil {
- return c.Redirect(http.StatusSeeOther, basePath+"/login")
+ return c.Redirect(http.StatusSeeOther, h.conf.BasePath+"login")
}
if !claims.IsAdmin {
return echo.NewHTTPError(http.StatusForbidden)
@@ -52,7 +50,7 @@ func newAdminMiddleware() echo.MiddlewareFunc {
func (h *Handler) RegisterHandlers(g *echo.Group) {
g.Use(newAssetsMiddleware())
- g.Use(newAdminMiddleware())
+ g.Use(h.newAdminMiddleware())
g.GET("/dashboard", h.getDashboard)
g.GET("/users", h.getUsers)
@@ -69,7 +67,7 @@ func (h *Handler) RegisterHandlers(g *echo.Group) {
func (h *Handler) getDashboard(c echo.Context) error {
return c.Render(http.StatusOK, "dashboard", echo.Map{
- "BasePath": basePath,
+ "BasePath": h.conf.BasePath,
"Title": "Dashboard",
})
}
@@ -91,7 +89,7 @@ func (h *Handler) getUsers(c echo.Context) error {
}
return c.Render(http.StatusOK, "users", echo.Map{
- "BasePath": basePath,
+ "BasePath": h.conf.BasePath,
"Title": "Users",
"Users": users,
})
@@ -111,7 +109,7 @@ func (h *Handler) getUserEdit(c echo.Context) error {
}
return c.Render(http.StatusOK, "user_edit", echo.Map{
- "BasePath": basePath,
+ "BasePath": h.conf.BasePath,
"Title": "User Edit",
"User": echo.Map{
"UserID": row.UserID,
@@ -155,7 +153,7 @@ func (h *Handler) postUserEdit(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
- return c.Redirect(http.StatusSeeOther, basePath+"/admin/users")
+ return c.Redirect(http.StatusSeeOther, h.conf.BasePath+"admin/users")
}
func (h *Handler) postUserFetchIcon(c echo.Context) error {
@@ -177,7 +175,7 @@ func (h *Handler) postUserFetchIcon(c echo.Context) error {
// The failure is intentionally ignored. Retry manually if needed.
}
}()
- return c.Redirect(http.StatusSeeOther, basePath+"/admin/users")
+ return c.Redirect(http.StatusSeeOther, h.conf.BasePath+"admin/users")
}
func (h *Handler) getGames(c echo.Context) error {
@@ -203,7 +201,7 @@ func (h *Handler) getGames(c echo.Context) error {
}
return c.Render(http.StatusOK, "games", echo.Map{
- "BasePath": basePath,
+ "BasePath": h.conf.BasePath,
"Title": "Games",
"Games": games,
})
@@ -257,7 +255,7 @@ func (h *Handler) getGameEdit(c echo.Context) error {
}
return c.Render(http.StatusOK, "game_edit", echo.Map{
- "BasePath": basePath,
+ "BasePath": h.conf.BasePath,
"Title": "Game Edit",
"Game": echo.Map{
"GameID": row.GameID,
@@ -367,7 +365,7 @@ func (h *Handler) postGameEdit(c echo.Context) error {
}
}
- return c.Redirect(http.StatusSeeOther, basePath+"/admin/games")
+ return c.Redirect(http.StatusSeeOther, h.conf.BasePath+"admin/games")
}
func (h *Handler) postGameStart(c echo.Context) error {
@@ -389,7 +387,7 @@ func (h *Handler) postGameStart(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
- return c.Redirect(http.StatusSeeOther, basePath+"/admin/games")
+ return c.Redirect(http.StatusSeeOther, h.conf.BasePath+"admin/games")
}
func (h *Handler) getOnlineQualifyingRanking(c echo.Context) error {
@@ -424,7 +422,7 @@ func (h *Handler) getOnlineQualifyingRanking(c echo.Context) error {
}
}
return c.Render(http.StatusOK, "online_qualifying_ranking", echo.Map{
- "BasePath": basePath,
+ "BasePath": h.conf.BasePath,
"Title": "Online Qualifying Ranking",
"Entries": entries,
})
@@ -464,5 +462,5 @@ func (h *Handler) postFix(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
}
- return c.Redirect(http.StatusSeeOther, basePath+"/admin/dashboard")
+ return c.Redirect(http.StatusSeeOther, h.conf.BasePath+"admin/dashboard")
}
diff --git a/backend/admin/templates/base.html b/backend/admin/templates/base.html
index 08c7dc5..653acc6 100644
--- a/backend/admin/templates/base.html
+++ b/backend/admin/templates/base.html
@@ -2,9 +2,9 @@
<html>
<head>
<title>ADMIN {{ .Title }} | PHPerKaigi 2025 Albatross</title>
- <link rel="icon" href="{{ .BasePath }}/favicon.svg">
- <link rel="stylesheet" href="{{ .BasePath }}/admin/css/normalize.css">
- <link rel="stylesheet" href="{{ .BasePath }}/admin/css/sakura.css">
+ <link rel="icon" href="{{ .BasePath }}favicon.svg">
+ <link rel="stylesheet" href="{{ .BasePath }}admin/css/normalize.css">
+ <link rel="stylesheet" href="{{ .BasePath }}admin/css/sakura.css">
</head>
<body>
<section>
diff --git a/backend/admin/templates/dashboard.html b/backend/admin/templates/dashboard.html
index 92133b6..dcc71ba 100644
--- a/backend/admin/templates/dashboard.html
+++ b/backend/admin/templates/dashboard.html
@@ -2,18 +2,18 @@
{{ define "content" }}
<p>
- <a href="{{ .BasePath }}/admin/users">Users</a>
+ <a href="{{ .BasePath }}admin/users">Users</a>
</p>
<p>
- <a href="{{ .BasePath }}/admin/games">Games</a>
+ <a href="{{ .BasePath }}admin/games">Games</a>
</p>
<p>
- <a href="{{ .BasePath }}/admin/online-qualifying-ranking?game_1=7&game_2=8">Online Qualifying Ranking</a>
+ <a href="{{ .BasePath }}admin/online-qualifying-ranking?game_1=7&game_2=8">Online Qualifying Ranking</a>
</p>
-<form method="post" action="{{ .BasePath }}/admin/fix">
+<form method="post" action="{{ .BasePath }}admin/fix">
<button type="submit">fix</button>
</form>
-<form method="post" action="{{ .BasePath }}/logout">
+<form method="post" action="{{ .BasePath }}logout">
<button type="submit">Logout</button>
</form>
{{ end }}
diff --git a/backend/admin/templates/game_edit.html b/backend/admin/templates/game_edit.html
index 0d92c95..2d769c4 100644
--- a/backend/admin/templates/game_edit.html
+++ b/backend/admin/templates/game_edit.html
@@ -1,7 +1,7 @@
{{ template "base.html" . }}
{{ define "breadcrumb" }}
-<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a> | <a href="{{ .BasePath }}/admin/games">Games</a>
+<a href="{{ .BasePath }}admin/dashboard">Dashboard</a> | <a href="{{ .BasePath }}admin/games">Games</a>
{{ end }}
{{ define "content" }}
@@ -59,7 +59,7 @@
<button type="submit">Save</button>
</div>
<div>
- <button type="submit" formaction="{{ .BasePath }}/admin/games/{{ .Game.GameID }}/start">Start</button>
+ <button type="submit" formaction="{{ .BasePath }}admin/games/{{ .Game.GameID }}/start">Start</button>
</div>
</form>
{{ end }}
diff --git a/backend/admin/templates/games.html b/backend/admin/templates/games.html
index 3be6726..b5c512a 100644
--- a/backend/admin/templates/games.html
+++ b/backend/admin/templates/games.html
@@ -1,7 +1,7 @@
{{ template "base.html" . }}
{{ define "breadcrumb" }}
-<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a>
+<a href="{{ .BasePath }}admin/dashboard">Dashboard</a>
{{ end }}
{{ define "content" }}
diff --git a/backend/admin/templates/online_qualifying_ranking.html b/backend/admin/templates/online_qualifying_ranking.html
index 039687e..663b68e 100644
--- a/backend/admin/templates/online_qualifying_ranking.html
+++ b/backend/admin/templates/online_qualifying_ranking.html
@@ -1,7 +1,7 @@
{{ template "base.html" . }}
{{ define "breadcrumb" }}
-<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a>
+<a href="{{ .BasePath }}admin/dashboard">Dashboard</a>
{{ end }}
{{ define "content" }}
diff --git a/backend/admin/templates/user_edit.html b/backend/admin/templates/user_edit.html
index 6942204..4c1016b 100644
--- a/backend/admin/templates/user_edit.html
+++ b/backend/admin/templates/user_edit.html
@@ -1,7 +1,7 @@
{{ template "base.html" . }}
{{ define "breadcrumb" }}
-<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a> | <a href="{{ .BasePath }}/admin/users">Users</a>
+<a href="{{ .BasePath }}admin/dashboard">Dashboard</a> | <a href="{{ .BasePath }}admin/users">Users</a>
{{ end }}
{{ define "content" }}
diff --git a/backend/admin/templates/users.html b/backend/admin/templates/users.html
index 36fae0d..4b8e6dc 100644
--- a/backend/admin/templates/users.html
+++ b/backend/admin/templates/users.html
@@ -1,7 +1,7 @@
{{ template "base.html" . }}
{{ define "breadcrumb" }}
-<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a>
+<a href="{{ .BasePath }}admin/dashboard">Dashboard</a>
{{ end }}
{{ define "content" }}