Compare commits
4 Commits
5dc5590da9
...
d328ddb749
Author | SHA1 | Date | |
---|---|---|---|
d328ddb749 | |||
ac740cf4b8 | |||
b7d82f15e9 | |||
b4003c8216 |
@ -31,12 +31,11 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) {
|
||||
entry := atom.NewEntry(articleTitle)
|
||||
entry.ID = atom.NewID(fmt.Sprint("urn:entry:", article.ID))
|
||||
entry.Published = atom.NewDate(article.Created)
|
||||
entry.Content = atom.NewContent(atom.OutOfLine, "text/hmtl", article.ContentLink)
|
||||
|
||||
if article.AutoGenerated {
|
||||
entry.Content = atom.NewContent(atom.InlineText, "text", "")
|
||||
entry.Summary = atom.NewText("text", "automatically generated")
|
||||
} else {
|
||||
entry.Content = atom.NewContent(atom.OutOfLine, "text/hmtl", article.ContentLink)
|
||||
|
||||
articleSummary, err := ConvertToPlain(article.Summary)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting description to plain text for Atom feed: %v", err)
|
||||
|
@ -52,7 +52,7 @@ func newConfig() *Config {
|
||||
PDFDir: "/var/www/cpolis/pdfs",
|
||||
PicsDir: "/var/www/cpolis/pics",
|
||||
Port: ":8080",
|
||||
Version: "v0.13.3",
|
||||
Version: "v0.13.4",
|
||||
WebDir: "/var/www/cpolis/web",
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,15 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
f "streifling.com/jason/cpolis/cmd/frontend"
|
||||
)
|
||||
|
||||
func ServeImage(c *b.Config) http.HandlerFunc {
|
||||
func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !tokenIsVerified(w, r, c) {
|
||||
return
|
||||
if _, err := f.GetSession(w, r, c, s); err != nil {
|
||||
if !tokenIsVerified(w, r, c) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
absFilepath, err := filepath.Abs(c.PicsDir)
|
||||
|
@ -32,7 +32,7 @@ type EditorHTMLData struct {
|
||||
|
||||
func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -64,7 +64,7 @@ func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -157,7 +157,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 {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -245,7 +245,7 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func ShowUnpublishedUnrejectedAndPublishedRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -289,7 +289,7 @@ func ShowUnpublishedUnrejectedAndPublishedRejectedArticles(c *b.Config, db *b.DB
|
||||
|
||||
func ShowRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -327,7 +327,7 @@ func ShowRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerF
|
||||
|
||||
func ReviewRejectedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -392,7 +392,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 {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -486,7 +486,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 {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -521,7 +521,7 @@ func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func ShowCurrentIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -545,7 +545,7 @@ func ShowCurrentIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc
|
||||
|
||||
func ShowPublishedArticles(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -582,7 +582,7 @@ func ShowPublishedArticles(c *b.Config, db *b.DB, s *b.CookieStore, action strin
|
||||
|
||||
func ReviewArticle(c *b.Config, db *b.DB, s *b.CookieStore, action, title, button string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -662,7 +662,7 @@ func ReviewArticle(c *b.Config, db *b.DB, s *b.CookieStore, action, title, butto
|
||||
|
||||
func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -715,7 +715,7 @@ func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func AllowEditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -774,7 +774,7 @@ func AllowEditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc
|
||||
|
||||
func EditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -5,14 +5,13 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
)
|
||||
|
||||
func UploadImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -45,7 +44,7 @@ func UploadImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func UploadBanner(c *b.Config, s *b.CookieStore, fileKey, htmlFile, htmlTemplate string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -81,22 +80,3 @@ func UploadBanner(c *b.Config, s *b.CookieStore, fileKey, htmlFile, htmlTemplate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
absFilepath, err := filepath.Abs(c.PicsDir)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, absFilepath+"/"+r.PathValue("img"))
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
|
||||
func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
func UploadPDF(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -26,8 +26,8 @@ func saveSession(w http.ResponseWriter, r *http.Request, s *b.CookieStore, u *b.
|
||||
return nil
|
||||
}
|
||||
|
||||
// getSession is used for verifying that the user is logged in and returns their session and an error.
|
||||
func getSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.CookieStore) (*b.Session, error) {
|
||||
// GetSession is used for verifying that the user is logged in and returns their session and an error.
|
||||
func GetSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.CookieStore) (*b.Session, error) {
|
||||
msg := "Keine gültige Session. Bitte erneut anmelden."
|
||||
tmpl, tmplErr := template.ParseFiles(c.WebDir+"/templates/index.html", c.WebDir+"/templates/login.html")
|
||||
|
||||
@ -142,7 +142,7 @@ func Login(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -167,7 +167,7 @@ func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func CreateTag(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -27,7 +27,7 @@ func CreateTag(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func AddTag(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -27,7 +27,7 @@ func checkUserStrings(user *b.User) (string, int, bool) {
|
||||
|
||||
func CreateUser(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -44,7 +44,7 @@ func CreateUser(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -122,7 +122,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 {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -147,7 +147,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 {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -293,7 +293,7 @@ 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 {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -325,7 +325,7 @@ func ShowAllUsers(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.H
|
||||
|
||||
func EditUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := getSession(w, r, c, s); err != nil {
|
||||
if _, err := GetSession(w, r, c, s); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -356,7 +356,7 @@ func EditUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -440,7 +440,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 {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(w, r, c, s)
|
||||
session, err := GetSession(w, r, c, s)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -68,8 +68,7 @@ func main() {
|
||||
mux.HandleFunc("GET /article/write", f.WriteArticle(config, db, store))
|
||||
mux.HandleFunc("GET /atom/serve", c.ServeAtomFeed(config))
|
||||
mux.HandleFunc("GET /hub", f.ShowHub(config, db, store))
|
||||
mux.HandleFunc("GET /image/{img}", f.ServeImage(config, store))
|
||||
mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config))
|
||||
mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config, store))
|
||||
mux.HandleFunc("GET /issue/this", f.ShowCurrentIssue(config, db, store))
|
||||
mux.HandleFunc("GET /logout", f.Logout(config, store))
|
||||
mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config))
|
||||
|
@ -90,7 +90,7 @@
|
||||
|
||||
{{define "article-banner-template"}}
|
||||
<div id="article-banner-container">
|
||||
<img src="/image/{{.BannerImage}}" alt="">
|
||||
<img src="/image/serve/{{.BannerImage}}" alt="">
|
||||
<input id="article-banner-url" name="article-banner-url" type="hidden" value="{{.BannerImage}}" />
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
<div>
|
||||
<div class="w-full" id="article-banner-container">
|
||||
<img src="/image/{{.BannerImage}}" alt="Banner Image">
|
||||
<img src="/image/serve/{{.BannerImage}}" alt="Banner Image">
|
||||
</div>
|
||||
|
||||
<span>Titel</span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user