test tokens
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user