Example #1
0
def static_file_handler(pre, file):
    pathinfo = ctx.request.path_info
    if not pathinfo.startswith('/'):
        raise HttpError('403')
    fpath = os.path.join(ctx.application.document_root, pathinfo[1:])
    logging.info('static file: %s' % fpath)
    if not os.path.isfile(fpath):
        raise HttpError(404)
    fext = os.path.splitext(fpath)[1]
    ctx.response.content_type = mimetypes.types_map.get(
        fext.lower(), 'application/octet-stream')
    ctx.response.content_length = os.path.getsize(fpath)
    return _static_file_generator(fpath)
Example #2
0
def blog(blog_id):
    blog = Blog.get(blog_id)
    if blog is None:
        raise HttpError.notfound()
    blog.html_content = markdown(blog.content)
    comments = Comment.find_by('where blog_id=? order by created_at desc limit 1000', blog_id)
    return dict(blog=blog,comments=comments,user=ctx.request.user)
Example #3
0
 def wrapper(*args,**kwargs):
     user = None
     cookie = ctx.request.cookies.get(_COOKIE_NAME)
     if cookie:
         user = parse_signed_cookie(cookie)
         if user and user.admin:
             logging.info('bind user <%s> to session...' % user.email)
         ctx.request.user = user
         return func(*args,**kwargs)
     else:
         raise HttpError.seeother('/signin')
Example #4
0
def manage_blogs_edit(blog_id):
    blog = Blog.get(blog_id)
    if blog is None:
        raise HttpError.notfound()
    return dict(id=blog.id, name=blog.name, summary=blog.summary, content=blog.content, action='/api/blogs/%s' % blog_id, redirect='/manage/blogs', user=ctx.request.user)
Example #5
0
def manage_index():
    raise HttpError.seeother('/manage/comments')
Example #6
0
def signout():
    ctx.response.delete_cookie(_COOKIE_NAME)
    raise HttpError.seeother('/')
Example #7
0
def manage_interceptor(next):
    user = ctx.request.user
    if user and user.admin:
        return next()
    raise HttpError.seeother('/signin')
Example #8
0
def manage_interceptor(next):
    user = ctx.request.user
    if user and user.admin:
        return next()
    raise HttpError.seeother("/signin")