Exemplo n.º 1
0
            return
        tid = int(self.get_argument("tid"))
        text = self.get_argument("text")      
        yield service.postToThing(tid,text,self.user)
        self.redirect("/t/{}.html".format(tid))
        
class NewTopic(BaseHandler,SessionAuthMixin):
    """ handler for posting new topics"""
    @defer.inlineCallbacks
    def post(self):
        yield self.verifySession()
        
        if not self.requireLogin():
            return
        
        tid = int(self.get_argument("tid"))
        title = self.get_argument("title")
        text = self.get_argument("text")
        
        yield service.newTopic(tid,title,text,self.user)
        
        self.redirect("/t/{}.html".format(tid))


            
import application
application.addHandler(r"/t/([1-9]+).html",ThingHandler)
application.addHandler(r"/api/get_thing.json",ThingJSONHandler)
application.addHandler(r"/new_post",PostToContainer)
application.addHandler(r"/new_topic",NewTopic)
Exemplo n.º 2
0
            if 'set_session_secret' in res:
                self.set_cookie("s", res['set_session_secret'])

            self.finish(json_out.serialize({"status": "success",
                                            "msg": "Logged in",
                                            "uid": res.uid}))
        else:
            self.finish(json_out.serialize({"status": "failure",
                                            "msg": "Incorrect credentials"}))
        
            

class LogoutJSONHandler(BaseHandler):
    """
    provides a logout method callable via JSON+XHR
    """
    def post(self):
        self.clear_cookie("s")
        self.set_header("Content-Type","application/json")
        #todo: invalidate the actual cookie
        self.finish(json_out.serialize({"success": True}))
        
import application

application.addHandler(r"/api/logout.json", LogoutJSONHandler)
application.addHandler(r"/api/login.json", LoginJSONHandler)
application.addHandler(r"/api/register.json", RegisterJSONHandler)
application.addHandler(r"/login.html", LoginHandler)
application.addHandler(r"/logout.html", LogoutHandler)
application.addHandler(r"/register.html", RegisterHandler)