Exemplo n.º 1
0
 def get_next_url(self):
     if self.referer:
         match = URL_PATTERN.match(self.referer)
         if match and match.group('host') == self.request.host:  # todo: check scheme?
             next_url = match.group('path')
             if next_url and next_url != '/':
                 return next_url
Exemplo n.º 2
0
 def get_next_url(self):
     if self.referer:
         match = URL_PATTERN.match(self.referer)
         if match and match.group('host') == self.request.host:  # todo: check scheme?
             next_url = match.group('path')
             if next_url and next_url != '/':
                 return next_url
Exemplo n.º 3
0
 def get(self):
     self.set_cache(0, is_public=False)
     self.set_session_time_cookie()  # 强制修改 session_time,使用户可以重新访问 PageAppendHandler,以更新配置信息
     if self.referer:
         match = URL_PATTERN.match(self.referer)
         if match:
             request = self.request
             if match.group('host') == request.host and match.group('scheme') == request.protocol:
                 if self.current_user_id:
                     self.clear_cookie('user_id')
                 self.redirect(match.group('path'))
                 return
     self.redirect('/')
Exemplo n.º 4
0
 def get(self):
     self.set_cache(0, is_public=False)
     self.set_session_time_cookie(
     )  # 强制修改 session_time,使用户可以重新访问 PageAppendHandler,以更新配置信息
     if self.referer:
         match = URL_PATTERN.match(self.referer)
         if match:
             request = self.request
             if match.group('host') == request.host and match.group(
                     'scheme') == request.protocol:
                 if self.current_user_id:
                     self.clear_cookie('user_id')
                 self.redirect(match.group('path'))
                 return
     self.redirect('/')
Exemplo n.º 5
0
    def get(self):
        self.set_cache(is_public=False)

        if not self.referer:
            raise HTTPError(403)
        match = URL_PATTERN.match(self.referer)
        if not match:
            raise HTTPError(403)
        referer_host = match.group('host')
        if not referer_host:
            raise HTTPError(403)
        host = self.request.headers.get('Host')
        if host != referer_host:
            raise HTTPError(403)

        if self.get_cookie('session_time'):
            self.clear_cookie('session_time')  # session_time 的作用是让用户重新访问这个接口,既然已经在访问了,也就可以清除掉了

        output = {}
        if self.current_user:
            output['has_logged_in'] = 1
            output['user_name'] = self.current_user.name
            output['logout_url'] = CONFIG.BLOG_HOME_RELATIVE_PATH + 'logout'
            output['profile_url'] = CONFIG.BLOG_HOME_RELATIVE_PATH + 'profile'
            output['comment_url_prefix'] = CONFIG.BLOG_HOME_RELATIVE_PATH + 'comment/'
            extension = '.js' if CONFIG.DEBUG_MODE else '.min.js'
            output['article_js_urls'] = [
                '%s%s%s' % (CONFIG.BLOG_HOME_RELATIVE_PATH, js_path, extension)
                for js_path in (
                    'static/markitup/jquery.markitup',
                    'static/markitup/sets/bbcode/set',
                    'static/theme/null/js/msgbox'
                )
            ]
            if self.is_admin:
                output['is_admin'] = 1
                output['admin_url'] = CONFIG.BLOG_ADMIN_RELATIVE_PATH
                output['edit_url_prefix'] = CONFIG.BLOG_ADMIN_RELATIVE_PATH + 'article/'
        else:
            output['login_url'] = CONFIG.LOGIN_URL

        self.write_json(output)
Exemplo n.º 6
0
    def post(self):
        current_user = self.current_user
        name = self.get_argument('name')
        if name and len(name) <= 15 and current_user.name != name:
            current_user.name = name
            self.set_session_time_cookie()

        site = self.get_argument('site')
        if site:
            match = URL_PATTERN.match(site)
            if match:
                if not match.group('host'):
                    self.finish('抱歉,您填的网址不正确')
                    return
                if not match.group('scheme'):
                    site = 'http://' + site
                current_user.site = site
            else:
                self.finish('抱歉,您填的网址不正确')
                return
        else:
            current_user.site = None
        current_user.save()
        self.finish('您的资料保存成功了')
Exemplo n.º 7
0
    def post(self):
        current_user = self.current_user
        name = self.get_argument('name')
        if name and len(name) <= 15 and current_user.name != name:
            current_user.name = name
            self.set_session_time_cookie()

        site = self.get_argument('site')
        if site:
            match = URL_PATTERN.match(site)
            if match:
                if not match.group('host'):
                    self.finish('抱歉,您填的网址不正确')
                    return
                if not match.group('scheme'):
                    site = 'http://' + site
                current_user.site = site
            else:
                self.finish('抱歉,您填的网址不正确')
                return
        else:
            current_user.site = None
        current_user.save()
        self.finish('您的资料保存成功了')