-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZfile.py
107 lines (92 loc) · 2.83 KB
/
Zfile.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# coding=utf-8
import os
import torndb
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import simplejson
from tornado import escape
#setting
from tornado.options import define, options
define("port", defaut=8888,help="run port",type=int)
define("mysql_host", default="127.0.0.1:3306", help="db host")
define("mysql_database", default="user", help="db name")
define("mysql_user", default="root", help="db user")
define("mysql_password", default="", help="db password")
TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), "templates")
STATIC_PATH = os.path.join(os.path.dirname(__file__), "static")
class BaseHandler(tornado.web.RequestHandler):
resp = None
db = self.application.db
template_path = TEMPLATE_PATH
static = STATIC_PATH
def get_curret_user(self):
return self.get_secure_cookie("user")
def check_user(self):
if not self.current_user:
self.redirect("/account/login")
return
def req_params(self):
return tornado.input()
def _print(self, page_name, base =None):
pass
def json(self):
self.db.close()
return simplejson.dumps(self.resp)
class MyRequestHandler(tornado.web.RequestHandler):
def check_xsrf_cookie(self):
pass
class HomeHandler(BaseHandler):
def get(self):
self.check_user()
self.render("templates/index.html")
#Account Action
class AccountHandler(BaseHandler):
def login(self):
self.check_user()
self.render("templates/disk")
self.render("templates/login")
def login_auth(self):
def log_out(self):
def register(self):
#File Action
class FileHandler(BaseHandler):
def __init__(self):
def index(self):
def upload(self):
def download(self):
def remove(self):
class Application(tornado.web.Application):
def __init__(self):
'''
handlers = [
(r"/", IndexHandler),
(r"/account/register", RegisterHandler)
(r"/account/login", Login)
]
'''
handlers =[
(r"/", HomeHandler),
(r"/account/login", AccountHandler.login),
]
settings = dict(
template_path = TEMPLATE_PATH,
static_path = STATIC_PATH,
debug = True
)
tornado.web.Application.__init__(self, handlers, **settings)
self.db = torndb.Connection(
host = options.mysql_host,
database = options.mysql_database,
user = options.mysql_user,
password = options.mysql_password
)
def main():
tornado.options.parse_command_line()
app = tornado.httpserver.HTTPServer(Application())
app.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()