package ui import ( "html/template" "log" "net/http" "streifling.com/jason/cpolis/cmd/data" "streifling.com/jason/cpolis/cmd/feed" ) func HandleLogin(db *data.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { user := r.PostFormValue("username") pass := r.PostFormValue("password") id, err := db.GetID(user) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) // TODO: und nun? } if err := db.CheckPassword(id, pass); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } else { template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil) } } } func HandleFinishedEdit(f *feed.Feed) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { title := r.PostFormValue("editor-title") desc := r.PostFormValue("editor-desc") mdContent := r.PostFormValue("editor-text") content, err := data.ConvertToHTML(mdContent) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Panicln(err) } feed.AddToFeed(f, title, desc, content) feed.SaveFeed(f, "tmp/rss.gob") // template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "html-result", rssItem) } }