Merge branch 'devel'
This commit is contained in:
commit
0e768c9f61
@ -23,15 +23,6 @@ const (
|
||||
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) {
|
||||
session, err := s.Get(r, "cookie")
|
||||
@ -55,6 +46,15 @@ func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
type editorHTMLData struct {
|
||||
Title string
|
||||
Description string
|
||||
Content string
|
||||
HTMLContent template.HTML
|
||||
Tags []*b.Tag
|
||||
Mode int
|
||||
}
|
||||
|
||||
session, err := s.Get(r, "cookie")
|
||||
if err != nil {
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/login.html")
|
||||
@ -62,11 +62,11 @@ func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||
}
|
||||
|
||||
var data EditorHTMLData
|
||||
var data editorHTMLData
|
||||
if session.Values["article"] == nil {
|
||||
data = EditorHTMLData{}
|
||||
data = editorHTMLData{}
|
||||
} else {
|
||||
data = session.Values["article"].(EditorHTMLData)
|
||||
data = session.Values["article"].(editorHTMLData)
|
||||
}
|
||||
data.Mode = EditMode
|
||||
|
||||
@ -489,51 +489,3 @@ func UploadImage(c *b.Config) http.HandlerFunc {
|
||||
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 = template.Must(tmpl, err)
|
||||
tmpl.ExecuteTemplate(w, "page-content", data)
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
|
||||
func init() {
|
||||
gob.Register(b.User{})
|
||||
gob.Register(f.EditorHTMLData{})
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -74,7 +73,6 @@ func main() {
|
||||
mux.HandleFunc("POST /add-tag", f.AddTag(config, db, store))
|
||||
mux.HandleFunc("POST /add-user", f.AddUser(config, db, store))
|
||||
mux.HandleFunc("POST /login", f.Login(config, db, store))
|
||||
mux.HandleFunc("POST /preview-article", f.PreviewArticle(config, store))
|
||||
mux.HandleFunc("POST /resubmit-article/{id}", f.ResubmitArticle(config, db, store))
|
||||
mux.HandleFunc("POST /submit-article", f.SubmitArticle(config, db, store))
|
||||
mux.HandleFunc("POST /update-self", f.UpdateSelf(config, db, store))
|
||||
|
Loading…
x
Reference in New Issue
Block a user