test tokens

This commit is contained in:
shoopea
2024-11-17 23:37:42 +01:00
parent 3bd57a4e98
commit 060933aa27
5 changed files with 418 additions and 17 deletions
+16 -8
View File
@@ -3,6 +3,7 @@ package main
import (
"context"
"embed"
"fmt"
"html/template"
"io/fs"
"net/http"
@@ -20,6 +21,7 @@ type AdminConfig struct {
Users []*User `json:"users"`
Secrets *SecretsConfig `json:"secrets"`
Addr string `json:"addr"`
URL string `json:"url"`
}
type SecretsConfig struct {
@@ -42,6 +44,7 @@ func NewAdmin() *AdminConfig {
Addr: "0.0.0.0:8080",
Secrets: NewSecrets(),
Users: make([]*User, 0),
URL: "https://backup.example.com/",
}
return a
@@ -100,12 +103,6 @@ func (a *AdminConfig) Run() {
r.GET("/", HttpAnyIndex)
r.POST("/", HttpAnyIndex)
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
r.GET("/run", func(c *gin.Context) {
cfg.Run()
c.JSON(http.StatusOK, gin.H{
@@ -148,8 +145,7 @@ func (a *AdminConfig) Run() {
protected.GET("home", HttpAnyHome)
unprotected := r.Group("u", HttpNoAuth())
unprotected.GET("signin", HttpAnySignIn)
unprotected.POST("signin", HttpAnySignIn)
unprotected.POST("submit", HttpPostSubmit)
unprotected.GET("recover", HttpGetRecover)
srv := &http.Server{
@@ -186,3 +182,15 @@ func (a *AdminConfig) Run() {
}
}
func FindUserID(user string) (uint64, error) {
log.WithFields(log.Fields{}).Debugf("starting")
defer log.WithFields(log.Fields{}).Debugf("done")
for _, v := range cfg.Admin.Users {
if v.Username == user {
return v.ID, nil
}
}
return 0, fmt.Errorf("no user")
}