Enhance project functionality: add email template, implement email sending, and improve table management routes

Also add qr code generation route

The table management in the database does currently not work
This commit is contained in:
Jonas Hahn
2025-08-25 16:43:24 +02:00
parent a1cba9c4eb
commit 01132e1968
4 changed files with 26 additions and 0 deletions

View File

@@ -82,6 +82,7 @@ func main() {
r.GET("/login", getLogin)
r.POST("/login", postLogin)
r.GET("/magic", getMagic)
r.GET("/qr/:qrSlug", getQr)
authorized := r.Group("/")
authorized.Use(RequireAuthMiddleware())

View File

@@ -7,12 +7,16 @@ import (
"errors"
"html/template"
"log"
"net/http"
"os"
"strings"
"time"
"github.com/gin-gonic/gin"
"gopkg.in/gomail.v2"
"github.com/skip2/go-qrcode"
)
func mustRandToken(n int) string {
@@ -178,3 +182,21 @@ func sendEmail(email string, token string) error {
}
return nil
}
func getQr(c *gin.Context) {
slug := c.Param("qrSlug")
var url string
if slug == "" {
url = "http://localhost:18765"
} else {
url = "http://localhost:18765/table/" + slug
}
png, err := qrcode.Encode(url, qrcode.Medium, 256)
if err != nil {
c.String(http.StatusInternalServerError, "could not generate QR")
return
}
c.Data(http.StatusOK, "image/png", png)
}