Compare commits
27 Commits
new_rss
...
e5bdc235b6
Author | SHA1 | Date | |
---|---|---|---|
e5bdc235b6 | |||
655992c8b2 | |||
aa7fcd6075 | |||
f9cc90a948 | |||
7f2433c30b | |||
f34efc95dd | |||
935d0a1ca4 | |||
48d4d482b2 | |||
8dae3ca21e | |||
6f02852212 | |||
4cc2110c4b | |||
04cbee097c | |||
93423ae606 | |||
41113b24a8 | |||
2247f316a3 | |||
9beedf9b2b | |||
7d6f96a185 | |||
8d47146a7c | |||
4853184ba1 | |||
50895249df | |||
6e91253908 | |||
9bb6010319 | |||
75a0af055c | |||
171a0dd250 | |||
372882a252 | |||
2d0b53a254 | |||
2447f50bac |
@ -1,9 +1,6 @@
|
|||||||
package data
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -11,29 +8,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Article struct {
|
type Article struct {
|
||||||
Tags *TagList
|
|
||||||
Title string
|
Title string
|
||||||
Author string
|
Author string
|
||||||
Created time.Time
|
Created time.Time
|
||||||
Desc string
|
Desc string
|
||||||
Content string
|
Content string
|
||||||
|
Tags []string
|
||||||
UUID uuid.UUID
|
UUID uuid.UUID
|
||||||
AuthorID int64
|
AuthorID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArticleList struct {
|
type ArticleList struct {
|
||||||
addCh chan *Article
|
addCh chan *Article
|
||||||
delCh chan uuid.UUID
|
delCh chan uuid.UUID
|
||||||
retCh chan *Article
|
retCh chan *Article
|
||||||
getCh chan []Article
|
getCh chan []Article
|
||||||
articles []*Article
|
list []*Article
|
||||||
wg sync.WaitGroup
|
|
||||||
}
|
|
||||||
|
|
||||||
type TagList struct {
|
|
||||||
addCh chan string
|
|
||||||
getCh chan []string
|
|
||||||
tags []string
|
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,29 +36,22 @@ func minArticleList() *ArticleList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minTagList() *TagList {
|
func (l *ArticleList) start() {
|
||||||
return &TagList{
|
l.wg.Done()
|
||||||
addCh: make(chan string),
|
|
||||||
getCh: make(chan []string),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (al *ArticleList) start() {
|
|
||||||
al.wg.Done()
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case article := <-al.addCh:
|
case article := <-l.addCh:
|
||||||
al.articles = append(al.articles, article)
|
l.list = append(l.list, article)
|
||||||
case uuid := <-al.delCh:
|
case uuid := <-l.delCh:
|
||||||
for i, article := range al.articles {
|
for i, article := range l.list {
|
||||||
if article.UUID == uuid {
|
if article.UUID == uuid {
|
||||||
al.articles = append(al.articles[:i], al.articles[i+1:]...)
|
l.list = append(l.list[:i], l.list[i+1:]...)
|
||||||
al.retCh <- article
|
l.retCh <- article
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case al.getCh <- func() []Article {
|
case l.getCh <- func() []Article {
|
||||||
var list []Article
|
var list []Article
|
||||||
for _, article := range al.articles {
|
for _, article := range l.list {
|
||||||
list = append(list, *article)
|
list = append(list, *article)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
@ -77,20 +60,9 @@ func (al *ArticleList) start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tl *TagList) start() {
|
|
||||||
tl.wg.Done()
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case tag := <-tl.addCh:
|
|
||||||
tl.tags = append(tl.tags, tag)
|
|
||||||
case tl.getCh <- tl.tags:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewArticleList() *ArticleList {
|
func NewArticleList() *ArticleList {
|
||||||
list := minArticleList()
|
list := minArticleList()
|
||||||
list.articles = []*Article{}
|
list.list = []*Article{}
|
||||||
|
|
||||||
list.wg.Add(1)
|
list.wg.Add(1)
|
||||||
go list.start()
|
go list.start()
|
||||||
@ -99,104 +71,19 @@ func NewArticleList() *ArticleList {
|
|||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
func (al *ArticleList) Add(a *Article) {
|
func (l *ArticleList) Add(a *Article) {
|
||||||
al.addCh <- a
|
l.addCh <- a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (al *ArticleList) Release(uuid uuid.UUID) (*Article, bool) {
|
func (l *ArticleList) Release(uuid uuid.UUID) (*Article, bool) {
|
||||||
al.delCh <- uuid
|
l.delCh <- uuid
|
||||||
article := <-al.retCh
|
article := <-l.retCh
|
||||||
if article == nil {
|
if article == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
return article, true
|
return article, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (al *ArticleList) Get() []Article {
|
func (l *ArticleList) Get() []Article {
|
||||||
return <-al.getCh
|
return <-l.getCh
|
||||||
}
|
|
||||||
|
|
||||||
func (al *ArticleList) Save(filename string) error {
|
|
||||||
file, err := os.Create(filename)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error creating key file: %v", err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
encoder := gob.NewEncoder(file)
|
|
||||||
articles := al.Get()
|
|
||||||
err = encoder.Encode(articles)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error ecoding key: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadArticleList(filename string) (*ArticleList, error) {
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error opening key file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder := gob.NewDecoder(file)
|
|
||||||
articleList := NewArticleList()
|
|
||||||
err = decoder.Decode(&articleList.articles)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error decoding key: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return articleList, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTagList() *TagList {
|
|
||||||
list := minTagList()
|
|
||||||
list.tags = []string{}
|
|
||||||
|
|
||||||
list.wg.Add(1)
|
|
||||||
go list.start()
|
|
||||||
list.wg.Wait()
|
|
||||||
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tl *TagList) Add(tag string) {
|
|
||||||
tl.addCh <- tag
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tl *TagList) Get() []string {
|
|
||||||
return <-tl.getCh
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tl *TagList) Save(filename string) error {
|
|
||||||
file, err := os.Create(filename)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error creating key file: %v", err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
encoder := gob.NewEncoder(file)
|
|
||||||
tags := tl.Get()
|
|
||||||
err = encoder.Encode(tags)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error ecoding key: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadTagList(filename string) (*TagList, error) {
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error opening key file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder := gob.NewDecoder(file)
|
|
||||||
tagList := NewTagList()
|
|
||||||
err = decoder.Decode(&tagList.tags)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error decoding key: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return tagList, nil
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func OpenDB(dbName string) (*DB, error) {
|
|||||||
return &db, nil
|
return &db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) AddUser(user *User, pass string) error {
|
func (db *DB) AddUser(user User, pass string) error {
|
||||||
hashedPass, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
|
hashedPass, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating password hash: %v", err)
|
return fmt.Errorf("error creating password hash: %v", err)
|
||||||
|
106
cmd/data/rss.go
Normal file
106
cmd/data/rss.go
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package data
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/gob"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/gorilla/feeds"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Feed struct {
|
||||||
|
addCh chan *feeds.Item
|
||||||
|
setCh chan feeds.Feed
|
||||||
|
getCh chan feeds.Feed
|
||||||
|
feed feeds.Feed
|
||||||
|
wg sync.WaitGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
func minFeed() *Feed {
|
||||||
|
return &Feed{
|
||||||
|
addCh: make(chan *feeds.Item),
|
||||||
|
setCh: make(chan feeds.Feed),
|
||||||
|
getCh: make(chan feeds.Feed),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Feed) start() {
|
||||||
|
f.wg.Done()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case item := <-f.addCh:
|
||||||
|
f.feed.Items = append(f.feed.Items, item)
|
||||||
|
case f.getCh <- f.feed:
|
||||||
|
case f.feed = <-f.setCh:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFeed(title, link, desc string) *Feed {
|
||||||
|
feed := minFeed()
|
||||||
|
feed.feed = feeds.Feed{
|
||||||
|
Title: title,
|
||||||
|
Link: &feeds.Link{Href: link},
|
||||||
|
Description: desc,
|
||||||
|
}
|
||||||
|
|
||||||
|
feed.wg.Add(1)
|
||||||
|
go feed.start()
|
||||||
|
feed.wg.Wait()
|
||||||
|
|
||||||
|
return feed
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Feed) Get() feeds.Feed {
|
||||||
|
return <-f.getCh
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Feed) Set(feed feeds.Feed) {
|
||||||
|
f.setCh <- feed
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpenFeed(filename string) (*Feed, error) {
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error opening file %v: %v", filename, err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
feed := minFeed()
|
||||||
|
feed.wg.Add(1)
|
||||||
|
go feed.start()
|
||||||
|
feed.wg.Wait()
|
||||||
|
|
||||||
|
decoder := gob.NewDecoder(file)
|
||||||
|
tmpFeed := new(feeds.Feed)
|
||||||
|
err = decoder.Decode(tmpFeed)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decoding file %v: %v", filename, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
feed.Set(*tmpFeed)
|
||||||
|
|
||||||
|
return feed, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Feed) Save(filename string) error {
|
||||||
|
file, err := os.Create(filename)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error creating file %v: %v", filename, err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
encoder := gob.NewEncoder(file)
|
||||||
|
feed := f.Get()
|
||||||
|
err = encoder.Encode(feed)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error encoding file %v: %v", filename, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Feed) Add(i *feeds.Item) {
|
||||||
|
f.addCh <- i
|
||||||
|
}
|
@ -11,11 +11,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AddUserData struct {
|
type AddUserData struct {
|
||||||
*data.User
|
|
||||||
Msg string
|
Msg string
|
||||||
|
data.User
|
||||||
}
|
}
|
||||||
|
|
||||||
func inputsEmpty(user *data.User, pass, pass2 string) bool {
|
func inputsEmpty(user data.User, pass, pass2 string) bool {
|
||||||
return len(user.UserName) == 0 ||
|
return len(user.UserName) == 0 ||
|
||||||
len(user.FirstName) == 0 ||
|
len(user.FirstName) == 0 ||
|
||||||
len(user.LastName) == 0 ||
|
len(user.LastName) == 0 ||
|
||||||
@ -23,7 +23,7 @@ func inputsEmpty(user *data.User, pass, pass2 string) bool {
|
|||||||
len(pass2) == 0
|
len(pass2) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkUserStrings(user *data.User) (string, int, bool) {
|
func checkUserStrings(user data.User) (string, int, bool) {
|
||||||
userLen := 15
|
userLen := 15
|
||||||
nameLen := 50
|
nameLen := 50
|
||||||
|
|
||||||
@ -38,12 +38,14 @@ func checkUserStrings(user *data.User) (string, int, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUser(w http.ResponseWriter, r *http.Request) {
|
func CreateUser() http.HandlerFunc {
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
||||||
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddUser(db *data.DB, s *data.CookieStore) http.HandlerFunc {
|
func AddUser(db *data.DB) 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 {
|
||||||
@ -53,7 +55,7 @@ func AddUser(db *data.DB, s *data.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
htmlData := AddUserData{
|
htmlData := AddUserData{
|
||||||
User: &data.User{
|
User: data.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"),
|
||||||
@ -92,36 +94,12 @@ func AddUser(db *data.DB, s *data.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
num, err := db.CountEntries()
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if num == 0 {
|
|
||||||
if htmlData.Role != data.Admin {
|
|
||||||
htmlData.Msg = "Der erste Benutzer muss ein Administrator sein."
|
|
||||||
htmlData.Role = data.Admin
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", htmlData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := saveSession(w, r, s, htmlData.User); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := db.AddUser(htmlData.User, pass); err != nil {
|
if err := db.AddUser(htmlData.User, pass); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", 0)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.streifling.com/jason/rss"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/gorilla/feeds"
|
||||||
"streifling.com/jason/cpolis/cmd/data"
|
"streifling.com/jason/cpolis/cmd/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,14 +25,12 @@ func ShowHub(s *data.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteArticle(tl *data.TagList) http.HandlerFunc {
|
func WriteArticle(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
tmpl, err := template.ParseFiles("web/templates/editor.html")
|
||||||
tmpl, err := template.ParseFiles("web/templates/editor.html")
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", tl.Get())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FinishArticle(al *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
func FinishArticle(l *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
article := new(data.Article)
|
article := new(data.Article)
|
||||||
var err error
|
var err error
|
||||||
@ -70,8 +68,7 @@ func FinishArticle(al *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
|||||||
article.Created = time.Now()
|
article.Created = time.Now()
|
||||||
article.AuthorID = session.Values["id"].(int64)
|
article.AuthorID = session.Values["id"].(int64)
|
||||||
|
|
||||||
al.Add(article)
|
l.Add(article)
|
||||||
al.Save("tmp/articles.gob")
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
tmpl = template.Must(tmpl, err)
|
tmpl = template.Must(tmpl, err)
|
||||||
@ -79,14 +76,14 @@ func FinishArticle(al *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowUnpublishedArticles(al *data.ArticleList) http.HandlerFunc {
|
func ShowUnpublishedArticles(l *data.ArticleList) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := template.ParseFiles("web/templates/unpublished-articles.html")
|
tmpl, err := template.ParseFiles("web/templates/unpublished-articles.html")
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", al.Get())
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", l.Get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReviewArticle(al *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
func ReviewArticle(l *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
uuid, err := uuid.Parse(r.PostFormValue("uuid"))
|
uuid, err := uuid.Parse(r.PostFormValue("uuid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -95,7 +92,7 @@ func ReviewArticle(al *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, article := range al.Get() {
|
for _, article := range l.Get() {
|
||||||
if article.UUID == uuid {
|
if article.UUID == uuid {
|
||||||
tmpl, err := template.ParseFiles("web/templates/to-be-published.html")
|
tmpl, err := template.ParseFiles("web/templates/to-be-published.html")
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", article)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", article)
|
||||||
@ -116,7 +113,7 @@ func ReviewArticle(al *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PublishArticle(f *rss.Feed, al *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
func PublishArticle(f *data.Feed, l *data.ArticleList, s *data.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
uuid, err := uuid.Parse(r.PostFormValue("uuid"))
|
uuid, err := uuid.Parse(r.PostFormValue("uuid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,7 +122,7 @@ func PublishArticle(f *rss.Feed, al *data.ArticleList, s *data.CookieStore) http
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
article, ok := al.Release(uuid)
|
article, ok := l.Release(uuid)
|
||||||
if !ok {
|
if !ok {
|
||||||
// TODO: Warnung anzeigen
|
// TODO: Warnung anzeigen
|
||||||
// msg = "Alle Felder müssen ausgefüllt werden."
|
// msg = "Alle Felder müssen ausgefüllt werden."
|
||||||
@ -134,6 +131,14 @@ func PublishArticle(f *rss.Feed, al *data.ArticleList, s *data.CookieStore) http
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f.Add(&feeds.Item{
|
||||||
|
Title: article.Title,
|
||||||
|
Created: article.Created,
|
||||||
|
Description: article.Desc,
|
||||||
|
Content: article.Content,
|
||||||
|
})
|
||||||
|
f.Save("tmp/rss.gob")
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
tmpl, err := template.ParseFiles("web/templates/login.html")
|
||||||
@ -141,14 +146,6 @@ func PublishArticle(f *rss.Feed, al *data.ArticleList, s *data.CookieStore) http
|
|||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
item := rss.NewItem()
|
|
||||||
item.Title = article.Title
|
|
||||||
item.Author = article.Author
|
|
||||||
item.Description = article.Desc
|
|
||||||
item.Content = &rss.Content{Value: article.Content}
|
|
||||||
f.Channels[0].AddItem(item)
|
|
||||||
f.Save("tmp/rss.gob")
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
tmpl = template.Must(tmpl, err)
|
tmpl = template.Must(tmpl, err)
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
package ui
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"streifling.com/jason/cpolis/cmd/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateTag(w http.ResponseWriter, r *http.Request) {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-tag.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddTag(tl *data.TagList, s *data.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
tl.Add(r.PostFormValue("tag"))
|
|
||||||
tl.Save("tmp/tags.gob")
|
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,12 +5,13 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.streifling.com/jason/rss"
|
"streifling.com/jason/cpolis/cmd/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ShowRSS(f *rss.Feed) http.HandlerFunc {
|
func ShowRSS(f *data.Feed) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
rss, err := f.ToXML()
|
feed := f.Get()
|
||||||
|
rss, err := feed.ToRss()
|
||||||
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)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -9,23 +8,6 @@ import (
|
|||||||
"streifling.com/jason/cpolis/cmd/data"
|
"streifling.com/jason/cpolis/cmd/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
func saveSession(w http.ResponseWriter, r *http.Request, s *data.CookieStore, u *data.User) error {
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error getting session: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
session.Values["authenticated"] = true
|
|
||||||
session.Values["id"] = u.ID
|
|
||||||
session.Values["name"] = u.FirstName + u.LastName
|
|
||||||
session.Values["role"] = u.Role
|
|
||||||
if err := session.Save(r, w); err != nil {
|
|
||||||
return fmt.Errorf("error saving session: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func HomePage(db *data.DB, s *data.CookieStore) http.HandlerFunc {
|
func HomePage(db *data.DB, s *data.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
numRows, err := db.CountEntries()
|
numRows, err := db.CountEntries()
|
||||||
@ -78,7 +60,18 @@ func Login(db *data.DB, s *data.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveSession(w, r, s, user); err != nil {
|
session, err := s.Get(r, "cookie")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session.Values["authenticated"] = true
|
||||||
|
session.Values["id"] = user.ID
|
||||||
|
session.Values["name"] = user.FirstName + user.LastName
|
||||||
|
session.Values["role"] = user.Role
|
||||||
|
if err := session.Save(r, w); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
2
go.mod
2
go.mod
@ -3,9 +3,9 @@ module streifling.com/jason/cpolis
|
|||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.streifling.com/jason/rss v0.0.0-20240305145359-7d49b2cb25fc
|
|
||||||
github.com/go-sql-driver/mysql v1.7.1
|
github.com/go-sql-driver/mysql v1.7.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/gorilla/feeds v1.1.2
|
||||||
github.com/gorilla/sessions v1.2.2
|
github.com/gorilla/sessions v1.2.2
|
||||||
github.com/microcosm-cc/bluemonday v1.0.26
|
github.com/microcosm-cc/bluemonday v1.0.26
|
||||||
github.com/yuin/goldmark v1.7.0
|
github.com/yuin/goldmark v1.7.0
|
||||||
|
12
go.sum
12
go.sum
@ -1,7 +1,3 @@
|
|||||||
git.streifling.com/jason/rss v0.0.0-20240305140009-a59d3f112892 h1:miU3U9H8zSoYprEaG7xaGLMb4CcGLjGt7McC8Wrf+Vs=
|
|
||||||
git.streifling.com/jason/rss v0.0.0-20240305140009-a59d3f112892/go.mod h1:gpZF0nZbQSstMpyHD9DTAvlQEG7v4pjO5c7aIMWM4Jg=
|
|
||||||
git.streifling.com/jason/rss v0.0.0-20240305145359-7d49b2cb25fc h1:vJ36ouI2wTK+jFktnqyAfFHoYnoznAgAo1nUzvMzCvQ=
|
|
||||||
git.streifling.com/jason/rss v0.0.0-20240305145359-7d49b2cb25fc/go.mod h1:gpZF0nZbQSstMpyHD9DTAvlQEG7v4pjO5c7aIMWM4Jg=
|
|
||||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||||
@ -12,12 +8,20 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
|||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
||||||
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
||||||
|
github.com/gorilla/feeds v1.1.2 h1:pxzZ5PD3RJdhFH2FsJJ4x6PqMqbgFk1+Vez4XWBW8Iw=
|
||||||
|
github.com/gorilla/feeds v1.1.2/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y=
|
||||||
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
||||||
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
||||||
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
|
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
|
||||||
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
|
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
|
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
|
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
|
||||||
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||||
|
23
main.go
23
main.go
@ -15,8 +15,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logFile, err := os.OpenFile("tmp/cpolis.log",
|
logFile, err := os.Create("tmp/cpolis.log")
|
||||||
os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
@ -47,33 +46,23 @@ func main() {
|
|||||||
}
|
}
|
||||||
store := data.NewCookieStore(key)
|
store := data.NewCookieStore(key)
|
||||||
|
|
||||||
articleList, err := data.LoadArticleList("tmp/articles.gob")
|
articleList := data.NewArticleList()
|
||||||
if err != nil {
|
|
||||||
articleList = data.NewArticleList()
|
|
||||||
}
|
|
||||||
|
|
||||||
tagList, err := data.LoadTagList("tmp/tags.gob")
|
|
||||||
if err != nil {
|
|
||||||
tagList = data.NewTagList()
|
|
||||||
}
|
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir("web/static/"))))
|
mux.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir("web/static/"))))
|
||||||
mux.HandleFunc("/", ui.HomePage(db, store))
|
mux.HandleFunc("/", ui.HomePage(db, store))
|
||||||
|
|
||||||
mux.HandleFunc("GET /create-tag/", ui.CreateTag)
|
|
||||||
mux.HandleFunc("GET /create-user/", ui.CreateUser)
|
|
||||||
mux.HandleFunc("GET /hub/", ui.ShowHub(store))
|
mux.HandleFunc("GET /hub/", ui.ShowHub(store))
|
||||||
mux.HandleFunc("GET /rss/", ui.ShowRSS(feed))
|
mux.HandleFunc("GET /rss/", ui.ShowRSS(feed))
|
||||||
mux.HandleFunc("GET /unpublished-articles/", ui.ShowUnpublishedArticles(articleList))
|
|
||||||
mux.HandleFunc("GET /write-article/", ui.WriteArticle(tagList))
|
|
||||||
|
|
||||||
mux.HandleFunc("POST /add-tag/", ui.AddTag(tagList, store))
|
mux.HandleFunc("POST /add-user/", ui.AddUser(db))
|
||||||
mux.HandleFunc("POST /add-user/", ui.AddUser(db, store))
|
mux.HandleFunc("POST /create-user/", ui.CreateUser())
|
||||||
mux.HandleFunc("POST /finish-article/", ui.FinishArticle(articleList, store))
|
mux.HandleFunc("POST /finish-article/", ui.FinishArticle(articleList, store))
|
||||||
mux.HandleFunc("POST /login/", ui.Login(db, store))
|
mux.HandleFunc("POST /login/", ui.Login(db, store))
|
||||||
mux.HandleFunc("POST /review-article/", ui.ReviewArticle(articleList, store))
|
mux.HandleFunc("POST /review-article/", ui.ReviewArticle(articleList, store))
|
||||||
mux.HandleFunc("POST /publish-article/", ui.PublishArticle(feed, articleList, store))
|
mux.HandleFunc("POST /publish-article/", ui.PublishArticle(feed, articleList, store))
|
||||||
|
mux.HandleFunc("POST /unpublished-articles/", ui.ShowUnpublishedArticles(articleList))
|
||||||
|
mux.HandleFunc("POST /write-article/", ui.WriteArticle)
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(":8080", mux))
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
{{define "page-content"}}
|
|
||||||
<h2>Neuer Benutzer</h2>
|
|
||||||
<form>
|
|
||||||
<input required name="tag" placeholder="Tag" type="text" />
|
|
||||||
<input type="submit" value="Anlegen" hx-post="/add-tag/" hx-target="#page-content" />
|
|
||||||
</form>
|
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
|
||||||
{{end}}
|
|
@ -8,16 +8,15 @@
|
|||||||
<input required name="first-name" placeholder="Vorname" type="text" value="{{.FirstName}}" />
|
<input required name="first-name" placeholder="Vorname" type="text" value="{{.FirstName}}" />
|
||||||
<input required name="last-name" placeholder="Nachname" type="text" value="{{.LastName}}" />
|
<input required name="last-name" placeholder="Nachname" type="text" value="{{.LastName}}" />
|
||||||
|
|
||||||
<input required id="writer" name="role" type="radio" value="2" {{if eq .Role 2 }}checked{{end}} />
|
|
||||||
<label for="writer">Schreiber</label>
|
<label for="writer">Schreiber</label>
|
||||||
<input required id="editor" name="role" type="radio" value="1" {{if eq .Role 1 }}checked{{end}} />
|
<input required id="writer" name="role" type="radio" value="2" {{if eq .Role "2" }}checked{{end}} />
|
||||||
<label for="editor">Redakteur</label>
|
<label for="editor">Redakteur</label>
|
||||||
<input required id="admin" name="role" type="radio" value="0" {{if eq .Role 0 }}checked{{end}} />
|
<input required id="editor" name="role" type="radio" value="1" {{if eq .Role "1" }}checked{{end}} />
|
||||||
<label for="admin">Admin</label>
|
<label for="admin">Admin</label>
|
||||||
|
<input required id="admin" name="role" type="radio" value="0" {{if eq .Role "0" }}checked{{end}} />
|
||||||
|
|
||||||
<input type="submit" value="Anlegen" hx-post="/add-user/" hx-target="#page-content" />
|
<input type="submit" value="Anlegen" hx-post="/add-user/" hx-target="#page-content" />
|
||||||
</form>
|
</form>
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var msg = "{{.Msg}}";
|
var msg = "{{.Msg}}";
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
<input name="editor-title" placeholder="Titel" type="text" />
|
<input name="editor-title" placeholder="Titel" type="text" />
|
||||||
<textarea name="editor-desc" placeholder="Beschreibung"></textarea>
|
<textarea name="editor-desc" placeholder="Beschreibung"></textarea>
|
||||||
<textarea name="editor-text" placeholder="Artikel"></textarea>
|
<textarea name="editor-text" placeholder="Artikel"></textarea>
|
||||||
{{range .}}
|
|
||||||
<input id="{{.}}" name="tags" type="checkbox" value="{{.}}" />
|
|
||||||
<label for="{{.}}">{{.}}</label>
|
|
||||||
{{end}}
|
|
||||||
<input type="submit" value="Senden" hx-post="/finish-article/" hx-target="#page-content" />
|
<input type="submit" value="Senden" hx-post="/finish-article/" hx-target="#page-content" />
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Hub</h2>
|
<h2>Hub</h2>
|
||||||
<button hx-get="/write-article/" hx-target="#page-content">Artikel schreiben</button>
|
<button hx-post="/write-article/" hx-target="#page-content">Artikel schreiben</button>
|
||||||
<button hx-get="/rss/" hx-target="#page-content">RSS Feed</button>
|
<button hx-post="/rss/" hx-target="#page-content">RSS Feed</button>
|
||||||
{{if lt . 2}}
|
|
||||||
<button hx-get="/unpublished-articles/" hx-target="#page-content">Unveröffentlichte Artikel</button>
|
|
||||||
<button hx-get="/create-tag/" hx-target="#page-content">Neuer Tag</button>
|
|
||||||
{{end}}
|
|
||||||
{{if eq . 0}}
|
{{if eq . 0}}
|
||||||
<button hx-get="/create-user/" hx-target="#page-content">Benutzer hinzufügen</button>
|
<button hx-post="/create-user/" hx-target="#page-content">Benutzer hinzufügen</button>
|
||||||
|
{{end}}
|
||||||
|
{{if lt . 2}}
|
||||||
|
<button hx-post="/unpublished-articles/" hx-target="#page-content">Unveröffentlichte Artikel</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Reference in New Issue
Block a user