Compare commits
No commits in common. "32f11f57b534e6865c748898971404c630b37e61" and "21fd3403b27a2d23337a4d2e63efcd5e50db8ff9" have entirely different histories.
32f11f57b5
...
21fd3403b2
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package control
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package control
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package control
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -7,9 +7,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.streifling.com/jason/rss"
|
"git.streifling.com/jason/rss"
|
||||||
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetChannel(db *DB, title, link, description string) (*rss.Channel, error) {
|
func GetChannel(db *model.DB, title, link, description string) (*rss.Channel, error) {
|
||||||
channel := &rss.Channel{
|
channel := &rss.Channel{
|
||||||
Title: title,
|
Title: title,
|
||||||
Link: link,
|
Link: link,
|
||||||
@ -50,7 +51,7 @@ func GetChannel(db *DB, title, link, description string) (*rss.Channel, error) {
|
|||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateRSS(db *DB, title, link, desc string) (*string, error) {
|
func GenerateRSS(db *model.DB, title, link, desc string) (*string, error) {
|
||||||
channel := &rss.Channel{
|
channel := &rss.Channel{
|
||||||
Title: title,
|
Title: title,
|
||||||
Link: link,
|
Link: link,
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package control
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
83
cmd/main.go
83
cmd/main.go
@ -6,17 +6,17 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
f "streifling.com/jason/cpolis/cmd/frontend"
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
|
"streifling.com/jason/cpolis/cmd/view"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
gob.Register(b.User{})
|
gob.Register(model.User{})
|
||||||
gob.Register(f.EditorHTMLData{})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config, err := b.HandleConfig()
|
config, err := control.HandleConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
@ -28,58 +28,59 @@ func main() {
|
|||||||
defer logFile.Close()
|
defer logFile.Close()
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(logFile)
|
||||||
|
|
||||||
db, err := b.OpenDB(config.DBName)
|
db, err := model.OpenDB(config.DBName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
key, err := b.LoadKey(config.KeyFile)
|
key, err := control.LoadKey(config.KeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
key, err = b.NewKey()
|
key, err = control.NewKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
b.SaveKey(key, config.KeyFile)
|
control.SaveKey(key, config.KeyFile)
|
||||||
}
|
}
|
||||||
store := b.NewCookieStore(key)
|
store := control.NewCookieStore(key)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
||||||
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
||||||
mux.HandleFunc("/", f.HomePage(config, db, store))
|
mux.HandleFunc("/", view.HomePage(config, db, store))
|
||||||
|
|
||||||
mux.HandleFunc("GET /create-tag", f.CreateTag(config))
|
mux.HandleFunc("GET /create-tag", view.CreateTag(config))
|
||||||
mux.HandleFunc("GET /create-user", f.CreateUser(config))
|
mux.HandleFunc("GET /create-user", view.CreateUser(config))
|
||||||
mux.HandleFunc("GET /edit-self", f.EditSelf(config, db, store))
|
mux.HandleFunc("GET /edit-self", view.EditSelf(config, db, store))
|
||||||
mux.HandleFunc("GET /edit-user/{id}", f.EditUser(config, db))
|
mux.HandleFunc("GET /edit-user/{id}", view.EditUser(config, db))
|
||||||
mux.HandleFunc("GET /delete-user/{id}", f.DeleteUser(config, db, store))
|
mux.HandleFunc("GET /delete-user/{id}", view.DeleteUser(config, db, store))
|
||||||
mux.HandleFunc("GET /hub", f.ShowHub(config, db, store))
|
mux.HandleFunc("GET /hub", view.ShowHub(config, db, store))
|
||||||
mux.HandleFunc("GET /logout", f.Logout(config, store))
|
mux.HandleFunc("GET /logout", view.Logout(config, store))
|
||||||
mux.HandleFunc("GET /pics/{pic}", f.ServeImage(config, store))
|
mux.HandleFunc("GET /pics/{pic}", view.ServeImage(config, store))
|
||||||
mux.HandleFunc("GET /publish-article/{id}", f.PublishArticle(config, db, store))
|
mux.HandleFunc("GET /publish-article/{id}", view.PublishArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /publish-issue", f.PublishLatestIssue(config, db, store))
|
mux.HandleFunc("GET /publish-issue", view.PublishLatestIssue(config, db, store))
|
||||||
mux.HandleFunc("GET /reject-article/{id}", f.RejectArticle(config, db, store))
|
mux.HandleFunc("GET /reject-article/{id}", view.RejectArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /rejected-articles", f.ShowRejectedArticles(config, db, store))
|
mux.HandleFunc("GET /rejected-articles", view.ShowRejectedArticles(config, db, store))
|
||||||
mux.HandleFunc("GET /review-rejected-article/{id}", f.ReviewRejectedArticle(config, db, store))
|
mux.HandleFunc("GET /review-rejected-article/{id}", view.ReviewRejectedArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /review-unpublished-article/{id}", f.ReviewUnpublishedArticle(config, db, store))
|
mux.HandleFunc("GET /review-unpublished-article/{id}", view.ReviewUnpublishedArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /rss", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, config.RSSFile) })
|
mux.HandleFunc("GET /rss", func(w http.ResponseWriter, r *http.Request) {
|
||||||
mux.HandleFunc("GET /show-all-users-edit", f.ShowAllUsers(config, db, store, "edit-user"))
|
http.ServeFile(w, r, config.RSSFile)
|
||||||
mux.HandleFunc("GET /show-all-users-delete", f.ShowAllUsers(config, db, store, "delete-user"))
|
})
|
||||||
mux.HandleFunc("GET /this-issue", f.ShowCurrentArticles(config, db))
|
mux.HandleFunc("GET /show-all-users-edit", view.ShowAllUsers(config, db, store, "edit-user"))
|
||||||
mux.HandleFunc("GET /unpublished-articles", f.ShowUnpublishedArticles(config, db))
|
mux.HandleFunc("GET /show-all-users-delete", view.ShowAllUsers(config, db, store, "delete-user"))
|
||||||
mux.HandleFunc("GET /write-article", f.WriteArticle(config, db, store))
|
mux.HandleFunc("GET /this-issue", view.ShowCurrentArticles(config, db))
|
||||||
|
mux.HandleFunc("GET /unpublished-articles", view.ShowUnpublishedArticles(config, db))
|
||||||
|
mux.HandleFunc("GET /write-article", view.WriteArticle(config, db))
|
||||||
|
|
||||||
mux.HandleFunc("POST /add-first-user", f.AddFirstUser(config, db, store))
|
mux.HandleFunc("POST /add-first-user", view.AddFirstUser(config, db, store))
|
||||||
mux.HandleFunc("POST /add-tag", f.AddTag(config, db, store))
|
mux.HandleFunc("POST /add-tag", view.AddTag(config, db, store))
|
||||||
mux.HandleFunc("POST /add-user", f.AddUser(config, db, store))
|
mux.HandleFunc("POST /add-user", view.AddUser(config, db, store))
|
||||||
mux.HandleFunc("POST /login", f.Login(config, db, store))
|
mux.HandleFunc("POST /login", view.Login(config, db, store))
|
||||||
mux.HandleFunc("POST /preview-article", f.PreviewArticle(config, store))
|
mux.HandleFunc("POST /resubmit-article/{id}", view.ResubmitArticle(config, db, store))
|
||||||
mux.HandleFunc("POST /resubmit-article/{id}", f.ResubmitArticle(config, db, store))
|
mux.HandleFunc("POST /submit-article", view.SubmitArticle(config, db, store))
|
||||||
mux.HandleFunc("POST /submit-article", f.SubmitArticle(config, db, store))
|
mux.HandleFunc("POST /update-self", view.UpdateSelf(config, db, store))
|
||||||
mux.HandleFunc("POST /update-self", f.UpdateSelf(config, db, store))
|
mux.HandleFunc("POST /update-user/{id}", view.UpdateUser(config, db, store))
|
||||||
mux.HandleFunc("POST /update-user/{id}", f.UpdateUser(config, db, store))
|
mux.HandleFunc("POST /upload-image", view.UploadImage(config))
|
||||||
mux.HandleFunc("POST /upload-image", f.UploadImage(config))
|
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(config.Port, mux))
|
log.Fatalln(http.ListenAndServe(config.Port, mux))
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package model
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package backend
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,11 +1,9 @@
|
|||||||
package frontend
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -15,24 +13,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
func ShowHub(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
EditMode = iota
|
|
||||||
PreviewMode
|
|
||||||
)
|
|
||||||
|
|
||||||
type EditorHTMLData struct {
|
|
||||||
Title string
|
|
||||||
Description string
|
|
||||||
Content string
|
|
||||||
HTMLContent template.HTML
|
|
||||||
Tags []*b.Tag
|
|
||||||
Mode int
|
|
||||||
}
|
|
||||||
|
|
||||||
func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -41,36 +26,14 @@ func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.Values["article"] = nil
|
|
||||||
if err = session.Save(r, w); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func WriteArticle(c *control.Config, db *model.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := s.Get(r, "cookie")
|
tags, err := db.GetTagList()
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
var data EditorHTMLData
|
|
||||||
if session.Values["article"] == nil {
|
|
||||||
data = EditorHTMLData{}
|
|
||||||
} else {
|
|
||||||
data = session.Values["article"].(EditorHTMLData)
|
|
||||||
}
|
|
||||||
data.Mode = EditMode
|
|
||||||
|
|
||||||
data.Tags, err = db.GetTagList()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
@ -78,11 +41,11 @@ func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html")
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html")
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func SubmitArticle(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -91,14 +54,7 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.Values["article"] = nil
|
article := &model.Article{
|
||||||
if err = session.Save(r, w); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
article := &b.Article{
|
|
||||||
Title: r.PostFormValue("article-title"),
|
Title: r.PostFormValue("article-title"),
|
||||||
Description: r.PostFormValue("article-description"),
|
Description: r.PostFormValue("article-description"),
|
||||||
Content: r.PostFormValue("article-content"),
|
Content: r.PostFormValue("article-content"),
|
||||||
@ -137,7 +93,7 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func ResubmitArticle(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -151,10 +107,10 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
content := r.PostFormValue("article-content")
|
content := r.PostFormValue("article-content")
|
||||||
|
|
||||||
if err = db.UpdateAttributes(
|
if err = db.UpdateAttributes(
|
||||||
&b.Attribute{Table: "articles", ID: id, AttName: "title", Value: title},
|
&model.Attribute{Table: "articles", ID: id, AttName: "title", Value: title},
|
||||||
&b.Attribute{Table: "articles", ID: id, AttName: "description", Value: description},
|
&model.Attribute{Table: "articles", ID: id, AttName: "description", Value: description},
|
||||||
&b.Attribute{Table: "articles", ID: id, AttName: "content", Value: content},
|
&model.Attribute{Table: "articles", ID: id, AttName: "content", Value: content},
|
||||||
&b.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
@ -191,7 +147,7 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowUnpublishedArticles(c *b.Config, db *b.DB) http.HandlerFunc {
|
func ShowUnpublishedArticles(c *control.Config, db *model.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
unpublishedArticles, err := db.GetCertainArticles(false, false)
|
unpublishedArticles, err := db.GetCertainArticles(false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -206,11 +162,11 @@ func ShowUnpublishedArticles(c *b.Config, db *b.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func ShowRejectedArticles(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
type htmlData struct {
|
type htmlData struct {
|
||||||
MyIDs map[int64]bool
|
MyIDs map[int64]bool
|
||||||
RejectedArticles []*b.Article
|
RejectedArticles []*model.Article
|
||||||
}
|
}
|
||||||
data := new(htmlData)
|
data := new(htmlData)
|
||||||
|
|
||||||
@ -241,13 +197,13 @@ func ShowRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReviewUnpublishedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func ReviewUnpublishedArticle(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
type htmlData struct {
|
type htmlData struct {
|
||||||
Title string
|
Title string
|
||||||
Description string
|
Description string
|
||||||
Content template.HTML
|
Content template.HTML
|
||||||
Tags []*b.Tag
|
Tags []*model.Tag
|
||||||
ID int64
|
ID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,21 +224,21 @@ func ReviewUnpublishedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Hand
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Title, err = b.ConvertToPlain(article.Title)
|
data.Title, err = control.ConvertToPlain(article.Title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Description, err = b.ConvertToPlain(article.Description)
|
data.Description, err = control.ConvertToPlain(article.Description)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := b.ConvertToHTML(article.Content)
|
content, err := control.ConvertToHTML(article.Content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
@ -303,12 +259,12 @@ func ReviewUnpublishedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Hand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReviewRejectedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func ReviewRejectedArticle(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
type htmlData struct {
|
type htmlData struct {
|
||||||
Selected map[int64]bool
|
Selected map[int64]bool
|
||||||
Article *b.Article
|
Article *model.Article
|
||||||
Tags []*b.Tag
|
Tags []*model.Tag
|
||||||
}
|
}
|
||||||
data := new(htmlData)
|
data := new(htmlData)
|
||||||
|
|
||||||
@ -350,7 +306,7 @@ func ReviewRejectedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Handler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func PublishArticle(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -373,22 +329,22 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = db.UpdateAttributes(
|
if err = db.UpdateAttributes(
|
||||||
&b.Attribute{Table: "articles", ID: id, AttName: "published", Value: true},
|
&model.Attribute{Table: "articles", ID: id, AttName: "published", Value: true},
|
||||||
&b.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
||||||
&b.Attribute{Table: "articles", ID: id, AttName: "created", Value: time.Now().Format("2006-01-02 15:04:05")},
|
&model.Attribute{Table: "articles", ID: id, AttName: "created", Value: time.Now().Format("2006-01-02 15:04:05")},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
feed, err := b.GenerateRSS(db, c.Title, c.Link, c.Description)
|
feed, err := control.GenerateRSS(db, c.Title, c.Link, c.Description)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = b.SaveRSS(c.RSSFile, feed); err != nil {
|
if err = control.SaveRSS(c.RSSFile, feed); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@ -400,7 +356,7 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func RejectArticle(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -417,7 +373,7 @@ func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = db.UpdateAttributes(
|
if err = db.UpdateAttributes(
|
||||||
&b.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: true},
|
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: true},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
@ -430,7 +386,7 @@ func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowCurrentArticles(c *b.Config, db *b.DB) http.HandlerFunc {
|
func ShowCurrentArticles(c *control.Config, db *model.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
articles, err := db.GetCurrentIssueArticles()
|
articles, err := db.GetCurrentIssueArticles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -444,7 +400,7 @@ func ShowCurrentArticles(c *b.Config, db *b.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UploadImage(c *b.Config) http.HandlerFunc {
|
func UploadImage(c *control.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
file, header, err := r.FormFile("article-image")
|
file, header, err := r.FormFile("article-image")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -464,12 +420,6 @@ func UploadImage(c *b.Config) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.MkdirAll(fmt.Sprint(c.PicsDir, "/"), fs.FileMode(0755)); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
img, err := os.Create(absFilepath)
|
img, err := os.Create(absFilepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -484,56 +434,9 @@ func UploadImage(c *b.Config) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprint(c.Domain, "/pics/", filename)
|
alt := strings.Join(nameStrings[0:len(nameStrings)-1], " ")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
imgMD := fmt.Sprint("![", alt, "](", c.Domain, "/pics/", filename, ")")
|
||||||
json.NewEncoder(w).Encode(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func PreviewArticle(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var err error
|
|
||||||
data := EditorHTMLData{Mode: PreviewMode}
|
|
||||||
|
|
||||||
data.Title, err = b.ConvertToPlain(r.PostFormValue("article-title"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Description, err = b.ConvertToPlain(r.PostFormValue("article-description"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Content = r.PostFormValue("article-content")
|
|
||||||
content, err := b.ConvertToHTML(data.Content)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data.HTMLContent = template.HTML(content)
|
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
session.Values["article"] = data
|
|
||||||
if err = session.Save(r, w); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html")
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html")
|
||||||
tmpl = template.Must(tmpl, err)
|
template.Must(tmpl, err).ExecuteTemplate(w, "editor-images", imgMD)
|
||||||
tmpl.ExecuteTemplate(w, "page-content", data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,20 +1,21 @@
|
|||||||
package frontend
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateTag(c *b.Config) http.HandlerFunc {
|
func CreateTag(c *control.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-tag.html")
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-tag.html")
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddTag(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func AddTag(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
db.AddTag(r.PostFormValue("tag"))
|
db.AddTag(r.PostFormValue("tag"))
|
||||||
|
|
@ -1,14 +1,14 @@
|
|||||||
package frontend
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
func ServeImage(c *control.Config, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
absFilepath, err := filepath.Abs(c.PicsDir)
|
absFilepath, err := filepath.Abs(c.PicsDir)
|
||||||
if err != nil {
|
if err != nil {
|
@ -1,14 +1,15 @@
|
|||||||
package frontend
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func PublishLatestIssue(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if err := db.PublishLatestIssue(); err != nil {
|
if err := db.PublishLatestIssue(); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
@ -1,4 +1,4 @@
|
|||||||
package frontend
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -6,10 +6,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func saveSession(w http.ResponseWriter, r *http.Request, s *b.CookieStore, u *b.User) error {
|
func saveSession(w http.ResponseWriter, r *http.Request, s *control.CookieStore, u *model.User) error {
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting session: %v", err)
|
return fmt.Errorf("error getting session: %v", err)
|
||||||
@ -26,7 +27,7 @@ func saveSession(w http.ResponseWriter, r *http.Request, s *b.CookieStore, u *b.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func HomePage(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
numRows, err := db.CountEntries("users")
|
numRows, err := db.CountEntries("users")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -53,7 +54,7 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Login(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func Login(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
userName := r.PostFormValue("username")
|
userName := r.PostFormValue("username")
|
||||||
password := r.PostFormValue("password")
|
password := r.PostFormValue("password")
|
||||||
@ -88,7 +89,7 @@ func Login(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
func Logout(c *control.Config, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
@ -1,4 +1,4 @@
|
|||||||
package frontend
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -7,15 +7,16 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserData struct {
|
type UserData struct {
|
||||||
*b.User
|
*model.User
|
||||||
Msg string
|
Msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkUserStrings(user *b.User) (string, int, bool) {
|
func checkUserStrings(user *model.User) (string, int, bool) {
|
||||||
userLen := 15
|
userLen := 15
|
||||||
nameLen := 50
|
nameLen := 50
|
||||||
|
|
||||||
@ -30,14 +31,14 @@ func checkUserStrings(user *b.User) (string, int, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUser(c *b.Config) http.HandlerFunc {
|
func CreateUser(c *control.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html")
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html")
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func AddUser(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
role, err := strconv.Atoi(r.PostFormValue("role"))
|
role, err := strconv.Atoi(r.PostFormValue("role"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -47,7 +48,7 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
htmlData := UserData{
|
htmlData := UserData{
|
||||||
User: &b.User{
|
User: &model.User{
|
||||||
UserName: r.PostFormValue("username"),
|
UserName: r.PostFormValue("username"),
|
||||||
FirstName: r.PostFormValue("first-name"),
|
FirstName: r.PostFormValue("first-name"),
|
||||||
LastName: r.PostFormValue("last-name"),
|
LastName: r.PostFormValue("last-name"),
|
||||||
@ -107,7 +108,7 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func EditSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func EditSelf(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -128,7 +129,7 @@ func EditSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func UpdateSelf(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -138,7 +139,7 @@ func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userData := UserData{
|
userData := UserData{
|
||||||
User: &b.User{
|
User: &model.User{
|
||||||
ID: session.Values["id"].(int64),
|
ID: session.Values["id"].(int64),
|
||||||
UserName: r.PostFormValue("username"),
|
UserName: r.PostFormValue("username"),
|
||||||
FirstName: r.PostFormValue("first-name"),
|
FirstName: r.PostFormValue("first-name"),
|
||||||
@ -198,16 +199,16 @@ func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func AddFirstUser(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
htmlData := UserData{
|
htmlData := UserData{
|
||||||
User: &b.User{
|
User: &model.User{
|
||||||
UserName: r.PostFormValue("username"),
|
UserName: r.PostFormValue("username"),
|
||||||
FirstName: r.PostFormValue("first-name"),
|
FirstName: r.PostFormValue("first-name"),
|
||||||
LastName: r.PostFormValue("last-name"),
|
LastName: r.PostFormValue("last-name"),
|
||||||
Role: b.Admin,
|
Role: model.Admin,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pass := r.PostFormValue("password")
|
pass := r.PostFormValue("password")
|
||||||
@ -273,11 +274,11 @@ func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowAllUsers(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.HandlerFunc {
|
func ShowAllUsers(c *control.Config, db *model.DB, s *control.CookieStore, action string) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
type htmlData struct {
|
type htmlData struct {
|
||||||
Users map[int64]*b.User
|
Users map[int64]*model.User
|
||||||
Action string
|
Action string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +303,7 @@ func ShowAllUsers(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.H
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func EditUser(c *b.Config, db *b.DB) http.HandlerFunc {
|
func EditUser(c *control.Config, db *model.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -323,7 +324,7 @@ func EditUser(c *b.Config, db *b.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func UpdateUser(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -340,7 +341,7 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userData := UserData{
|
userData := UserData{
|
||||||
User: &b.User{
|
User: &model.User{
|
||||||
ID: id,
|
ID: id,
|
||||||
UserName: r.PostFormValue("username"),
|
UserName: r.PostFormValue("username"),
|
||||||
FirstName: r.PostFormValue("first-name"),
|
FirstName: r.PostFormValue("first-name"),
|
||||||
@ -407,7 +408,7 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func DeleteUser(c *control.Config, db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
@ -1,25 +1,24 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Editor</h2>
|
<h2>Editor</h2>
|
||||||
|
|
||||||
<form id="edit-area">
|
<form>
|
||||||
<div class="flex flex-col gap-y-1">
|
<div class="flex flex-col gap-y-1">
|
||||||
<label for="article-title">Titel</label>
|
<label for="article-title">Titel</label>
|
||||||
<input name="article-title" type="text" value="{{.Title}}" />
|
<input name="article-title" type="text" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label for="article-description">Beschreibung</label>
|
<label for="article-description">Beschreibung</label>
|
||||||
<textarea name="article-description">{{.Description}}</textarea>
|
<textarea name="article-description"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label for="article-content">Artikel</label>
|
<label for="article-content">Artikel</label>
|
||||||
<textarea id="easyMDE">{{.Content}}</textarea>
|
<textarea name="article-content"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<input id="article-content" name="article-content" type="hidden" />
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span>Tags</span>
|
<span>Tags</span>
|
||||||
<div class="flex flex-wrap gap-x-4">
|
<div class="flex flex-wrap gap-x-4">
|
||||||
{{range .Tags}}
|
{{range .}}
|
||||||
<div>
|
<div>
|
||||||
<input id="{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" />
|
<input id="{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" />
|
||||||
<label for="{{.Name}}">{{.Name}}</label>
|
<label for="{{.Name}}">{{.Name}}</label>
|
||||||
@ -28,6 +27,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="editor-images">
|
||||||
|
<input class="mb-2" name="article-image" type="file" hx-encoding="multipart/form-data" hx-post="/upload-image"
|
||||||
|
hx-swap="beforeend" hx-target="#editor-images" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Senden" hx-post="/submit-article" hx-target="#page-content" />
|
<input class="action-btn" type="submit" value="Senden" hx-post="/submit-article" hx-target="#page-content" />
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
@ -35,33 +39,32 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var easyMDE = new EasyMDE({
|
function copyToClipboard(text) {
|
||||||
element: document.getElementById('easyMDE'),
|
event.preventDefault(); // Get-Request verhindern
|
||||||
hideIcons: ['image'],
|
|
||||||
imageTexts: {sbInit: ''},
|
|
||||||
showIcons: ["code", "table", "upload-image"],
|
|
||||||
uploadImage: true,
|
|
||||||
|
|
||||||
imageUploadFunction: function (file, onSuccess, onError) {
|
var textarea = document.createElement("textarea");
|
||||||
var formData = new FormData();
|
textarea.textContent = text;
|
||||||
formData.append('article-image', file);
|
document.body.appendChild(textarea);
|
||||||
|
|
||||||
fetch('/upload-image', {
|
textarea.select();
|
||||||
method: 'POST',
|
try {
|
||||||
body: formData
|
document.execCommand('copy');
|
||||||
})
|
} catch (err) {
|
||||||
.then(response => response.json())
|
console.warn('Fehler beim Kopieren', err);
|
||||||
.then(data => {
|
}
|
||||||
onSuccess(data);
|
|
||||||
})
|
document.body.removeChild(textarea);
|
||||||
.catch(error => {
|
}
|
||||||
onError(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
easyMDE.codemirror.on("change", () => {
|
|
||||||
document.getElementById('article-content').value = easyMDE.value();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{define "editor-images"}}
|
||||||
|
{{if gt (len .) 0}}
|
||||||
|
<div class="border px-2 py-1 rounded-md flex gap-4 justify-between">
|
||||||
|
<div class="self-center">{{.}}</div>
|
||||||
|
<button class="bg-slate-50 border my-2 px-3 py-2 rounded-md w-32 hover:bg-slate-100"
|
||||||
|
onclick="copyToClipboard('{{.}}')">Kopieren</button>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Orient Editor</title>
|
<title>Orient Editor</title>
|
||||||
<link href="/web/static/css/style.css" rel="stylesheet">
|
<link href="/web/static/css/style.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="https://unpkg.com/easymde/dist/easymde.min.css">
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="flex flex-col justify-between min-h-screen bg-slate-50">
|
<body class="flex flex-col justify-between min-h-screen bg-slate-50">
|
||||||
@ -26,8 +25,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script src="https://unpkg.com/htmx.org@2.0.1"></script>
|
<script src="/web/static/js/htmx.min.js"></script>
|
||||||
<script src="https://unpkg.com/easymde/dist/easymde.min.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
<label for="article-content">Artikel</label>
|
<label for="article-content">Artikel</label>
|
||||||
<textarea name="article-content" placeholder="Artikel">{{.Article.Content}}</textarea>
|
<textarea name="article-content" placeholder="Artikel">{{.Article.Content}}</textarea>
|
||||||
</div>
|
</div>
|
||||||
<input id="article-content" name="article-content" type="hidden" />
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span>Tags</span>
|
<span>Tags</span>
|
||||||
@ -29,6 +28,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="editor-images">
|
||||||
|
<input class="mb-2" name="article-image" type="file" hx-encoding="multipart/form-data" hx-post="/upload-image"
|
||||||
|
hx-swap="beforeend" hx-target="#editor-images" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Senden" hx-post="/resubmit-article/{{.Article.ID}}"
|
<input class="action-btn" type="submit" value="Senden" hx-post="/resubmit-article/{{.Article.ID}}"
|
||||||
hx-target="#page-content" />
|
hx-target="#page-content" />
|
||||||
@ -37,33 +41,32 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var easyMDE = new EasyMDE({
|
function copyToClipboard(text) {
|
||||||
element: document.getElementById('easyMDE'),
|
event.preventDefault(); // Get-Request verhindern
|
||||||
hideIcons: ['image'],
|
|
||||||
imageTexts: {sbInit: ''},
|
|
||||||
showIcons: ["code", "table", "upload-image"],
|
|
||||||
uploadImage: true,
|
|
||||||
|
|
||||||
imageUploadFunction: function (file, onSuccess, onError) {
|
var textarea = document.createElement("textarea");
|
||||||
var formData = new FormData();
|
textarea.textContent = text;
|
||||||
formData.append('article-image', file);
|
document.body.appendChild(textarea);
|
||||||
|
|
||||||
fetch('/upload-image', {
|
textarea.select();
|
||||||
method: 'POST',
|
try {
|
||||||
body: formData
|
document.execCommand('copy');
|
||||||
})
|
} catch (err) {
|
||||||
.then(response => response.json())
|
console.warn('Fehler beim Kopieren', err);
|
||||||
.then(data => {
|
}
|
||||||
onSuccess(data);
|
|
||||||
})
|
document.body.removeChild(textarea);
|
||||||
.catch(error => {
|
}
|
||||||
onError(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
easyMDE.codemirror.on("change", () => {
|
|
||||||
document.getElementById('article-content').value = easyMDE.value();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{define "editor-images"}}
|
||||||
|
{{if gt (len .) 0}}
|
||||||
|
<div class="border px-2 py-1 rounded-md flex gap-4 justify-between">
|
||||||
|
<div class="self-center">{{.}}</div>
|
||||||
|
<button class="bg-slate-50 border my-2 px-3 py-2 rounded-md w-32 hover:bg-slate-100"
|
||||||
|
onclick="copyToClipboard('{{.}}')">Kopieren</button>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user