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:
1
go.mod
1
go.mod
@@ -33,6 +33,7 @@ require (
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
golang.org/x/arch v0.16.0 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -83,6 +83,8 @@ github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
|
||||
@@ -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