X Tutup
Skip to content

Commit 492d76a

Browse files
committed
tornado 5
1 parent 105b550 commit 492d76a

File tree

16 files changed

+340
-30
lines changed

16 files changed

+340
-30
lines changed

307.md

Lines changed: 283 additions & 0 deletions
Large diffs are not rendered by default.

3code/web/application.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
setting = dict(
1010
template_path = os.path.join(os.path.dirname(__file__), "templates"),
11-
static_path = os.path.join(os.path.dirname(__file__), "statics")
12-
)
13-
11+
static_path = os.path.join(os.path.dirname(__file__), "statics"),
12+
cookie_secret = "bZJc2sWbQLKos6GkHn/VB9oXwQt8S0R0kRvJ5/xJ89E=",
13+
xsrf_cookies = True,
14+
)
1415
application = tornado.web.Application(
1516
handlers = url,
1617
**setting
17-
)
18+
)

3code/web/application.pyc

162 Bytes
Binary file not shown.

3code/web/handlers/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def post(self):
1717
if user_infos:
1818
db_pwd = user_infos[0][2]
1919
if db_pwd == password:
20+
self.set_secure_cookie(username,db_pwd)
2021
self.write(username)
2122
else:
2223
self.write("your password was not right.")

3code/web/handlers/index.pyc

40 Bytes
Binary file not shown.

3code/web/handlers/user.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
class UserHandler(tornado.web.RequestHandler):
88
def get(self):
99
username = self.get_argument("user")
10+
print self.get_secure_cookie(username)
1011
user_infos = mrd.select_table(table="users",column="*",condition="username",value=username)
1112
self.render("user.html", users = user_infos)

3code/web/handlers/user.pyc

38 Bytes
Binary file not shown.

3code/web/statics/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
body {
3+
color:red;
4+
}

3code/web/statics/js/script.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
1+
function getCookie(name){
2+
var x = document.cookie.match("\\b" + name + "=([^;]*)\\b");
3+
return x ? x[1]:undefined;
4+
}
25
$(document).ready(function(){
36
$("#login").click(function(){
47
var user = $("#username").val();
58
var pwd = $("#password").val();
6-
var pd = {"username":user, "password":pwd};
9+
var pd = {"username":user, "password":pwd, "_xsrf":getCookie("_xsrf")};
710
$.ajax({
811
type:"post",
912
url:"/",
1013
data:pd,
1114
cache:false,
1215
success:function(data){
13-
//window.location.href = "/user?user="+data;
14-
alert(data);
16+
window.location.href = "/user?user="+data;
1517
},
1618
error:function(){
1719
alert("error!");
1820
},
1921
});
2022
});
21-
});
23+
});

3code/web/templates/base.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>Learning Python</title>
7+
<link rel="stylesheet" type="text/css" href="{{static_url("css/style.css")}}"
8+
</head>
9+
<body>
10+
<header>
11+
{% block header %}{% end %}
12+
</header>
13+
<content>
14+
{% block body %}{% end %}
15+
</content>
16+
<footer>
17+
{% set website = "<a href='http://www.itdiffer.com'>welcome to my website</a>" %}
18+
{% raw website %}
19+
</footer>
20+
<script src="{{static_url("js/jquery.min.js")}}"></script>
21+
<script src="{{static_url("js/script.js")}}"></script>
22+
</body>
23+
</html>

0 commit comments

Comments
 (0)
X Tutup