예제 #1
0
파일: main.py 프로젝트: tomasvdw/thas
def _process(func, request):
    try:
        return Response(func(request))
    except HttpError as e:
        return Response(e.message, e.httpcode)
    except Exception as e:
        raise
예제 #2
0
def staticpages(request, path):
    serve_file = partial(serve_static_file, request, default_charset='utf-8')
    path = wsgi_normpath(path)

    while path and path[0] == '/':
        path = path[1:]

    # Special case for root page
    if path == '':
        path = 'index.html'

    fs_path = os.path.join(*path.split('/'))
    abs_path = staticpath(fs_path)

    response = serve_file(abs_path)
    if response.status_code == 404 and os.path.isdir(abs_path):
        if path != "" and not path.endswith('/'):
            redirect = '/' + path + '/'
            if request.script_name != '':
                redirect = request.script_name + redirect
            return Response.redirect(redirect, status=302)

        return serve_file(os.path.join(abs_path, 'index.html'))

    return response
예제 #3
0
파일: at.py 프로젝트: q3k/at
def login(request):
    login = request.get('login')
    pwd = request.get('password')
    goto = request.get('goto') or '/'
    userid = get_credentials(login, pwd)
    if userid:
        request.session['userid'] = userid
        request.session['login'] = login
        return Response.redirect(goto)
    else:
        request.form['error'] = 'Username or password invalid'
        return login_form(request)
예제 #4
0
파일: at.py 프로젝트: q3k/at
def register(request):
    login = request['login']
    url = request['url']
    if 'wiki' in request.form:
        url = config.wiki_url % { 'login': login }
    try:
        conn.execute('insert into users (login, url, pass) values (?, ?, ?)',
            [login, url, sha256(request['password']).hexdigest()])
        return Response.redirect('/')
    except sqlite3.Error as e:
        request.form['error'] = 'Cannot add user - username taken?'
        return register_form(request)
예제 #5
0
파일: at.py 프로젝트: q3k/at
 def func(request, *a, **kw):
     if 'userid' not in request.session:
         return Response.redirect('/login?' + 
             urlencode({'goto': request.path_info,
                 'error': 'You must log in to continue'}))
     return f(request, *a, **kw)
예제 #6
0
파일: at.py 프로젝트: q3k/at
def logout(request):
    request.session.clear()
    return Response.redirect('/')
예제 #7
0
def CloNe(request, id):
    return Response(['This is a CloNeNode with ID: ' + str(id)])
예제 #8
0
def all(request):
    return Response(['This is for getting all ...'])
def new_message(request):
    twitter.tweet(request['name'], request['message'])
    return Response.redirect("/")
예제 #10
0
파일: main.py 프로젝트: tomasvdw/thas
def versioninfo(request):
    """
     Show version info
     """
    return Response('THAS server 1.0')