def initialize(self, *a, **kw):
     """
     Auth middleware to set self.user if set in cookie
     """
     Handler.initialize(self, *a, **kw)
     uid = self.read_secure_cookie('user_id')
     if uid and User.get_by_id(int(uid)):
         self.user = uid
         self.blog_user = User.get_by_id(int(uid))
     else:
         self.user = None
         self.blog_user = None
 def initialize(self, *a, **kw):
     """
     Auth middleware to set self.user if set in cookie
     """
     Handler.initialize(self, *a, **kw)
     uid = self.read_secure_cookie('user_id')
     if uid and User.get_by_id(int(uid)):
         self.user = uid
         self.blog_user = User.get_by_id(int(uid))
     else:
         self.user = None
         self.blog_user = None
Exemple #3
0
 def done(self):
     """
     Saves an user instance if possible and redirects to login page
     """
     u = User.by_name(self.username)
     if u:
         msg = 'That user already exists.'
         self.render('signup-form.html', error_username=msg)
     else:
         u = User.register(self.username, self.password, self.email)
         u.put()
         self.login(u)
         self.redirect('/blog/')
 def done(self):
     """
     Saves an user instance if possible and redirects to login page
     """
     u = User.by_name(self.username)
     if u:
         msg = 'That user already exists.'
         self.render('register.html', error_username=msg)
     else:
         u = User.register(self.username, self.password, self.email)
         u.put()
         self.login(u)
         self.redirect('/')
Exemple #5
0
 def post(self):
     """
     To process ans store blog post information into database
     """
     title = self.request.get("title")
     content = self.request.get("content")
     if self.user:
         if title and content:
             user_obj = User.get_by_id(int(self.user))
             # adding publish date directly for now
             post = Post(title=title,
                         content=content,
                         user=user_obj,
                         published_at=datetime.now())
             new_post = post.put()
             self.redirect("/blog/{}".format(db.get(new_post).slug))
         else:
             error = "Both title and art required for submitting !"
             self.render("add_blog.html",
                         subject=title,
                         content=content,
                         error=error)
     else:
         cookie_error = "Your session has expired please login again to continue!"
         self.render('login.html', error=cookie_error)
 def get(self):
     posts = db.GqlQuery("SELECT * FROM Post WHERE is_draft=False ORDER BY created_at DESC LIMIT 10")
     if self.user:
         user = User.get_by_id(int(self.user))
         self.render('blog_list.html', posts=posts, username=user.username)
     else:
         self.render('blog_list.html', posts=posts)
Exemple #7
0
 def get(self):
     posts = db.GqlQuery("SELECT * FROM Post WHERE is_draft=False "
                         "ORDER BY created_at DESC LIMIT 10")
     if self.user:
         user = User.get_by_id(int(self.user))
         self.render('blog_list.html', posts=posts, username=user.username)
     else:
         self.render('blog_list.html', posts=posts)
Exemple #8
0
    def post(self):
        username = self.request.get('username')
        password = self.request.get('password')

        u = User.login(username, password)
        if u:
            self.login(u)
            self.redirect('/blog/')
        else:
            msg = 'Invalid login'
            self.render('login-form.html', error=msg)
    def post(self):
        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.html', error=msg)
 def post(self, post_id):
     """
     Create a new comment for the post with post_id as in params
     """
     if not self.user:
         error = "You must be logged in to comment"
         self.render('login.html', error=error)
     else:
         post = Post.get_by_id(int(post_id))
         user_obj = User.get_by_id(int(self.user))
         comment = self.request.get('comment')
         comment = Comment(comment=comment, user=user_obj, post=post)
         comment.put()
         self.redirect("/blog/{}".format(post.slug))
Exemple #11
0
 def get(self, post_id):
     """
     """
     user_obj = User.get_by_id(int(self.user))
     if not self.user:
         cookie_error = "Your session has expired please login again to continue!"
         self.render('login.html', error=cookie_error)
     else:
         post = Post.get_by_id(int(post_id))
         author = post.user.key().id()
         if author == int(self.user) or Like.all().filter('post =', post).filter('user ='******'/like/error')
         else:
             like = Like(post=post, user=user_obj)
             like.put()
             self.redirect("/blog/{}".format(post.slug))
Exemple #12
0
 def post(self):
     """
     To process ans store blog post information into database
     """
     title = self.request.get("title")
     content = self.request.get("content")
     if self.user:
         if title and content:
             user_obj = User.get_by_id(int(self.user))
             # adding publish date directly for now
             post = Post(title=title, content=content, user=user_obj, published_at=datetime.now())
             new_post = post.put()
             self.redirect("/blog/{}".format(db.get(new_post).slug))
         else:
             error = "Both title and art required for submitting !"
             self.render("add_blog.html", subject=title, content=content, error=error)
     else:
         cookie_error = "Your session has expired please login again to continue!"
         self.render('login.html', error=cookie_error)