admin dashboard zugriff angefangen
This commit is contained in:
parent
ea1e8fe8d6
commit
d0bf1fe755
3
ctdo.sql
3
ctdo.sql
|
@ -7,4 +7,7 @@ create table events (
|
||||||
media varchar(10000),
|
media varchar(10000),
|
||||||
date varchar(10) not null,
|
date varchar(10) not null,
|
||||||
primary key(id)
|
primary key(id)
|
||||||
|
);
|
||||||
|
create table adminKeys (
|
||||||
|
adminKey varchar(16) not null
|
||||||
);
|
);
|
|
@ -28,3 +28,9 @@ func dbQuerry(database *sql.DB, sqlCode string) *sql.Rows {
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ctdoConnect() *sql.DB {
|
||||||
|
dbValues := readDatabaseYML()
|
||||||
|
|
||||||
|
return dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database)
|
||||||
|
}
|
||||||
|
|
39
events.go
39
events.go
|
@ -1,9 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func getEvents() []event {
|
func getEvents() []event {
|
||||||
dbValues := readDatabaseYML()
|
db := ctdoConnect()
|
||||||
|
|
||||||
db := dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database)
|
|
||||||
|
|
||||||
rows := dbQuerry(db, "SELECT * FROM events;")
|
rows := dbQuerry(db, "SELECT * FROM events;")
|
||||||
|
|
||||||
|
@ -20,3 +18,38 @@ func getEvents() []event {
|
||||||
|
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addEvent(Event event) bool {
|
||||||
|
db := ctdoConnect()
|
||||||
|
|
||||||
|
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+"');")
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAdminKeys() []string {
|
||||||
|
db := ctdoConnect()
|
||||||
|
|
||||||
|
rows := dbQuerry(db, "select * from adminKeys;")
|
||||||
|
|
||||||
|
output := []string{}
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
temp := ""
|
||||||
|
err := rows.Scan(temp)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
output = append(output, temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(output) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
36
func.go
36
func.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -28,6 +29,14 @@ func handler() {
|
||||||
httpHandleFunc("impressum", "./web/pages/impressum.html", "text/html")
|
httpHandleFunc("impressum", "./web/pages/impressum.html", "text/html")
|
||||||
httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", "text/html")
|
httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", "text/html")
|
||||||
|
|
||||||
|
keys := getAdminKeys()
|
||||||
|
|
||||||
|
if keys != nil {
|
||||||
|
for _, key := range keys {
|
||||||
|
httpHandleFunc("admin/"+key, "./web/pages/admin/dashboard.html", "text/html")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Styles
|
//Styles
|
||||||
httpHandleFunc("style/main.css", "./web/styles/main.css", "text/css")
|
httpHandleFunc("style/main.css", "./web/styles/main.css", "text/css")
|
||||||
httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", "text/css")
|
httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", "text/css")
|
||||||
|
@ -134,14 +143,16 @@ func htmlReplacer(input string, activePage string) string {
|
||||||
output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet in "+string(getNextTopic().days)+" Tagen statt!", "class=\"topic\"")+htmlElement("p", "Am "+getNextTopic().date, "class=\"topic\""))
|
output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet in "+string(getNextTopic().days)+" Tagen statt!", "class=\"topic\"")+htmlElement("p", "Am "+getNextTopic().date, "class=\"topic\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
events := getEvents()
|
/*
|
||||||
|
events := getEvents()
|
||||||
|
|
||||||
if len(events) == 0 {
|
if len(events) == 0 {
|
||||||
output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
output = strings.ReplaceAll(output, "!NEWBANNER", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
output = strings.ReplaceAll(output, "!NEWBANNER", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
||||||
|
|
||||||
|
@ -240,3 +251,16 @@ func readDatabaseYML() database {
|
||||||
|
|
||||||
return *output
|
return *output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateRandomString(length int) string {
|
||||||
|
chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
chars += strings.ToLower(chars)
|
||||||
|
|
||||||
|
output := ""
|
||||||
|
|
||||||
|
for i := 0; i < length; i++ {
|
||||||
|
output += string(chars[rand.Intn(len(chars)-1)])
|
||||||
|
}
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
1
main.go
1
main.go
|
@ -8,7 +8,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
println(len(getEvents()))
|
|
||||||
addr := ":80"
|
addr := ":80"
|
||||||
|
|
||||||
handler()
|
handler()
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>ctdo - admin</title>
|
||||||
|
<link rel="stylesheet" href="/style/main.css">
|
||||||
|
<link rel="stylesheet" href="/style/dashboard.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<img src="/image/logo_ctdo.svg" alt="ctdo logo">
|
||||||
|
!NAV
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
!RAUMSTATUS
|
||||||
|
</main>
|
||||||
|
<footer>
|
||||||
|
!FOOTERNAV
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue