def login(request): type = request.form.get('do') token = request.form.get('token') username = request.form.get('user') passwd = request.form.get('pw') if not (username and passwd and type and token) or not is_valid_token( type, token): return serve_text('') user = get_user(username) if type == 'reg' and user is None: user = register(username, passwd) if user and user.is_valid_pw(passwd): request.login(username) todo = request.form.get('reason') if not todo: response = serve_text('ok') else: response = exec_todo(request, user, todo) #remember user for n hours hours = 24 * (30 if request.form.get('rem') == 'on' else 1) request.session.save_cookie(response, expires=cookie_expires(hours), max_age=cookie_lifespan(hours)) return response return serve_text('')
def user_exists(request): name = request.args.get('name') if not name: raise Forbidden user = get_user(name) if user is not None: return serve_text('username taken.') else: return serve_text('')
def clearcache(request): cache.clear() #cache.delete('view_simple_search') #cache.delete('view_simple_about') #cache.delete('view_simple_links') #cache.delete('view_simple_robots') return serve_text('cache cleared: ' + datetime.now().isoformat(' '))
def autocomplete(request, name): query = request.args.get('q') if not query: raise NotFound if name == 'tags': res = session.query(Tag).filter(Tag.name.ilike(query+'%')).limit(10) suggestions = '\n'.join(r.name for r in res) elif name == 'reddits': res = session.query(Subreddit).filter(Subreddit.url.ilike(query+'%')).order_by(Subreddit.subscribers.desc()).limit(10) suggestions = '\n'.join(r.url for r in res) return serve_text(suggestions)
def login(request): type = request.form.get('do') token = request.form.get('token') username = request.form.get('user') passwd = request.form.get('pw') if not (username and passwd and type and token) or not is_valid_token(type, token): return serve_text('') user = get_user(username) if type == 'reg' and user is None: user = register(username, passwd) if user and user.is_valid_pw(passwd): request.login(username) todo = request.form.get('reason') if not todo: response = serve_text('ok') else: response = exec_todo(request, user, todo) #remember user for n hours hours = 24 * (30 if request.form.get('rem') == 'on' else 1) request.session.save_cookie(response, expires=cookie_expires(hours), max_age=cookie_lifespan(hours)) return response return serve_text('')
def autocomplete(request, name): query = request.args.get('q') if not query: raise NotFound if name == 'tags': res = session.query(Tag).filter(Tag.name.ilike(query + '%')).limit(10) suggestions = '\n'.join(r.name for r in res) elif name == 'reddits': res = session.query(Subreddit).filter( Subreddit.url.ilike(query + '%')).order_by( Subreddit.subscribers.desc()).limit(10) suggestions = '\n'.join(r.url for r in res) return serve_text(suggestions)
def code(request): return serve_text('bla')
def robots(request): txt = 'User-agent: * \nDisallow: /login \nDisallow: /api/ \nAllow: /' return serve_text(txt)
def restartmonitors(request): out = commands.getoutput('supervisorctl -c /home/www/vhost/metareddit/supervisord.conf restart all') return serve_text('monitors restarted: ' + out)
def cleandb(request): rm = Monitor() rm.cleandb() return serve_text('db cleaned: ' + datetime.now().isoformat(' '))