Exemplo n.º 1
0
    def post(self, post_id):

        post_exists(post_id)

        user_cookie = self.request.cookies.get('user')
        subject = self.request.get("subject")
        content = self.request.get("content")
        if user_cookie:
            if user_logged_in(user_cookie):
                if subject and content:
                    p = Post.get_by_id(int(post_id))
                    p.subject = subject
                    p.content = content
                    p = p.put()

                    self.redirect("/post/%d" % p.id())
                else:
                    error = "We need the subject and some content!"
                    self.render("edit-post.html", subject=subject,
                                content=content, user_cookie=user_cookie,
                                error=error)
            else:
                self.redirect('/')
        else:
            self.redirect("/signup")
Exemplo n.º 2
0
    def route(*args, **kwargs):
        if not user_logged_in():
            #If no user logged in, call the function
            return func(*args, **kwargs)

        #If user is logged in, redirect to home with error message
        flash("User logged in!", category="error")
        return redirect(url_for("home"))
Exemplo n.º 3
0
 def get(self):
     user_cookie = self.request.cookies.get('user')
     if user_cookie:
         if user_logged_in(user_cookie):
             self.render("new-post.html", user_cookie=user_cookie)
         else:
             self.redirect('/signup')
     else:
         self.redirect('/signup')
Exemplo n.º 4
0
    def route(*args, **kwargs):
        if user_logged_in():
            #If a user is logged in proceed with function
            return func(*args, **kwargs)

        #If user is not logged in, redirect to login page with error message
        flash("You need to be logged in to access that page!",
              category="error")
        return redirect(url_for("login"))
Exemplo n.º 5
0
    def post(self, comment_id):

        comment_exists(comment_id)

        user_cookie = self.request.cookies.get('user')
        if user_logged_in(user_cookie):
            post_id = self.request.get("post_id")
            self.delete_comment(comment_id)
            time.sleep(0.5)
            self.redirect("/post/%d" % int(post_id))
        else:
            self.redirect('/')
Exemplo n.º 6
0
    def get(self, post_id):

        post_exists(post_id)

        user_cookie = self.request.cookies.get('user')
        if user_cookie:
            if user_logged_in(user_cookie):
                self.render("add-comment.html",
                            post_id=post_id,
                            user_cookie=user_cookie)
            else:
                self.redirect('/signup')
        else:
            self.redirect('/signup')
Exemplo n.º 7
0
    def get(self, comment_id):

        comment_exists(comment_id)

        user_cookie = self.request.cookies.get('user')
        user_id_cookie = user_cookie.split('|')[0]
        if user_logged_in(user_cookie):
            if user_owns_comment(comment_id, user_id_cookie):
                self.render(
                    "delete-comment.html",
                    comments=[user_owns_comment(comment_id, user_id_cookie)],
                    user_cookie=user_cookie)
            else:
                self.redirect("/")
        else:
            self.redirect("/")
Exemplo n.º 8
0
    def get(self, post_id):

        post_exists(post_id)

        user_cookie = self.request.cookies.get('user')
        if user_cookie:
            user_id_cookie = user_cookie.split('|')[0]
            if user_logged_in(user_cookie):
                if user_owns_post(post_id, user_id_cookie):
                    self.render("edit-post.html", posts=[post_exists(post_id)],
                                user_cookie=user_cookie)
                else:
                    self.redirect('/')
            else:
                self.redirect('/')
        else:
            self.redirect('/signup')
Exemplo n.º 9
0
    def post(self, comment_id):

        comment_exists(comment_id)

        user_cookie = self.request.cookies.get('user')
        comment = self.request.get("comment")
        post_id = self.request.get("post_id")
        if user_logged_in(user_cookie):
            if comment:
                c = Comment.get_by_id(int(comment_id))
                c.comment = comment
                c.put()
                time.sleep(0.5)
                self.redirect("/post/%d" % int(post_id))
            else:
                error = "We need the comment"
                self.render("edit-comment.html",
                            comment=comment,
                            user_cookie=user_cookie,
                            error=error)
        else:
            self.redirect('/')
Exemplo n.º 10
0
    def post(self, post_id):

        post_exists(post_id)

        comment = self.request.get("comment")
        user_cookie = self.request.cookies.get('user')
        user_id_cookie = user_cookie.split('|')[0]
        if user_logged_in(user_cookie):
            if comment:
                c = Comment(comment=comment,
                            post_id=int(post_id),
                            user_id=int(user_id_cookie))
                c.put()
                time.sleep(0.5)
                self.redirect("/post/%d" % int(post_id))
            else:
                error = "We need a comment!"
                self.render("comment.html",
                            comment=comment,
                            error=error,
                            user_cookie=user_cookie)
        else:
            self.redirect('/')
Exemplo n.º 11
0
    def post(self):
        subject = self.request.get("subject")
        content = self.request.get("content")
        user_cookie = self.request.cookies.get('user')

        if user_cookie:
            user_id_cookie = user_cookie.split('|')[0]
            if user_logged_in(user_cookie):
                if subject and content:
                    p = Post(subject=subject, content=content,
                             user_id=int(user_id_cookie))
                    p = p.put()

                    self.redirect("/post/%d" % p.id())
                else:
                    error = "We need the subject and some content!"
                    self.render("new-post.html", subject=subject,
                                content=content, user_cookie=user_cookie,
                                error=error)
            else:
                self.redirect("/signup")
        else:
            self.redirect("/signup")