diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 83 |
1 files changed, 38 insertions, 45 deletions
@@ -447,7 +447,6 @@ func main() { http.HandleFunc("/" + *Key + "/", func(w http.ResponseWriter, r *http.Request) { id, _ := GetPasswordFromSession(r) - actor := GetActorFromPath(db, r.URL.Path, "/" + *Key + "/") if actor.Id == "" { @@ -475,26 +474,7 @@ func main() { if follow || adminFollow { r.ParseForm() - - var followActivity Activity - - followActivity.AtContext.Context = "https://www.w3.org/ns/activitystreams" - followActivity.Type = "Follow" - - - var obj ObjectBase - var nactor Actor - if r.FormValue("actor") == Domain { - nactor = GetActorFromDB(db, r.FormValue("actor")) - } else { - nactor = FingerActor(r.FormValue("actor")) - } - - followActivity.Actor = &nactor - followActivity.Object = &obj - - followActivity.Object.Actor = r.FormValue("follow") - followActivity.To = append(followActivity.To, r.FormValue("follow")) + followActivity := MakeFollowActivity(db, r.FormValue("actor"), r.FormValue("follow")) if followActivity.Actor.Id == Domain && !IsActorLocal(db, followActivity.Object.Actor) { w.Write([]byte("main board can only follow local boards. Create a new board and then follow outside boards from it.")) @@ -566,6 +546,7 @@ func main() { adminData.Board.Post.Actor = actor.Id + adminData.AutoSubscribe = GetActorAutoSubscribeDB(db, actor.Id); t.ExecuteTemplate(w, "layout", adminData) @@ -609,15 +590,10 @@ func main() { http.HandleFunc("/" + *Key + "/addboard", func(w http.ResponseWriter, r *http.Request) { - id, _ := GetPasswordFromSession(r) - actor := GetActorFromDB(db, Domain) - - if id == "" || (id != actor.Id && id != Domain) { - t := template.Must(template.ParseFiles("./static/verify.html")) - t.Execute(w, "") - return + if !HasValidation(w, r, actor) { + return } var newActorActivity Activity @@ -654,14 +630,9 @@ func main() { http.HandleFunc("/" + *Key + "/postnews", func(w http.ResponseWriter, r *http.Request) { - id, _ := GetPasswordFromSession(r) - actor := GetActorFromDB(db, Domain) - - if id == "" || (id != actor.Id && id != Domain) { - t := template.Must(template.ParseFiles("./static/verify.html")) - t.Execute(w, "") + if !HasValidation(w, r, actor) { return } @@ -677,14 +648,9 @@ func main() { http.HandleFunc("/" + *Key + "/newsdelete/", func(w http.ResponseWriter, r *http.Request){ - id, _ := GetPasswordFromSession(r) - actor := GetActorFromDB(db, Domain) - - if id == "" || (id != actor.Id && id != Domain) { - t := template.Must(template.ParseFiles("./static/verify.html")) - t.Execute(w, "") + if !HasValidation(w, r, actor) { return } @@ -1219,12 +1185,9 @@ func main() { http.HandleFunc("/blacklist", func(w http.ResponseWriter, r *http.Request) { - id, _ := GetPasswordFromSession(r) - actor := GetActorFromDB(db, Domain) - if id == "" || (id != actor.Id && id != Domain) { - http.Redirect(w, r, "/", http.StatusSeeOther) + if !HasValidation(w, r, actor) { return } @@ -1263,7 +1226,26 @@ func main() { if r.URL.Query().Get("hash") != "" { RouteImages(w, r.URL.Query().Get("hash")) } - }) + }) + + http.HandleFunc("/autosubscribe", func(w http.ResponseWriter, r *http.Request) { + + if !HasValidation(w, r, GetActorFromDB(db, Domain)) { + return + } + + board := r.URL.Query().Get("board") + actor := GetActorByNameFromDB(db, board) + + SetActorAutoSubscribeDB(db, actor.Id) + autoSub := GetActorAutoSubscribeDB(db, actor.Id) + + if autoSub { + AutoFollow(db, actor.Id) + } + + http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther) + }) fmt.Println("Server for " + Domain + " running on port " + Port) @@ -2680,3 +2662,14 @@ func IsPostBlacklist(db *sql.DB, comment string) bool { return false } + +func HasValidation(w http.ResponseWriter, r *http.Request, actor Actor) bool { + id, _ := GetPasswordFromSession(r) + + if id == "" || (id != actor.Id && id != Domain) { + http.Redirect(w, r, "/", http.StatusSeeOther) + return false + } + + return true +} |