go,tmpl: add a way to manage API keys [wip]
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2023-08-05 22:13:43 +02:00
parent 536b5909c8
commit 81ca7d8ec1
Signed by: wanderer
SSH Key Fingerprint: SHA256:MdCZyJ2sHLltrLBp0xQO0O1qTW9BT/xl5nXkDvhlMCI
4 changed files with 98 additions and 0 deletions

@ -56,6 +56,7 @@ func (a *App) SetupRoutes() error {
e.POST("/signup", handlers.SignupPost(a.db)) e.POST("/signup", handlers.SignupPost(a.db))
e.GET("/home", handlers.Home(a.db), compress) e.GET("/home", handlers.Home(a.db), compress)
e.GET("/manage/api-keys", handlers.ManageAPIKeys(), handlers.MiddlewareSession)
e.GET("/manage/users", handlers.ManageUsers(), handlers.MiddlewareSession) e.GET("/manage/users", handlers.ManageUsers(), handlers.MiddlewareSession)
e.GET("/manage/users/new", handlers.ManageUsers(), handlers.MiddlewareSession) e.GET("/manage/users/new", handlers.ManageUsers(), handlers.MiddlewareSession)
e.POST("/manage/users/create", handlers.CreateUser(), handlers.MiddlewareSession) e.POST("/manage/users/create", handlers.CreateUser(), handlers.MiddlewareSession)

@ -0,0 +1,39 @@
// Copyright 2023 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: AGPL-3.0-only
package handlers
import (
"net/http"
moduser "git.dotya.ml/mirre-mt/pcmt/modules/user"
"github.com/labstack/echo/v4"
)
func ManageAPIKeys() echo.HandlerFunc {
return func(c echo.Context) error {
addHeaders(c)
u := c.Get("sessUsr").(moduser.User)
err := c.Render(http.StatusOK, "manage/apikeys.tmpl",
page{
AppName: setting.AppName(),
AppVer: appver,
Title: "Manage API Keys",
DevelMode: setting.IsDevel(),
Current: "api-keys",
User: u,
},
)
if err != nil {
c.Logger().Errorf("error: %q", err)
return renderErrorPage(
c,
http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError),
err.Error(),
)
}
return nil
}
}

@ -0,0 +1,49 @@
{{ template "head.tmpl" . }}
<body class="h-screen bg-white dark:bg-gray-900">
{{ template "navbar.tmpl" . }}
<main class="grow">
<div class="px-2 md:px-0 md:mx-12 place-items-center text-center">
<h1 class="mt-20 text-2xl text-pink-500 font-bold">
Manage Your API keys
</h1>
{{ if and .Data .Data.flash }}
<hr class="md:px-14 md:mx-24">
<div class="relative flex items-center mb-4">
<p class="mt-2 text-md text-rose-800 dark:text-rose-500"><span class="font-medium">Error:</span> {{.Data.flash}}</p>
</div>
{{- else -}}{{end}}
<div class="mt-4 md:px-12 md:mx-12">
<!-- hibp form -->
<div class="mt-8 lg:max-w-xl lg:mt-0 block md:flex">
<h2 class="pr-8 text-purple-500 font-bold">
Have I Been Pwned? key
</h2>
<form method="post" class="w-full lg:max-w-xl md:mx-12">
<input type="hidden" name="csrf" value="{{- .CSRF -}}">
<div class="relative flex items-center place-items-center">
<input name="hibp-api-key" type="text" placeholder="Have I Been Pwned? API key" {{if and .Data.form .Data.form.HibpAPIKey}}value="{{.Data.form.HibpAPIKey}}"{{end}} autofocus class="block w-full py-3 px-11 valid:border text-gray-700 bg-white border rounded-lg dark:bg-gray-900 dark:text-gray-300 dark:valid:border-gray-600 focus:border-blue-400 dark:focus:border-blue-300 focus:ring-blue-300 focus:outline-none focus:ring focus:ring-opacity-40">
</div>
</form>
</div>
</div>
<hr class="mt-4 md:px-14 md:mx-24">
<div class="mt-4 md:px-12 md:mx-12">
<!-- desec form -->
<div class="mt-8 lg:max-w-xl lg:mt-0 block md:flex">
<h2 class="md:pr-8 text-purple-500 font-bold">
Desec.io key
</h2>
<form method="post" class="w-full lg:max-w-xl md:mx-12">
<input type="hidden" name="csrf" value="{{- .CSRF -}}">
<div class="relative flex items-center place-items-center">
<input name="desec-api-key" type="text" placeholder="desec.io API Key" {{if and .Data.form .Data.form.DesecioAPIKey}}value="{{.Data.form.DesecioAPIKey}}"{{end}} autofocus class="block w-full py-3 px-11 valid:border text-gray-700 bg-white border rounded-lg dark:bg-gray-900 dark:text-gray-300 dark:valid:border-gray-600 focus:border-blue-400 dark:focus:border-blue-300 focus:ring-blue-300 focus:outline-none focus:ring focus:ring-opacity-40">
</div>
</form>
</div>
</div>
</div>
</main>
{{ template "footer.tmpl" . }}

@ -33,6 +33,15 @@
User management User management
</a> </a>
</li> </li>
<li>
{{ if pageIs .Current "api-keys" }}
<a href="/manage/api-keys" class="block py-2 pl-3 pr-4 text-white bg-blue-500 rounded md:bg-transparent md:text-blue-700 md:p-0 md:dark:text-blue-500 dark:bg-blue-500 md:dark:bg-transparent" aria-current="page">
{{ else }}
<a href="/manage/api-keys" class="block py-2 pl-3 pr-4 text-gray-900 rounded hover:bg-gray-300 md:hover:bg-transparent md:border-0 md:hover:text-blue-500 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">
{{ end }}
API keys
</a>
</li>
{{end}} {{end}}
<li> <li>
<a href="#" class="block py-2 pl-3 pr-4 text-gray-900 rounded hover:bg-gray-300 md:hover:bg-transparent md:border-0 md:hover:text-blue-500 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">About</a> <a href="#" class="block py-2 pl-3 pr-4 text-gray-900 rounded hover:bg-gray-300 md:hover:bg-transparent md:border-0 md:hover:text-blue-500 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">About</a>