mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-09 12:59:38 +00:00
add index page and button to generate random inbox
This commit is contained in:
parent
c0c1ba4c08
commit
95252f12f5
@ -1,5 +1,22 @@
|
||||
package main
|
||||
|
||||
templ index(appname string) {
|
||||
<h1>Home for { appname }</h1>
|
||||
templ index_page() {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>nthmail.xyz</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1"/>
|
||||
<meta name="description" content="A temporary mail service"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>nthmail.xyz</h1>
|
||||
<p>
|
||||
A disposable, temporary and private mail address!
|
||||
</p>
|
||||
<form action="random" >
|
||||
<button type="submit">Get one now!</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/GRFreire/nthmail/pkg/rig"
|
||||
"github.com/go-chi/chi"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
@ -27,11 +28,23 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
domain, exists := os.LookupEnv("MAIL_SERVER_DOMAIN")
|
||||
if !exists {
|
||||
domain = "localhost"
|
||||
}
|
||||
|
||||
router := chi.NewRouter()
|
||||
|
||||
router.Get("/", func(res http.ResponseWriter, req *http.Request) {
|
||||
component := index("nthmail.xyz")
|
||||
component.Render(req.Context(), res)
|
||||
page := index_page()
|
||||
page.Render(req.Context(), res)
|
||||
})
|
||||
|
||||
router.Get("/random", func(res http.ResponseWriter, req *http.Request) {
|
||||
inbox_name := rig.GenerateRandomInboxName()
|
||||
inbox_addr := fmt.Sprintf("/%s@%s", inbox_name, domain)
|
||||
|
||||
http.Redirect(res, req, inbox_addr, 307)
|
||||
})
|
||||
|
||||
router.Get("/{rcpt-addr}", func(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
1619
pkg/rig/dict.go
Normal file
1619
pkg/rig/dict.go
Normal file
File diff suppressed because it is too large
Load Diff
14
pkg/rig/rig.go
Normal file
14
pkg/rig/rig.go
Normal file
@ -0,0 +1,14 @@
|
||||
package rig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
func GenerateRandomInboxName() string {
|
||||
animal := animals[rand.Intn(len(animals))]
|
||||
color := colors[rand.Intn(len(colors))]
|
||||
adjective := adjectives[rand.Intn(len(adjectives))]
|
||||
|
||||
return fmt.Sprintf("%s-%s-%s", adjective, color, animal)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user