admin dashboard zugriff angefangen

This commit is contained in:
xoy 2023-01-28 19:52:41 +01:00
parent ea1e8fe8d6
commit d0bf1fe755
7 changed files with 98 additions and 10 deletions

View File

@ -8,3 +8,6 @@ create table events (
date varchar(10) not null,
primary key(id)
);
create table adminKeys (
adminKey varchar(16) not null
);

View File

@ -28,3 +28,9 @@ func dbQuerry(database *sql.DB, sqlCode string) *sql.Rows {
return results
}
func ctdoConnect() *sql.DB {
dbValues := readDatabaseYML()
return dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database)
}

View File

@ -1,9 +1,7 @@
package main
func getEvents() []event {
dbValues := readDatabaseYML()
db := dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database)
db := ctdoConnect()
rows := dbQuerry(db, "SELECT * FROM events;")
@ -20,3 +18,38 @@ func getEvents() []event {
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
}

24
func.go
View File

@ -2,6 +2,7 @@ package main
import (
"io"
"math/rand"
"net/http"
"strconv"
"strings"
@ -28,6 +29,14 @@ func handler() {
httpHandleFunc("impressum", "./web/pages/impressum.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
httpHandleFunc("style/main.css", "./web/styles/main.css", "text/css")
httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", "text/css")
@ -134,6 +143,7 @@ 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\""))
}
/*
events := getEvents()
if len(events) == 0 {
@ -142,6 +152,7 @@ func htmlReplacer(input string, activePage string) string {
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/"))
@ -240,3 +251,16 @@ func readDatabaseYML() database {
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
}

View File

@ -8,7 +8,6 @@ import (
)
func main() {
println(len(getEvents()))
addr := ":80"
handler()

View File

@ -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>

0
web/styles/dashboard.css Normal file
View File