diff --git a/imgbook/app/Http/Controllers/Auth/RegisterController.php b/imgbook/app/Http/Controllers/Auth/RegisterController.php index 24036bd..10112ce 100644 --- a/imgbook/app/Http/Controllers/Auth/RegisterController.php +++ b/imgbook/app/Http/Controllers/Auth/RegisterController.php @@ -28,7 +28,7 @@ class RegisterController extends Controller * * @var string */ - protected $redirectTo = '/home'; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/imgbook/app/Http/Controllers/CommentController.php b/imgbook/app/Http/Controllers/CommentController.php index 4d54634..b0a3ee3 100644 --- a/imgbook/app/Http/Controllers/CommentController.php +++ b/imgbook/app/Http/Controllers/CommentController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; use App\Profanity; use App\Comment; @@ -148,8 +149,19 @@ public function update(Request $request, $id, Profanity $p) * @param int $id * @return \Illuminate\Http\Response */ - public function destroy($id) + public function apiDestroy($id, $post_id) { - // + $comment = Comment::findOrFail($id); + $post = Post::findOrFail($post_id); + + if($comment->user_id == (Auth::user()->id) || Auth::user()->type == 'admin') { + $comment->delete(); + $message = array( + 'message' => 'Comment deleted' + ); + return response($message,200); + } + + return redirect()->route('posts.index')->with('message', 'Unauthorized to delete'); } } diff --git a/imgbook/app/Http/Controllers/HomeController.php b/imgbook/app/Http/Controllers/HomeController.php deleted file mode 100644 index 7cbc2c3..0000000 --- a/imgbook/app/Http/Controllers/HomeController.php +++ /dev/null @@ -1,28 +0,0 @@ -middleware('auth'); - } - - /** - * Show the application dashboard. - * - * @return \Illuminate\Contracts\Support\Renderable - */ - public function index() - { - return view('home'); - } -} diff --git a/imgbook/app/Http/Controllers/PostController.php b/imgbook/app/Http/Controllers/PostController.php index c947de0..c00df3a 100644 --- a/imgbook/app/Http/Controllers/PostController.php +++ b/imgbook/app/Http/Controllers/PostController.php @@ -82,7 +82,7 @@ public function store(Request $request, Profanity $p) $image = $validatedData['image']; $tags = []; - if (sizeOf($validatedData['checkbox']) != 0) { + if (isset($validatedData['checkbox'])) { $checkboxes = $validatedData['checkbox']; for ($i=0; $i < 10; $i++) { if(array_key_exists($i, $checkboxes)) { @@ -96,9 +96,11 @@ public function store(Request $request, Profanity $p) $a->title = $validatedData['title']; $a->description = $validatedData['description']; $a->user_id = Auth::user()->id; - $a->tags()->attach($tags); $a->save(); + $post = Post::findOrFail($a)->last(); + $post->tags()->attach($tags); + \App::call('App\Http\Controllers\ImageController@store', ['image' => $image, 'post_id' => $a->id]); session()->flash('message', 'Post created'); @@ -176,7 +178,6 @@ public function update(Request $request, $id, Profanity $p) if(array_key_exists($i, $checkboxes)) { array_push($tags, $i); } - } } @@ -201,7 +202,7 @@ public function destroy($userId, $id) { $post = Post::findOrFail($id); - if($post->user_id == $userId) { + if($post->user_id == $userId || Auth::user()->type == 'admin') { $post->delete(); return redirect()->route('posts.index')->with('message', 'Post Deleted'); } diff --git a/imgbook/public/js/app.js b/imgbook/public/js/app.js index 91b8cb7..14c1466 100644 --- a/imgbook/public/js/app.js +++ b/imgbook/public/js/app.js @@ -1869,12 +1869,19 @@ __webpack_require__.r(__webpack_exports__); // // // +// +// +// +// +// /* harmony default export */ __webpack_exports__["default"] = ({ - props: ['postId', 'userId'], + props: ['postId', 'userId', 'userType'], data: function data() { return { comments: [], error: '', + success: '', + admin: 'admin', newComment: '', commentMessage: 'Post a comment', changeOrPost: 'Post', @@ -1905,22 +1912,35 @@ __webpack_require__.r(__webpack_exports__); this.putComment(); } }, - postComment: function postComment() { + deleteComment: function deleteComment(comment) { var _this2 = this; + axios["delete"]("/comment/" + comment.id + "/" + this.postId).then(function (response) { + //success + _this2.fetchComments(); + + _this2.success = response.message; + })["catch"](function (error) { + //failure + _this2.error = error.response.data.error; + }); + }, + postComment: function postComment() { + var _this3 = this; + axios.post("/comments", { text: this.newComment, post_id: this.postId, user_id: this.userId }).then(function (response) { //success - _this2.comments.unshift(response.data); + _this3.comments.unshift(response.data); - _this2.newComment = ''; - _this2.error = ''; + _this3.newComment = ''; + _this3.error = ''; })["catch"](function (error) { //failure - _this2.error = error.response.data.error; + _this3.error = error.response.data.error; }); }, editCommentButton: function editCommentButton(comment) { @@ -1930,21 +1950,21 @@ __webpack_require__.r(__webpack_exports__); this.commentIdBeingEdited = comment; }, putComment: function putComment() { - var _this3 = this; + var _this4 = this; axios.put("/comments/" + this.commentIdBeingEdited.id, { text: this.newComment }).then(function (response) { //success - _this3.fetchComments(); + _this4.fetchComments(); - _this3.commentMessage = "Post a comment"; - _this3.changeOrPost = "Post"; - _this3.commentIdBeingEdited = null; - _this3.error = ''; + _this4.commentMessage = "Post a comment"; + _this4.changeOrPost = "Post"; + _this4.commentIdBeingEdited = null; + _this4.error = ''; })["catch"](function (error) { //failure - _this3.error = error.response.data.error; + _this4.error = error.response.data.error; }); } } @@ -37356,6 +37376,13 @@ var render = function() { ]) : _vm._e(), _vm._v(" "), + _vm.success + ? _c("div", { staticClass: "alert alert-success" }, [ + _c("strong", [_vm._v("Success")]), + _vm._v(" " + _vm._s(_vm.success) + "\n ") + ]) + : _vm._e(), + _vm._v(" "), _c("label", [_c("b", [_vm._v(_vm._s(_vm.commentMessage))])]), _vm._v(" "), _c("div", { staticClass: "input-group" }, [ @@ -37433,6 +37460,34 @@ var render = function() { }, [_vm._v("Edit")] ) + : _vm._e(), + _vm._v(" "), + comment.user.id == _vm.userId + ? _c( + "button", + { + staticClass: "btn btn-danger pull-right", + on: { + click: function($event) { + return _vm.editCommentButton(comment) + } + } + }, + [_vm._v("Delete")] + ) + : _vm.userType == _vm.admin + ? _c( + "button", + { + staticClass: "btn btn-danger pull-right", + on: { + click: function($event) { + return _vm.deleteComment(comment) + } + } + }, + [_vm._v("Delete")] + ) : _vm._e() ]) ]) diff --git a/imgbook/resources/js/components/CommentComponent.vue b/imgbook/resources/js/components/CommentComponent.vue index 14ff8bb..f55bb7c 100644 --- a/imgbook/resources/js/components/CommentComponent.vue +++ b/imgbook/resources/js/components/CommentComponent.vue @@ -4,6 +4,9 @@