diff options
-rw-r--r-- | OutboxPost.go | 32 | ||||
-rw-r--r-- | main.go | 17 | ||||
-rw-r--r-- | outboxGet.go | 42 | ||||
-rw-r--r-- | verification.go | 2 |
4 files changed, 61 insertions, 32 deletions
diff --git a/OutboxPost.go b/OutboxPost.go index 550345d..9910761 100644 --- a/OutboxPost.go +++ b/OutboxPost.go @@ -101,10 +101,19 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { _, validActor = IsValidActor(activity.Object.Actor.Id) validLocalActor = (activity.Actor.Id == actor.Id) - verification := GetVerificationByCode(db, auth[1]) + + var verify Verify + verify.Identifier = "admin" + verify.Board = activity.Object.Actor.Id + + verify = GetVerificationCode(db, verify) + + code := verify.Code + code = CreateTripCode(code) + code = CreateTripCode(code) var rActivity Activity - if validActor && validLocalActor && verification.Board == activity.Actor.Id || verification.Board == Domain { + if validActor && validLocalActor && code == auth[1] || verify.Board == Domain { rActivity = AcceptFollow(activity) SetActorFollowingDB(db, rActivity) MakeActivityRequest(db, activity) @@ -132,9 +141,19 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { return } - verification := GetVerificationByCode(db, auth[1]) + var verify Verify + verify.Identifier = "admin" + verify.Board = Domain + + verify = GetVerificationCode(db, verify) + + fmt.Println(verify.Code) - if verification.Board != Domain { + code := verify.Code + code = CreateTripCode(code) + code = CreateTripCode(code) + + if code != auth[1] { w.WriteHeader(http.StatusBadRequest) w.Write([]byte("")) return @@ -588,6 +607,11 @@ func MakeActivityFollowingReq(w http.ResponseWriter, r *http.Request, activity A } func RemoteActorHasAuth(actor string, code string) bool { + + if actor == "" || code == "" { + return false + } + req, err := http.NewRequest("GET", actor + "/verification&code=" + code, nil) CheckError(err, "could not make remote actor auth req") @@ -563,7 +563,11 @@ func main() { CheckError(err, "error with add board follow req") - _, pass := GetPasswordFromSession(r) + _, pass := GetPasswordFromSession(r) + + pass = CreateTripCode(pass) + pass = CreateTripCode(pass) + req.Header.Set("Authorization", "Basic " + pass) req.Header.Set("Content-Type", activitystreams) @@ -694,6 +698,7 @@ func main() { var obj ObjectBase obj.Id = id + obj.Actor = &actor count, _ := GetObjectRepliesDBCount(db, obj) @@ -1735,11 +1740,16 @@ func GetUniqueFilename(_type string) string { func DeleteObjectRequest(db *sql.DB, id string) { var nObj ObjectBase + var nActor Actor nObj.Id = id + nObj.Actor = &nActor activity := CreateActivity("Delete", nObj) obj := GetObjectFromPath(db, id) + + activity.Actor.Id = obj.Actor.Id + followers := GetActorFollowDB(db, obj.Actor.Id) for _, e := range followers { activity.To = append(activity.To, e.Id) @@ -1748,19 +1758,22 @@ func DeleteObjectRequest(db *sql.DB, id string) { following := GetActorFollowingDB(db, obj.Actor.Id) for _, e := range following { activity.To = append(activity.To, e.Id) - } + } MakeActivityRequest(db, activity) } func DeleteObjectAndRepliesRequest(db *sql.DB, id string) { var nObj ObjectBase + var nActor Actor nObj.Id = id + nObj.Actor = &nActor activity := CreateActivity("Delete", nObj) obj := GetObjectFromPath(db, id) + nObj.Actor = obj.Actor followers := GetActorFollowDB(db, obj.Actor.Id) for _, e := range followers { activity.To = append(activity.To, e.Id) diff --git a/outboxGet.go b/outboxGet.go index 073a4bb..a42a3d7 100644 --- a/outboxGet.go +++ b/outboxGet.go @@ -93,7 +93,6 @@ func GetCollectionFromPath(db *sql.DB, path string) Collection { func GetObjectFromPath(db *sql.DB, path string) ObjectBase{ var nObj ObjectBase - var result []ObjectBase query := `select id, name, content, type, published, attributedto, attachment, preview, actor from activitystream where id=$1 order by published desc` @@ -102,37 +101,30 @@ func GetObjectFromPath(db *sql.DB, path string) ObjectBase{ CheckError(err, "error query collection path from db") defer rows.Close() + rows.Next() + var attachID string + var previewID string - for rows.Next(){ - var post ObjectBase - var attachID string - var previewID string - - var nActor Actor - post.Actor = &nActor - - err = rows.Scan(&post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.AttributedTo, &attachID, &previewID, &post.Actor.Id) - - CheckError(err, "error scan object into post struct from path") - - - var postCnt int - var imgCnt int - post.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, post) + var nActor Actor + nObj.Actor = &nActor + + err = rows.Scan(&nObj.Id, &nObj.Name, &nObj.Content, &nObj.Type, &nObj.Published, &nObj.AttributedTo, &attachID, &previewID, &nObj.Actor.Id) + + CheckError(err, "error scan object into post struct from path") - post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post) + var postCnt int + var imgCnt int - post.Replies.TotalItems = post.Replies.TotalItems + postCnt - post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt + nObj.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, nObj) - post.Attachment = GetObjectAttachment(db, attachID) + nObj.Replies.TotalItems, nObj.Replies.TotalImgs = GetObjectRepliesDBCount(db, nObj) - post.Preview = GetObjectPreview(db, previewID) + nObj.Replies.TotalItems = nObj.Replies.TotalItems + postCnt + nObj.Replies.TotalImgs = nObj.Replies.TotalImgs + imgCnt - result = append(result, post) - } + nObj.Attachment = GetObjectAttachment(db, attachID) - nObj = result[0] + nObj.Preview = GetObjectPreview(db, previewID) return nObj } diff --git a/verification.go b/verification.go index e0d94b8..97f80bf 100644 --- a/verification.go +++ b/verification.go @@ -190,7 +190,7 @@ func GetVerificationCode(db *sql.DB, verify Verify) Verify { CheckError(err, "error getting verify by code scan") } - return verify + return nVerify } func VerifyCooldownCurrent(db *sql.DB, auth string) VerifyCooldown { |