Skip to content

Commit f4caa96

Browse files
qwqw
authored andcommitted
xsrf
1 parent d72de0c commit f4caa96

17 files changed

Lines changed: 77 additions & 9 deletions

File tree

‎3code/web/application.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
static_path = os.path.join(os.path.dirname(__file__), "statics"),
1212
cookie_secret = "bZJc2sWbQLKos6GkHn/VB9oXwQt8S0R0kRvJ5/xJ89E=",
1313
xsrf_cookies = True,
14+
login_url = '/',
1415
)
1516
application = tornado.web.Application(
1617
handlers = url,

‎3code/web/application.pyc‎

24 Bytes
Binary file not shown.

‎3code/web/handlers/__init__.pyc‎

-4 Bytes
Binary file not shown.

‎3code/web/handlers/base.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
import tornado.web
5+
6+
class BaseHandler(tornado.web.RequestHandler):
7+
def get_current_user(self):
8+
return self.get_secure_cookie("user")
9+
10+

‎3code/web/handlers/base.pyc‎

667 Bytes
Binary file not shown.

‎3code/web/handlers/index.py‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env python
22
# coding=utf-8
33

4-
import tornado.web
4+
#import tornado.web
5+
import tornado.escape
56
import methods.readdb as mrd
7+
from base import BaseHandler
68

7-
class IndexHandler(tornado.web.RequestHandler):
9+
class IndexHandler(BaseHandler):
810
def get(self):
911
usernames = mrd.select_columns(table="users",column="username")
1012
one_user = usernames[0][0]
@@ -17,9 +19,28 @@ def post(self):
1719
if user_infos:
1820
db_pwd = user_infos[0][2]
1921
if db_pwd == password:
20-
self.set_secure_cookie(username,db_pwd)
22+
#self.set_secure_cookie('user', username)
23+
self.set_current_user(username)
2124
self.write(username)
2225
else:
23-
self.write("your password was not right.")
26+
self.write("-1")
2427
else:
25-
self.write("There is no thi user.")
28+
self.write("-1")
29+
30+
def set_current_user(self, user):
31+
if user:
32+
self.set_secure_cookie('user', tornado.escape.json_encode(user))
33+
#self.set_secure_cookie('user', user)
34+
else:
35+
self.clear_cookie("user")
36+
37+
class ErrorHandler(BaseHandler):
38+
def get(self):
39+
self.render("error.html")
40+
41+
class RegisterHandler(BaseHandler):
42+
def get(self):
43+
self.render("register.html")
44+
45+
def post(self):
46+
pass

‎3code/web/handlers/index.pyc‎

1.17 KB
Binary file not shown.

‎3code/web/handlers/user.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
# coding=utf-8
33

44
import tornado.web
5+
import tornado.escape
56
import methods.readdb as mrd
7+
from base import BaseHandler
68

7-
class UserHandler(tornado.web.RequestHandler):
9+
class UserHandler(BaseHandler):
10+
@tornado.web.authenticated
811
def get(self):
9-
username = self.get_argument("user")
10-
print self.get_secure_cookie(username)
12+
#username = self.get_argument("user")
13+
username = tornado.escape.json_decode(self.current_user)
14+
print username
15+
print type(username)
1116
user_infos = mrd.select_table(table="users",column="*",condition="username",value=username)
17+
print user_infos
1218
self.render("user.html", users = user_infos)

‎3code/web/handlers/user.pyc‎

111 Bytes
Binary file not shown.

‎3code/web/methods/__init__.pyc‎

48 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)