Beispiel #1
0
class BaseHandler(tornado.web.RequestHandler):
    def initialize(self):
        tornado.web.RequestHandler.initialize(self)
        self.db = scoped_session(sessionmaker(bind=engine))
        self.userHandler = UserHandler(self)
        self.user = self.userHandler.auth()
        if self.user and not self.user["is_teacher"]:
            self.userHandler.updateOnlineRecord()

    def get_current_user(self):
        return self.user

    def get_UA_md5(self):
        return hashlib.md5(self.request.headers["User-Agent"]).hexdigest()

    def check_xsrf_cookie(self):
        token = (
            self.get_argument("_xsrf", None)
            or self.request.headers.get("X-Xsrftoken")
            or self.request.headers.get("X-Csrftoken")
        )
        if not token:
            self.send_error(403)
        if self.xsrf_token != token:
            self.send_error(403)

    def write_error(self, status_code, **kwargs):
        self.require_setting("static_path")
        if status_code in [404, 500, 503, 403]:
            self.write("Error occur - {0}".format(status_code))
Beispiel #2
0
 def initialize(self):
     tornado.web.RequestHandler.initialize(self)
     self.db = scoped_session(sessionmaker(bind=engine))
     self.userHandler = UserHandler(self)
     self.user = self.userHandler.auth()
     if self.user and not self.user["is_teacher"]:
         self.userHandler.updateOnlineRecord()