Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tornado cookies authorization

class BaseHandler(tornado.web.RequestHandler):
    def get_current_user(self):
        return self.get_secure_cookie("user")

class MainHandler(BaseHandler):
    def get(self):
        if not self.current_user:
            self.redirect("/login")
            return
        name = tornado.escape.xhtml_escape(self.current_user)
        self.write("Hello, " + name)

class LoginHandler(BaseHandler):
    def get(self):
        self.write('<html><body><form action="/login" method="post">'
                   'Name: <input type="text" name="name">'
                   '<input type="submit" value="Sign in">'
                   '</form></body></html>')

    def post(self):
        self.set_secure_cookie("user", self.get_argument("name"))
        self.redirect("/")

application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/login", LoginHandler),
], cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__")
Comment

PREVIOUS NEXT
Code Example
Python :: rich content field django ckeditor not showing bullets 
Python :: keras imagenet 
Python :: Errors that you will get in the Time class in Python DateTime 
Python :: Delete file to trash 
Python :: region python 
Python :: latex new command with arguments 
Python :: django register form return a 302 request 
Python :: sample mapping in pandas 
Python :: what is cls and args in python classmethod 
Python :: Compute p-value 
Python :: ploting to data on the same axis 
Python :: Book.__init__() missing 5 required positional arguments 
Python :: python datediff days 
Python :: threshold image segmentation code python 
Python :: if you have a list and the user input one of the keys then output its value 
Python :: Implementing the hashing trick 
Python :: Customizing plot with axes object 
Python :: Understand the most appropriate graph to use for your dataset visualization 
Python :: add column to wandb.Table 
Python :: pytorch plot batch 
Python :: Count occurrence of each term in dataframe except for NaN 
Python :: python setup specify c++ version 
Python :: how to choose a random key from a dictionary in python 
Python :: tkinter radiobutton "bind_all" 
Python :: shutil cut poython 
Python :: ValueError: expected sparse matrix with integer values, found float values 
Python :: why am i not able to import wtf flask 
Python :: pop function second argument in python 
Python :: pyqt5 update display 
Python :: FilePathField 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =