2024-02-18 07:20:51 +01:00
|
|
|
package main
|
|
|
|
|
2024-02-18 10:07:49 +01:00
|
|
|
import (
|
2024-03-03 09:16:49 +01:00
|
|
|
"encoding/gob"
|
2024-02-18 10:07:49 +01:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2024-02-24 11:41:01 +01:00
|
|
|
"os"
|
2024-02-18 10:07:49 +01:00
|
|
|
|
2024-03-09 10:27:04 +01:00
|
|
|
"streifling.com/jason/cpolis/cmd/control"
|
|
|
|
"streifling.com/jason/cpolis/cmd/model"
|
|
|
|
"streifling.com/jason/cpolis/cmd/view"
|
2024-02-18 10:07:49 +01:00
|
|
|
)
|
2024-02-18 07:20:51 +01:00
|
|
|
|
2024-03-03 09:16:49 +01:00
|
|
|
func init() {
|
2024-03-09 10:27:04 +01:00
|
|
|
gob.Register(model.User{})
|
2024-03-03 09:16:49 +01:00
|
|
|
}
|
|
|
|
|
2024-02-18 07:20:51 +01:00
|
|
|
func main() {
|
2024-03-03 13:56:49 +01:00
|
|
|
logFile, err := os.OpenFile("tmp/cpolis.log",
|
|
|
|
os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
2024-02-24 11:41:01 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
defer logFile.Close()
|
2024-03-07 20:11:28 +01:00
|
|
|
// log.SetOutput(logFile)
|
2024-02-24 11:41:01 +01:00
|
|
|
|
2024-03-09 10:27:04 +01:00
|
|
|
db, err := model.OpenDB("cpolis")
|
2024-02-18 16:37:13 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2024-02-22 19:27:41 +01:00
|
|
|
defer db.Close()
|
2024-02-18 16:37:13 +01:00
|
|
|
|
2024-03-09 10:27:04 +01:00
|
|
|
key, err := control.LoadKey("tmp/key.gob")
|
2024-03-03 09:16:49 +01:00
|
|
|
if err != nil {
|
2024-03-09 10:27:04 +01:00
|
|
|
key, err = control.NewKey()
|
2024-03-03 09:16:49 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2024-03-09 10:27:04 +01:00
|
|
|
control.SaveKey(key, "tmp/key.gob")
|
2024-03-03 09:16:49 +01:00
|
|
|
}
|
2024-03-09 10:27:04 +01:00
|
|
|
store := control.NewCookieStore(key)
|
2024-03-03 09:16:49 +01:00
|
|
|
|
2024-02-18 14:31:28 +01:00
|
|
|
mux := http.NewServeMux()
|
2024-03-07 15:31:00 +01:00
|
|
|
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
|
|
|
http.FileServer(http.Dir("web/static/"))))
|
2024-03-09 10:27:04 +01:00
|
|
|
mux.HandleFunc("/", view.HomePage(db, store))
|
2024-02-24 10:56:12 +01:00
|
|
|
|
2024-03-09 10:27:04 +01:00
|
|
|
mux.HandleFunc("GET /create-tag/", view.CreateTag)
|
|
|
|
mux.HandleFunc("GET /create-user/", view.CreateUser)
|
2024-03-11 21:08:27 +01:00
|
|
|
mux.HandleFunc("GET /edit-user/", view.EditUser(db, store))
|
2024-03-10 15:03:46 +01:00
|
|
|
mux.HandleFunc("GET /hub/", view.ShowHub(db, store))
|
2024-03-12 20:27:39 +01:00
|
|
|
mux.HandleFunc("GET /logout/", view.Logout(store))
|
2024-03-28 07:41:11 +01:00
|
|
|
mux.HandleFunc("GET /publish-issue/", view.PublishLatestIssue(db, store))
|
2024-03-10 15:03:46 +01:00
|
|
|
mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(db, store))
|
2024-03-09 10:27:04 +01:00
|
|
|
mux.HandleFunc("GET /rss/", view.ShowRSS(
|
2024-03-09 10:12:46 +01:00
|
|
|
db,
|
|
|
|
"Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
|
|
|
"https://distrikt-ni-st.de",
|
|
|
|
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität",
|
|
|
|
))
|
2024-03-28 07:00:37 +01:00
|
|
|
mux.HandleFunc("GET /this-issue/", view.ShowCurrentArticles(db))
|
2024-03-09 10:27:04 +01:00
|
|
|
mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(db))
|
|
|
|
mux.HandleFunc("GET /write-article/", view.WriteArticle(db))
|
2024-03-01 11:30:31 +01:00
|
|
|
|
2024-03-09 10:27:04 +01:00
|
|
|
mux.HandleFunc("POST /add-tag/", view.AddTag(db, store))
|
|
|
|
mux.HandleFunc("POST /add-user/", view.AddUser(db, store))
|
|
|
|
mux.HandleFunc("POST /login/", view.Login(db, store))
|
|
|
|
mux.HandleFunc("POST /publish-article/", view.PublishArticle(db, store))
|
2024-03-10 15:03:46 +01:00
|
|
|
mux.HandleFunc("POST /reject-article/", view.RejectArticle(db, store))
|
|
|
|
mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(db, store))
|
|
|
|
mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(db, store))
|
|
|
|
mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(db, store))
|
|
|
|
mux.HandleFunc("POST /submit-article/", view.SubmitArticle(db, store))
|
2024-03-12 19:56:22 +01:00
|
|
|
mux.HandleFunc("POST /update-user/", view.UpdateUser(db, store))
|
2024-02-18 10:07:49 +01:00
|
|
|
|
|
|
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
2024-02-18 07:20:51 +01:00
|
|
|
}
|