containerized; first fixes; html templates added

This commit is contained in:
$(pass /github/name)
2024-07-03 21:27:50 +02:00
parent 96f008d67e
commit 905a0ac6dc
13 changed files with 342 additions and 14 deletions

5
.gitignore vendored
View File

@@ -35,6 +35,7 @@ go.work
!/.gitignore
!*.go
!*.html
!go.sum
!go.mod
@@ -43,6 +44,10 @@ go.work
# all template files:
!*.template*
# Docker stuff
!compose.yml
!Dockerfile
# !Makefile
# ...even if they are in subdirectories

32
Dockerfile Normal file
View File

@@ -0,0 +1,32 @@
# Stage 1: Build the binary
FROM golang:alpine AS builder
LABEL maintainer="Alex Stölting <alex-gomembership@gar-nich.net>"
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# Copy the source code into the container
COPY . .
ENV CGO_ENABLED=1
RUN apk add --no-cache gcc musl-dev
# Build the Go app
RUN go build -o main ./cmd/membership
FROM golang:alpine
# Set the Current Working Directory inside the container
WORKDIR /root/
# Copy the Pre-built binary file from the builder stage
COPY --from=builder /app/main .
# Expose port 8080 to the outside world
EXPOSE 8080
# Command to run the executable
CMD ["./main"]

View File

@@ -1,8 +1,12 @@
package main
import "GoMembership/internal/server"
import (
"GoMembership/internal/server"
"log"
)
func main() {
log.Println("startup...")
server.Run()
}

10
compose.yml Normal file
View File

@@ -0,0 +1,10 @@
services:
app:
build: .
container_name: carsharingBackend
ports:
- "8080:8080"
volumes:
- ./configs/config.json:/root/configs/config.json:ro
- ./data/db.sqlite3:/root/data/db.sqlite3
- ./templates:/root/templates:ro

View File

@@ -9,5 +9,8 @@
"Port": 465,
"Mailtype": "html",
"AdminEmail": "admin@server.com"
},
"templates": {
"MailDir": "templates"
}
}

View File

