def store(self, id, request_data): request_data['article_id'] = id request_data['user_id'] = Auth.user().id Comment().create(request_data) return RedirectResponse(Utils.url(f"articles/{id}"))
def delete(self, id): article = Article().find(id) if article.user().id == Auth.user().id: article.delete() return RedirectResponse(request.base_uri + '/articles')
def destroy(self, id): comment = Comment().find(id) if comment.user().id == Auth.user().id: comment.delete() return RedirectResponse((comment.article().url()))
def update(self, id, request_data): article = Article().find(id) if Auth.user().id == article.user_id: article.update(request_data) return RedirectResponse(article.url())
def edit(self, id): article = Article().find(id) if article.user().id == Auth.user().id: return view('articles.edit', article=article) return ErrorResponse('Unauthorised', 500)
def deauthenticate(self, request_data): user = Auth.user() user.session_id = '' user.save() response = RedirectResponse(Utils.url('login')) response.header('Set-cockie', "session_id=''; SameSite=Strict;") return response
def store(self, request_data): request_data['user_id'] = Auth.user().id article = Article().create(request_data) return RedirectResponse(article.url())
def show(self, id): return view('articles.show', article=Article().find(id), user=Auth.user())