def handle_login(env): tmpl = jinjaenv.get_template('loginform.html') if str(env['REQUEST_METHOD']) == 'POST': data = read_post_data(env) if 'user' not in data or 'pass' not in data: return template_render(tmpl, env, { 'session' : env['beaker.session'], 'loginfail' : True} ) user = urllib.unquote_plus(data['user'].value) pass_ = urllib.unquote_plus(data['pass'].value) # pass = hashlib.sha256(pass).hexdigest() u = lookup_user(user) if u is None: return template_render(tmpl, env, { 'session' : env['beaker.session'], 'loginfail' : True} ) if u.password == pass_: env['beaker.session']['user_name'] = user env['beaker.session'].save() return main_page(env) else: return template_render(tmpl, env, { 'session' : env['beaker.session'], 'loginfail' : True} ) return template_render(tmpl, env, { })
def style_serve(env, user): tmpl = jinjaenv.get_template('style.css') background = BACKGROUND_IMAGE if user and user.background_image != None: background = user.background_image headers = [('Content-Type', 'text/css')] return ['200 OK', headers, template_render(tmpl, env, {'background_image' : background})]
def pyroTorrentApp(env, start_response): """ pyroTorrent main function. """ # Log here if you want r = wt.apply_rule(env['PATH_INFO'], env) # 404 if r is None: start_response('404 Not Found', [('Content-Type', 'text/html')]) tmpl = jinjaenv.get_template('404.html') rtorrent_data = fetch_global_info() return template_render(tmpl, env, {'url' : env['PATH_INFO'], 'rtorrent_data' : rtorrent_data}) elif type(r) in (tuple, list) and len(r) == 3: # Respond with custom headers start_response(r[0], r[1]) r = r[2] # 200 else: start_response('200 OK', [('Content-Type', 'text/html;charset=utf8')]) # Response data # If r is not a file, but a string # prevent an exhausting loop if type(r) == str: return [r] return r
continue try: t = TorrentRequester(target, view) t.get_name().get_download_rate().get_upload_rate() \ .is_complete().get_size_bytes().get_download_total().get_hash() torrents[target['name']] = t.all() except InvalidTorrentException, e: return error_page(env, str(e)) tmpl = jinjaenv.get_template('download_list.html') return template_render(tmpl, env, {'torrents_list' : torrents, 'rtorrent_data' : rtorrent_data, 'view' : view} ) @webtool_callback @require_target @require_torrent def torrent_info_page(env, target, torrent): """ Page for torrent information. Files, messages, active, etc. """ try: q = torrent.query() q.get_hash().get_name().get_size_bytes().get_download_total().\ get_loaded_file().get_message().is_active() torrentinfo = q.all()[0] # .first() ?