@@ -27,10 +27,14 @@ type SMTPConfig struct {
Port int `json:"Port"`
}
type TemplateConfig struct {
MailDir string `json:"MailDir"`
}
type Config struct {
DB DatabaseConfig `json:"db"`
Auth AuthenticationConfig
SMTP SMTPConfig `json:"smtp"`
DB DatabaseConfig `json:"db"`
Auth AuthenticationConfig
SMTP SMTPConfig `json:"smtp"`
Templates TemplateConfig `json:"templates"`
}
var (

View File

@@ -16,7 +16,7 @@ import (
func Run() {
cfg := config.LoadConfig()
logger.Info.Printf("Config: %v", cfg)
db := database.Connect(cfg.DB)
defer db.Close()

View File

@@ -1,6 +1,7 @@
package services
import (
"GoMembership/internal/config"
"GoMembership/internal/models"
"GoMembership/pkg/logger"
"bytes"
@@ -33,9 +34,11 @@ func (s *EmailService) SendEmail(to string, subject string, body string) error {
return nil
}
func ParseTemplate(path string, data interface{}) (string, error) {
func ParseTemplate(filename string, data interface{}) (string, error) {
// Read the email template file
tpl, err := template.ParseFiles(path)
templateDir := config.LoadConfig().Templates.MailDir
tpl, err := template.ParseFiles(templateDir + "/" + filename)
if err != nil {
logger.Error.Printf("Failed to parse email template: %v", err)
return "", err
@@ -51,7 +54,6 @@ func ParseTemplate(path string, data interface{}) (string, error) {
return tplBuffer.String(), nil
}
func (s *EmailService) SendWelcomeEmail(user models.User) error {
// Prepare data to be injected into the template
data := struct {
FirstName string
@@ -62,7 +64,7 @@ func (s *EmailService) SendWelcomeEmail(user models.User) error {
}
subject := "Willkommen beim Dörpsmobil Hasloh e.V."
body, err := ParseTemplate("internal/templates/mail_welcome.html", data)
body, err := ParseTemplate("mail_welcome.html", data)
if err != nil {
logger.Error.Print("Couldn't send welcome mail")
return err

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Willkommen beim Dörpsmobil Hasloh e.V.</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
margin: 0;
padding: 20px;
background-color: #f9f9f9;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
}
h1 {
color: #007b5e;
}
p {
margin-bottom: 1em;
}
.contact-info {
margin-top: 20px;
}
.contact-info strong {
display: block;
margin-bottom: 5px;
}
a {
color: #007b5e;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>{{.Firstname}} {{.LastName}} hat sich registriert</h1>
<p>Ein neues Vereinsmitglied hat sich registriert</p>
<p>{{.Firstname}} {{.LastName}} hat sich registriert. Hier sind die Daten:</p>
<br>
<div class="contact-info">
<strong>Registrierungsdaten:</strong>
Name: {{.Firstname}} {{.LastName}} <br>
Email: {{.Email}}<br>
IBAN: {{.IBAN}}<br>
BIC: {{.BIC}}<br>
Mandatsreferenz: {{.MandateReference}}<br>
</div>
<p>Mit freundlichen Grüßen,<br>
der Server
</p>
</div>
</body>
</html>

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Willkommen beim Dörpsmobil Hasloh e.V.</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
margin: 0;
padding: 20px;
background-color: #f9f9f9;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
}
h1 {
color: #007b5e;
}
p {
margin-bottom: 1em;
}
.contact-info {
margin-top: 20px;
}
.contact-info strong {
display: block;
margin-bottom: 5px;
}
a {
color: #007b5e;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Willkommen beim Dörpsmobil Hasloh e.V.</h1>
<p>Hallo {{.FirstName}},</p>
<p>herzlich willkommen beim Dörpsmobil Hasloh e.V.! Vielen Dank für Ihre Registrierung und Ihre Unterstützung unseres Projekts.</p>
<p>Wir freuen uns, Sie als Mitglied begrüßen zu dürfen und wünschen Ihnen stets eine sichere und angenehme Fahrt mit unseren Fahrzeugen.</p>
<p>Für weitere Fragen stehen wir Ihnen gerne zur Verfügung:</p>
<div class="contact-info">
<strong>Kontakt:</strong>
Name: Anke Freitag<br>
Vorsitzende Doerpsmobil-Hasloh e.V.<br>
E-Mail: <a href="mailto:info@doerpsmobil-hasloh.de">info@doerpsmobil-hasloh.de</a><br>
Telefon: +49 174 870 1392
</div>
<p>Besuchen Sie auch unsere Webseite unter <a href="https://carsharing-hasloh.de">https://carsharing-hasloh.de</a> für weitere Informationen.</p>
<p>Mit freundlichen Grüßen,<br>
Ihr Team von Dörpsmobil Hasloh e.V.
</p>
</div>
</body>
</html>

View File

@@ -12,12 +12,12 @@ var (
)
func init() {
file, err := os.OpenFile("gomember.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
/* file, err := os.OpenFile("gomember.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
} */
Info = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
Warning = log.New(file, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile)
Error = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
Info = log.New(os.Stderr, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
Warning = log.New(os.Stderr, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile)
Error = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
}

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Willkommen beim Dörpsmobil Hasloh e.V.</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
margin: 0;
padding: 20px;
background-color: #f9f9f9;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
}
h1 {
color: #007b5e;
}
p {
margin-bottom: 1em;
}
.contact-info {
margin-top: 20px;
}
.contact-info strong {
display: block;
margin-bottom: 5px;
}
a {
color: #007b5e;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>{{.Firstname}} {{.LastName}} hat sich registriert</h1>
<p>Ein neues Vereinsmitglied hat sich registriert</p>
<p>{{.Firstname}} {{.LastName}} hat sich registriert. Hier sind die Daten:</p>
<br>
<div class="contact-info">
<strong>Registrierungsdaten:</strong>
Name: {{.Firstname}} {{.LastName}} <br>
Email: {{.Email}}<br>
IBAN: {{.IBAN}}<br>
BIC: {{.BIC}}<br>
Mandatsreferenz: {{.MandateReference}}<br>
</div>
<p>Mit freundlichen Grüßen,<br>
der Server
</p>
</div>
</body>
</html>

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Willkommen beim Dörpsmobil Hasloh e.V.</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
margin: 0;
padding: 20px;
background-color: #f9f9f9;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
}
h1 {
color: #007b5e;
}
p {
margin-bottom: 1em;
}
.contact-info {
margin-top: 20px;
}
.contact-info strong {
display: block;
margin-bottom: 5px;
}
a {
color: #007b5e;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Willkommen beim Dörpsmobil Hasloh e.V.</h1>
<p>Hallo {{.FirstName}},</p>
<p>herzlich willkommen beim Dörpsmobil Hasloh e.V.! Vielen Dank für Ihre Registrierung und Ihre Unterstützung unseres Projekts.</p>
<p>Wir freuen uns, Sie als Mitglied begrüßen zu dürfen und wünschen Ihnen stets eine sichere und angenehme Fahrt mit unseren Fahrzeugen.</p>
<p>Für weitere Fragen stehen wir Ihnen gerne zur Verfügung:</p>
<div class="contact-info">
<strong>Kontakt:</strong>
Name: Anke Freitag<br>
Vorsitzende Doerpsmobil-Hasloh e.V.<br>
E-Mail: <a href="mailto:info@doerpsmobil-hasloh.de">info@doerpsmobil-hasloh.de</a><br>
Telefon: +49 174 870 1392
</div>
<p>Besuchen Sie auch unsere Webseite unter <a href="https://carsharing-hasloh.de">https://carsharing-hasloh.de</a> für weitere Informationen.</p>
<p>Mit freundlichen Grüßen,<br>
Ihr Team von Dörpsmobil Hasloh e.V.
</p>
</div>
</body>
</html>