def _process(func, request): try: return Response(func(request)) except HttpError as e: return Response(e.message, e.httpcode) except Exception as e: raise
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
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)
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)
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)
def logout(request): request.session.clear() return Response.redirect('/')
def CloNe(request, id): return Response(['This is a CloNeNode with ID: ' + str(id)])
def all(request): return Response(['This is for getting all ...'])
def new_message(request): twitter.tweet(request['name'], request['message']) return Response.redirect("/")
def versioninfo(request): """ Show version info """ return Response('THAS server 1.0')