funktionalität der events erweitert
This commit is contained in:
parent
6ea9de47c5
commit
206989bccc
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"strings"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
@ -29,3 +30,10 @@ func ctdoConnect() *sql.DB {
|
|||
|
||||
return dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database)
|
||||
}
|
||||
|
||||
func sqlClean(sqlString string) string {
|
||||
sqlString = strings.ReplaceAll(sqlString, "'", "")
|
||||
sqlString = strings.ReplaceAll(sqlString, "\"", "")
|
||||
|
||||
return sqlString
|
||||
}
|
||||
|
|
10
events.go
10
events.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
func getEvents() []event {
|
||||
db := ctdoConnect()
|
||||
defer dbClose(db)
|
||||
|
||||
rows := dbQuerry(db, "SELECT * FROM events;")
|
||||
|
||||
|
@ -21,6 +22,7 @@ func getEvents() []event {
|
|||
|
||||
func getEventCount() int {
|
||||
db := ctdoConnect()
|
||||
defer dbClose(db)
|
||||
|
||||
row := dbQuerry(db, "SELECT COUNT(*) FROM events;")
|
||||
|
||||
|
@ -35,18 +37,22 @@ func getEventCount() int {
|
|||
|
||||
func addEvent(Event event) bool {
|
||||
db := ctdoConnect()
|
||||
defer dbClose(db)
|
||||
|
||||
if len(Event.title) > 80 || len(Event.description) > 500 || len(Event.media) > 10000 || len(Event.date) > 10 {
|
||||
if len(Event.title) > 80 || len(Event.description) > 500 || len(Event.media) == 10000 || len(Event.date) > 10 {
|
||||
return false
|
||||
}
|
||||
|
||||
dbQuerry(db, "insert into events (title, description, media, date) values ('"+Event.title+"', '"+Event.description+"', '"+Event.media+"', '"+Event.date+"');")
|
||||
sqlString := "insert into events (title, description, media, date) values ('" + Event.title + "', '" + Event.description + "', '" + Event.media + "', '" + Event.date + "');"
|
||||
|
||||
dbQuerry(db, sqlClean(sqlString))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func getAdminKeys() []string {
|
||||
db := ctdoConnect()
|
||||
defer dbClose(db)
|
||||
|
||||
rows := dbQuerry(db, "select * from adminKeys;")
|
||||
|
||||
|
|
53
http.go
53
http.go
|
@ -21,11 +21,12 @@ func httpHandleFunc(urlPath string, filepath string, contentType string) {
|
|||
}
|
||||
|
||||
func httpHandleFuncWithPOST(urlPath string, filepath string, contentType string) {
|
||||
Event := new(event)
|
||||
logger(readHttpYML() + "/" + urlPath + " <--> " + filepath + " <" + contentType + ">")
|
||||
s := new(submit)
|
||||
s.data = "null"
|
||||
http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
logger(r.Method + " request -> " + readHttpYML() + "/" + urlPath + " <" + contentType + ">")
|
||||
|
||||
r.ParseMultipartForm(10 << 20)
|
||||
err := r.ParseMultipartForm(200000)
|
||||
errorPanic(err)
|
||||
|
@ -35,39 +36,59 @@ func httpHandleFuncWithPOST(urlPath string, filepath string, contentType string)
|
|||
files := formdata.File["media"]
|
||||
|
||||
if filepath == "./web/pages/admin/dashboard.html" {
|
||||
logger("----------------ADD EVENT----------------")
|
||||
title := formdata.Value["title"]
|
||||
description := formdata.Value["description"]
|
||||
media := formdata.File["media"]
|
||||
mediaString := ""
|
||||
date := formdata.Value["date"]
|
||||
|
||||
if title[0] != "" && description[0] != "" && media != nil && date[0] != "" {
|
||||
logger("----------------POST----------------")
|
||||
logger("title: " + title[0])
|
||||
logger("descrtiption: " + description[0])
|
||||
logger("media: " + string(len(media)))
|
||||
|
||||
logger("files uploaded successfully : ")
|
||||
logger("files uploaded successfully: ")
|
||||
|
||||
for i, _ := range files {
|
||||
file, err := files[i].Open()
|
||||
errorPanic(err)
|
||||
|
||||
out, err := os.Create("./web/images/" + files[i].Filename)
|
||||
errorPanic(err, "unable to create the file '"+"./web/images/"+files[i].Filename+"' for writing. Check your write access privilege")
|
||||
|
||||
_, err = io.Copy(out, file)
|
||||
errorPanic(err)
|
||||
if len(media) > 0 {
|
||||
mediaString += ","
|
||||
}
|
||||
mediaString += "./web/images/" + files[i].Filename
|
||||
|
||||
logger("./web/images/" + files[i].Filename)
|
||||
}
|
||||
|
||||
Event.id = -1
|
||||
Event.title = title[0]
|
||||
Event.description = description[0]
|
||||
Event.media = mediaString
|
||||
Event.date = date[0]
|
||||
|
||||
logger("date: " + date[0])
|
||||
|
||||
if addEvent(*Event) {
|
||||
for i, _ := range files {
|
||||
file, err := files[i].Open()
|
||||
errorPanic(err)
|
||||
|
||||
out, err := os.Create("./web/images/" + files[i].Filename)
|
||||
errorPanic(err, "unable to create the file -> '"+"./web/images/"+files[i].Filename+"' : check your write access privilege")
|
||||
|
||||
_, err = io.Copy(out, file)
|
||||
errorPanic(err)
|
||||
}
|
||||
logger("event added!")
|
||||
} else {
|
||||
logger("event not added!")
|
||||
}
|
||||
} else {
|
||||
logger("no formdata")
|
||||
}
|
||||
logger("date: " + date[0])
|
||||
logger("----------------POST END----------------")
|
||||
logger("----------------ADD END----------------")
|
||||
}
|
||||
}
|
||||
|
||||
logger(r.Method + " request -> " + readHttpYML() + "/" + urlPath + " <" + contentType + ">")
|
||||
|
||||
w.Header().Add("Content-Type", contentType)
|
||||
|
||||
io.WriteString(w, htmlReplacer(fileRead(filepath), urlPath))
|
||||
|
|
38
main.go
38
main.go
|
@ -28,34 +28,14 @@ func main() {
|
|||
}
|
||||
|
||||
func handler() {
|
||||
logger("Pages:")
|
||||
logger("----------------HANDLE PAGES----------------")
|
||||
|
||||
//pages
|
||||
httpHandleFunc("", "./web/pages/home.html", "text/html")
|
||||
handleFilesInFolder("", "./web/pages/", true)
|
||||
/*
|
||||
httpHandleFunc("home", "./web/pages/home.html", "text/html")
|
||||
httpHandleFunc("treff", "./web/pages/treff.html", "text/html")
|
||||
httpHandleFunc("events", "./web/pages/events.html", "text/html")
|
||||
httpHandleFunc("about", "./web/pages/about.html", "text/html")
|
||||
|
||||
//contact pages
|
||||
httpHandleFunc("kontakt", "./web/pages/kontakt.html", "text/html")
|
||||
httpHandleFunc("kontakt/adresse", "./web/pages/kontakt/adresse.html", "text/html")
|
||||
httpHandleFunc("kontakt/irc", "./web/pages/kontakt/irc.html", "text/html")
|
||||
httpHandleFunc("kontakt/mail", "./web/pages/kontakt/mail.html", "text/html")
|
||||
httpHandleFunc("kontakt/tel", "./web/pages/kontakt/tel.html", "text/html")
|
||||
|
||||
//pages
|
||||
httpHandleFunc("verein", "./web/pages/verein.html", "text/html")
|
||||
httpHandleFunc("support", "./web/pages/support.html", "text/html")
|
||||
httpHandleFunc("impressum", "./web/pages/impressum.html", "text/html")
|
||||
httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", "text/html")
|
||||
*/
|
||||
|
||||
//admin pages
|
||||
keys := getAdminKeys()
|
||||
|
||||
if len(keys) > 0 {
|
||||
for _, key := range keys {
|
||||
httpHandleFunc("admin/"+key, "./web/pages/admin/dashboard.html", "text/html")
|
||||
|
@ -65,24 +45,10 @@ func handler() {
|
|||
|
||||
//styles
|
||||
handleFilesInFolder("style/", "./web/styles/", false)
|
||||
/*
|
||||
httpHandleFunc("style/main.css", "./web/styles/main.css", "text/css")
|
||||
httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", "text/css")
|
||||
httpHandleFunc("style/home.css", "./web/styles/home.css", "text/css")
|
||||
httpHandleFunc("style/events.css", "./web/styles/events.css", "text/css")
|
||||
httpHandleFunc("style/dashboard.css", "./web/styles/dashboard.css", "text/css")
|
||||
*/
|
||||
|
||||
//images
|
||||
handleFilesInFolder("image/", "./web/images/", false)
|
||||
/*
|
||||
httpHandleFunc("image/logo_ctdo.svg", "./web/images/logo_ctdo.svg", "image/svg+xml")
|
||||
httpHandleFunc("image/header.jpg", "./web/images/header.jpg", "image/jpeg")
|
||||
httpHandleFunc("image/adresse_knopf.webp", "./web/images/adresse_knopf.webp", "image/webp")
|
||||
httpHandleFunc("image/chat_knopf.webp", "./web/images/chat_knopf.webp", "image/webp")
|
||||
httpHandleFunc("image/mail_knopf.webp", "./web/images/mail_knopf.webp", "image/webp")
|
||||
httpHandleFunc("image/tel_knopf.webp", "./web/images/tel_knopf.webp", "image/webp")
|
||||
*/
|
||||
logger("----------------HANDLE END----------------")
|
||||
}
|
||||
|
||||
var alreadyHandledFiles []string = []string{"./web/pages/admin/dashboard.html"}
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package main
|
||||
|
||||
type submit struct {
|
||||
data string
|
||||
}
|
||||
|
||||
type status struct {
|
||||
state bool
|
||||
lastchange int64
|
||||
|
|
Loading…
Reference in New Issue