Esempio n. 1
0
    def post(self):
        if not BlogHandler.user_logged_in(self):
            # Grab user input
            have_error = False
            self.username = self.request.get('username')
            self.password = self.request.get('password')
            self.verify = self.request.get('verify')
            self.email = self.request.get('email')

            # Assign username and email to variables
            params = dict(username=self.username, email=self.email)

            # Validate user input
            if not valid_username(self.username):
                params['error_username'] = "******"
                have_error = True

            if not valid_password(self.password):
                params['error_password'] = "******"
                have_error = True
            elif self.password != self.verify:
                params['error_verify'] = "Your passwords didn't match."
                have_error = True

            if not valid_email(self.email):
                params['error_email'] = "That's not a valid email."
                have_error = True

            if have_error:
                self.render('signup-form.html', **params)
            else:
                self.done()
Esempio n. 2
0
    def post(self, post_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)
        if not BlogHandler.post_exists(self, post):
            self.redirect('/')
        else:
            if not BlogHandler.user_logged_in(self):
                self.redirect('/login')
            else:
                if not BlogHandler.user_owns_post(self, post):
                    self.redirect('/%s' % post_id)
                else:
                    author = self.user.name
                    subject = self.request.get('subject')
                    content = self.request.get('content')

                    if subject and content and author:
                        key = db.Key.from_path('Post',
                                               int(post_id),
                                               parent=blog_key())
                        post = db.get(key)
                        post.subject = subject
                        post.content = content
                        postID = int(post_id)
                        post.put()
                        self.redirect('/edited/%s' % postID)
                    else:
                        error = "subject and content, please!"
                        self.render("editpost.html",
                                    subject=subject,
                                    content=content,
                                    error=error,
                                    author=author)
Esempio n. 3
0
 def post(self, post_id):
     key = db.Key.from_path('Post', int(post_id),
                            parent=blog_key())
     post = db.get(key)
     if not BlogHandler.post_exists(self, post):
         self.redirect('/')
     else:
         postID = str(post.key().id())
         if BlogHandler.user_logged_in(self):
             if not BlogHandler.user_owns_post(self, post):
                 username = self.user.name
                 likeCount = Like.all().filter('post =',
                                               postID).filter('user ='******'/liked/%s' % postID)
                 else:
                     self.redirect('/%s' % postID)
             else:
                 postID = str(post.key().id())
                 contentType = "Sorry, you cannot like your own post."
                 self.render("deleted.html", contentType=contentType,
                             postID=postID)
         else:
             self.redirect('/login')
Esempio n. 4
0
    def post(self):
        if BlogHandler.user_logged_in(self):
            self.redirect('/')
        else:
            username = self.request.get('username')
            password = self.request.get('password')

            u = User.login(username, password)
            if u:
                self.login(u)
                self.redirect('/')
            else:
                msg = 'Invalid login'
                self.render('login-form.html', error=msg)
Esempio n. 5
0
 def post(self, post_id):
     key = db.Key.from_path('Comment', int(post_id), parent=blog_key())
     comment = db.get(key)
     if not BlogHandler.comment_exists(self, comment):
         self.redirect('/')
     else:
         postID = comment.post
         if BlogHandler.user_logged_in(self):
             if BlogHandler.user_owns_comment(self, comment):
                 db.delete(key)
                 self.redirect("/deletedcomment/%s" % postID)
             else:
                 self.redirect('/')
         else:
             self.redirect('/')
Esempio n. 6
0
 def post(self, post_id):
     key = db.Key.from_path('Comment', int(post_id), parent=blog_key())
     comment = db.get(key)
     if not BlogHandler.comment_exists(self, comment):
         self.redirect('/')
     else:
         returnPost = comment.post
         if not BlogHandler.user_logged_in(self):
             self.redirect('/login')
         else:
             if BlogHandler.user_owns_comment(self, comment):
                 comment.text = self.request.get('commentText')
                 comment.put()
                 self.redirect('/%s' % returnPost)
             else:
                 self.redirect('/%s' % returnPost)
Esempio n. 7
0
 def post(self, post_id):
     key = db.Key.from_path('Post', int(post_id), parent=blog_key())
     post = db.get(key)
     if not BlogHandler.post_exists(self, post):
         self.redirect('/')
     else:
         if not BlogHandler.user_logged_in(self):
             self.redirect('/login')
         else:
             author = self.user.name
             text = self.request.get('commentText')
             c = Comment(parent=blog_key(),
                         author=author,
                         post=post_id,
                         text=text)
             c.put()
             self.redirect('/%s' % post_id)
Esempio n. 8
0
 def post(self, post_id):
     key = db.Key.from_path('Comment', int(post_id), parent=blog_key())
     comment = db.get(key)
     if not BlogHandler.comment_exists(self, comment):
         self.redirect('/')
     else:
         if not BlogHandler.user_logged_in(self):
             self.redirect('/login')
         else:
             if BlogHandler.user_owns_comment(self, comment):
                 commentID = comment.key().id()
                 commentText = comment.text
                 postID = comment.post
                 self.render('editcomment.html', commentText=commentText,
                             commentID=commentID, postID=postID)
             else:
                 self.redirect('/')
Esempio n. 9
0
    def post(self):
        if not BlogHandler.user_logged_in(self):
            self.redirect('/')
        else:
            author = self.user.name
            subject = self.request.get('subject')
            content = self.request.get('content')

            if subject and content and author:
                p = Post(parent=blog_key(),
                         subject=subject,
                         content=content,
                         author=author)
                p.put()
                self.redirect('/%s' % str(p.key().id()))
            else:
                error = "subject and content, please!"
                self.render("newpost.html",
                            subject=subject,
                            content=content,
                            error=error,
                            author=author)
Esempio n. 10
0
 def get(self, post_id):
     key = db.Key.from_path('Post', int(post_id), parent=blog_key())
     post = db.get(key)
     if not BlogHandler.post_exists(self, post):
         self.redirect('/')
     else:
         if not BlogHandler.user_logged_in(self):
             self.redirect('/login')
         else:
             if not BlogHandler.user_owns_post(self, post):
                 self.redirect('/%s' % post_id)
             else:
                 subject = post.subject
                 content = post.content
                 author = post.author
                 error = ""
                 postID = post.key().id()
                 self.render("editpost.html",
                             subject=subject,
                             content=content,
                             error=error,
                             author=author,
                             postID=postID)
Esempio n. 11
0
 def get(self):
     if not BlogHandler.user_logged_in(self):
         self.render("signup-form.html")
     else:
         self.redirect("/")
Esempio n. 12
0
 def get(self):
     if BlogHandler.user_logged_in(self):
         self.render("newpost.html")
     else:
         self.redirect("/login")
Esempio n. 13
0
 def get(self):
     if not BlogHandler.user_logged_in(self):
         self.render('login-form.html')
     else:
         self.redirect('/')