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:
@@ -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())
|
||||
|
||||
22
src/utils.go
22
src/utils.go
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user