-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhttp_auth.py
More file actions
44 lines (36 loc) · 1.22 KB
/
Copy pathhttp_auth.py
File metadata and controls
44 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 4 23:25:44 2016
@author: thor
"""
from tornado.ioloop import IOLoop
from tornado import gen, web
class LoginHandler( web.RequestHandler ):
@gen.coroutine
def get( self ):
self.set_secure_cookie( 'username', 'Tom' )
self.write( 'login ok.' )
self.finish()
class LogoutHandler( web.RequestHandler ):
@gen.coroutine
def get( self ):
self.clear_cookie( 'username' )
self.write( 'logout ok.' )
self.finish()
class WhoHandler( web.RequestHandler ):
def get_current_user( self ):
return self.get_secure_cookie( 'username' ) or 'unknown'
@gen.coroutine
def get( self ):
self.write( 'you are ' + self.current_user )
self.finish()
application = web.Application( [
( r"/login", LoginHandler ),
( r"/logout", LogoutHandler ),
( r"/whoami", WhoHandler ),
],
autoreload = True,
cookie_secret="feljjfesrh48thfe2qrf3np2zl90bmw",
)
application.listen( 8765 )
IOLoop.current().start()