GeezerVison is showing github.com — tornado 5 · ebuty/StarterLearningPython@492d76a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: 307.md +283Lines changed: 283 additions & 0 deletions - Display the source diff
- Display the rich diff
Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: 3code/web/application.py +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 |
| 9 | 9 | setting = dict( | 10 | 10 | 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 | +) | 14 | 15 | application = tornado.web.Application( | 15 | 16 | handlers = url, | 16 | 17 | **setting | 17 | | - ) | | 18 | +) |
Collapse file Copy file name to clipboard Collapse file Copy file name to clipboardExpand all lines: 3code/web/handlers/index.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,7 @@ def post(self): | 17 | 17 | if user_infos: | 18 | 18 | db_pwd = user_infos[0][2] | 19 | 19 | if db_pwd == password: | | 20 | + self.set_secure_cookie(username,db_pwd) | 20 | 21 | self.write(username) | 21 | 22 | else: | 22 | 23 | self.write("your password was not right.") | |
Collapse file Copy file name to clipboard Collapse file Copy file name to clipboardExpand all lines: 3code/web/handlers/user.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | class UserHandler(tornado.web.RequestHandler): | 8 | 8 | def get(self): | 9 | 9 | username = self.get_argument("user") | | 10 | + print self.get_secure_cookie(username) | 10 | 11 | user_infos = mrd.select_table(table="users",column="*",condition="username",value=username) | 11 | 12 | self.render("user.html", users = user_infos) |
Collapse file Copy file name to clipboard Collapse file Copy file name to clipboard +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | + | | 2 | +body { | | 3 | + color:red; | | 4 | +} |
Collapse file Copy file name to clipboard +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | - | | 1 | +function getCookie(name){ | | 2 | + var x = document.cookie.match("\\b" + name + "=([^;]*)\\b"); | | 3 | + return x ? x[1]:undefined; | | 4 | +} | 2 | 5 | $(document).ready(function(){ | 3 | 6 | $("#login").click(function(){ | 4 | 7 | var user = $("#username").val(); | 5 | 8 | var pwd = $("#password").val(); | 6 | | - var pd = {"username":user, "password":pwd}; | | 9 | + var pd = {"username":user, "password":pwd, "_xsrf":getCookie("_xsrf")}; | 7 | 10 | $.ajax({ | 8 | 11 | type:"post", | 9 | 12 | url:"/", | 10 | 13 | data:pd, | 11 | 14 | cache:false, | 12 | 15 | success:function(data){ | 13 | | - //window.location.href = "/user?user="+data; | 14 | | - alert(data); | | 16 | + window.location.href = "/user?user="+data; | 15 | 17 | }, | 16 | 18 | error:function(){ | 17 | 19 | alert("error!"); | 18 | 20 | }, | 19 | 21 | }); | 20 | 22 | }); | 21 | | -}); | | 23 | +}); |
Collapse file Copy file name to clipboard +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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> |
|