def delete_news(request): auth_user(request.cookies.get('auth')) if not g.user: result = {'status': 'error', 'error': 'Not authenticated.' } return util.json_response(result) if request.POST.get('apisecret') != g.user["apisecret"]: result = {'status': 'error', 'error': 'Wrong form secret' } return util.json_response(result) news_id = util.force_int(request.POST.get('news_id')) if not news_id: result = {'status': 'error', 'error': 'bad news_id' } return util.json_response(result) if del_news(news_id, g.user['id']): result = {'status': 'ok', 'news_id': -1 } return util.json_response(result) result = {'status': 'err', 'error': 'News too old or wrong ID/owner.' } return util.json_response(result)
def vote_news(request): auth_user(request.cookies.get('auth')) if not g.user: result = {'status': 'error', 'error': 'Not authenticated.' } return util.json_response(result) if request.POST.get('apisecret') != g.user["apisecret"]: result = {'status': 'error', 'error': 'Wrong form secret' } return util.json_response(result) news_id = util.force_int(request.POST.get('news_id')) vote_type = request.POST.get('vote_type') if not news_id or (vote_type != 'up' and vote_type != 'down'): result = {'status': 'error', 'error': 'Missing news ID or invalid vote type.' } return util.json_response(result) # Vote the news karma, error = do_vote_news(news_id, vote_type) if karma: return util.json_response({"status": "ok" }) else: return util.json_response({"status": "error" })
def vote_news(request): auth_user(request.cookies.get('auth')) if not g.user: result = {'status': 'error', 'error': 'Not authenticated.'} return util.json_response(result) if request.POST.get('apisecret') != g.user["apisecret"]: result = {'status': 'error', 'error': 'Wrong form secret'} return util.json_response(result) news_id = util.force_int(request.POST.get('news_id')) vote_type = request.POST.get('vote_type') if not news_id or (vote_type != 'up' and vote_type != 'down'): result = { 'status': 'error', 'error': 'Missing news ID or invalid vote type.' } return util.json_response(result) # Vote the news karma, error = do_vote_news(news_id, vote_type) if karma: return util.json_response({"status": "ok"}) else: return util.json_response({"status": "error"})
def vote_news(request): auth_user(request.cookies.get("auth")) if not g.user: result = {"status": "error", "error": "Not authenticated."} return util.json_response(result) if request.POST.get("apisecret") != g.user["apisecret"]: result = {"status": "error", "error": "Wrong form secret"} return util.json_response(result) news_id = util.force_int(request.POST.get("news_id")) vote_type = request.POST.get("vote_type") if not news_id or (vote_type != "up" and vote_type != "down"): result = {"status": "error", "error": "Missing news ID or invalid vote type."} return util.json_response(result) # Vote the news karma, error = do_vote_news(news_id, vote_type) if karma: return util.json_response({"status": "ok"}) else: return util.json_response({"status": "error"})
def delete_news(request): auth_user(request.cookies.get("auth")) if not g.user: result = {"status": "error", "error": "Not authenticated."} return util.json_response(result) if request.POST.get("apisecret") != g.user["apisecret"]: result = {"status": "error", "error": "Wrong form secret"} return util.json_response(result) news_id = util.force_int(request.POST.get("news_id")) if not news_id: result = {"status": "error", "error": "bad news_id"} return util.json_response(result) if del_news(news_id, g.user["id"]): result = {"status": "ok", "news_id": -1} return util.json_response(result) result = {"status": "err", "error": "News too old or wrong ID/owner."} return util.json_response(result)
def delete_news(request): auth_user(request.cookies.get('auth')) if not g.user: result = {'status': 'error', 'error': 'Not authenticated.'} return util.json_response(result) if request.POST.get('apisecret') != g.user["apisecret"]: result = {'status': 'error', 'error': 'Wrong form secret'} return util.json_response(result) news_id = util.force_int(request.POST.get('news_id')) if not news_id: result = {'status': 'error', 'error': 'bad news_id'} return util.json_response(result) if del_news(news_id, g.user['id']): result = {'status': 'ok', 'news_id': -1} return util.json_response(result) result = {'status': 'err', 'error': 'News too old or wrong ID/owner.'} return util.json_response(result)
def submit(request): auth_user(request.cookies.get('auth')) if not g.user: result = {'status': 'error', 'error': 'Not authenticated.' } return util.json_response(result) if request.POST.get('apisecret') != g.user["apisecret"]: result = {'status': 'error', 'error': 'Wrong form secret' } return util.json_response(result) title = request.POST.get('title') url = request.POST.get('url') text = request.POST.get('text') news_id = util.force_int(request.POST.get('news_id')) if text: text = text.lstrip('\r\n').rstrip() if not title or (not url and not text): result = {'status': 'error', 'error': 'title and (url or text) required' } return util.json_response(result) # Make sure the URL is about an acceptable protocol, that is # http:// or https:// for now. if url and not url.startswith('http://') and not url.startswith('https://'): result = {'status': 'error', 'error': 'we only accept http:// and https:// news' } return util.json_response(result) if len(title) > config.MaxTitleLen or len(url) > config.MaxUrlLen: result = {'status': 'error', 'error': 'title or url too long' } return util.json_response(result) if not url and len(text) > config.CommentMaxLength: result = {'status': 'error', 'error': 'text too long' } return util.json_response(result) if news_id is None: result = {'status': 'error', 'error': 'bad news_id' } return util.json_response(result) if news_id == -1: if limit.submitted_recently(): result = {'status': 'error', 'error': "You have submitted a story too recently, " + "please wait %s seconds." % limit.allowed_to_post_in_seconds() } return util.json_response(result) news_id = insert_news(title, url, text, g.user['id']) else: news_id = edit_news(news_id, title, url, text, g.user['id']) if not news_id: result = {'status': 'error', 'error': 'Invalid parameters, news too old to be modified' + 'or url recently posted.' } return util.json_response(result) result = {'status': 'ok', 'news_id': int(news_id) } return util.json_response(result)
def submit(request): auth_user(request.cookies.get("auth")) if not g.user: result = {"status": "error", "error": "Not authenticated."} return util.json_response(result) if request.POST.get("apisecret") != g.user["apisecret"]: result = {"status": "error", "error": "Wrong form secret"} return util.json_response(result) title = request.POST.get("title") url = request.POST.get("url") text = request.POST.get("text") news_id = util.force_int(request.POST.get("news_id")) if text: text = text.lstrip("\r\n").rstrip() if not title or (not url and not text): result = {"status": "error", "error": "title and (url or text) required"} return util.json_response(result) # Make sure the URL is about an acceptable protocol, that is # http:// or https:// for now. if url and not url.startswith("http://") and not url.startswith("https://"): result = {"status": "error", "error": "we only accept http:// and https:// news"} return util.json_response(result) if len(title) > config.MaxTitleLen or len(url) > config.MaxUrlLen: result = {"status": "error", "error": "title or url too long"} return util.json_response(result) if not url and len(text) > config.CommentMaxLength: result = {"status": "error", "error": "text too long"} return util.json_response(result) if news_id is None: result = {"status": "error", "error": "bad news_id"} return util.json_response(result) if news_id == -1: if limit.submitted_recently(): result = { "status": "error", "error": "You have submitted a story too recently, " + "please wait %s seconds." % limit.allowed_to_post_in_seconds(), } return util.json_response(result) news_id = insert_news(title, url, text, g.user["id"]) else: news_id = edit_news(news_id, title, url, text, g.user["id"]) if not news_id: result = { "status": "error", "error": "Invalid parameters, news too old to be modified" + "or url recently posted.", } return util.json_response(result) result = {"status": "ok", "news_id": int(news_id)} return util.json_response(result)
def submit(request): auth_user(request.cookies.get('auth')) if not g.user: result = {'status': 'error', 'error': 'Not authenticated.'} return util.json_response(result) if request.POST.get('apisecret') != g.user["apisecret"]: result = {'status': 'error', 'error': 'Wrong form secret'} return util.json_response(result) title = request.POST.get('title') url = request.POST.get('url') text = request.POST.get('text') news_id = util.force_int(request.POST.get('news_id')) if text: text = text.lstrip('\r\n').rstrip() if not title or (not url and not text): result = { 'status': 'error', 'error': 'title and (url or text) required' } return util.json_response(result) # Make sure the URL is about an acceptable protocol, that is # http:// or https:// for now. if url and not url.startswith('http://') and not url.startswith( 'https://'): result = { 'status': 'error', 'error': 'we only accept http:// and https:// news' } return util.json_response(result) if len(title) > config.MaxTitleLen or len(url) > config.MaxUrlLen: result = {'status': 'error', 'error': 'title or url too long'} return util.json_response(result) if not url and len(text) > config.CommentMaxLength: result = {'status': 'error', 'error': 'text too long'} return util.json_response(result) if news_id is None: result = {'status': 'error', 'error': 'bad news_id'} return util.json_response(result) if news_id == -1: if limit.submitted_recently(): result = { 'status': 'error', 'error': "You have submitted a story too recently, " + "please wait %s seconds." % limit.allowed_to_post_in_seconds() } return util.json_response(result) news_id = insert_news(title, url, text, g.user['id']) else: news_id = edit_news(news_id, title, url, text, g.user['id']) if not news_id: result = { 'status': 'error', 'error': 'Invalid parameters, news too old to be modified' + 'or url recently posted.' } return util.json_response(result) result = {'status': 'ok', 'news_id': int(news_id)} return util.json_response(result)