def post_blog(request): if request.method == 'POST': if not request.POST.has_key('msg') or \ not request.POST.has_key('author'): return HttpResponseForbidden("Failed\r\n") msg = request.POST['msg'] authorname = request.POST['author'] key = request.POST['key'] author = Author.objects.filter(name=authorname) if len(author) == 0: return HttpResponseForbidden("Failed\r\n") author = author[0] msg = decode_post(msg, author.decrypt_key, key) if msg is None: return HttpResponseForbidden("Failed\r\n") if not is_full_post_spec(msg): return HttpResponseForbidden("Failed\r\n") msg['author'] = author post = get_post(msg, True) if len(post) <= 0: return HttpResponseForbidden("Failed\r\n") post = post[0] if len(post.uuid) != 0: post = modify_post(msg, post) post.save() return HttpResponse("Success\r\n") return HttpResponseForbidden("Not implemented\r\n")
def add_author(request): if request.method == 'POST': msg = request.POST['msg'] authorname = request.POST['author'] key = request.POST['key'] author = Author.objects.filter(name=authorname) if len(author) == 0: nr_authors = Author.objects.count() # This is our first author. He should be able to add users if nr_authors == 0: msg = json.loads(msg) msg['can_add_user'] = True msg['can_set_config'] = True else: return HttpResponseForbidden("Failed\r\n") else: author = author[0] if author.can_add_user: msg = decode_post(msg, author.decrypt_key, key) if not msg.has_key('can_set_config'): msg['can_set_config'] = False else: return HttpResponseForbidden("Failed\r\n") new_author = Author(name=msg['name'], decrypt_key=msg['decrypt_key'], \ email=msg['email'], about=msg['about'], \ can_add_user=msg['can_add_user'], \ can_set_config=msg['can_set_config']) new_author.save() return HttpResponse("Success\r\n") return HttpResponseForbidden("Not implemented\r\n")
def set_config(request): if request.method == 'POST': msg = request.POST['msg'] authorname = request.POST['author'] key = request.POST['key'] author = Author.objects.filter(name=authorname) if len(author) == 0: return HttpResponseForbidden("Failed\r\n") author = author[0] if not author.can_set_config: return HttpResponseForbidden("Failed\r\n") msg = decode_post(msg, author.decrypt_key, key) bc = BlogConfig.get() if msg.has_key('title'): bc.title = msg['title'] if msg.has_key('subtitle'): bc.subtitle = msg['subtitle'] if msg.has_key('nr_posts_per_page'): bc.nr_posts_per_page = int(msg['nr_posts_per_page']) if msg.has_key('captcha_name'): bc.captcha_name = msg['captcha_name'] if msg.has_key('captcha_secret'): bc.captcha_secret = msg['captcha_secret'] if msg.has_key('nr_poptags'): bc.nr_poptags = int(msg['nr_poptags']) if msg.has_key('about'): bc.about = msg['about'] if msg.has_key('domain_name'): bc.domain_name = msg['domain_name'] if msg.has_key('link'): bc.link = msg['link'] if msg.has_key('license'): bc.license = msg['license'] bc.save() return HttpResponse("Success\r\n") return HttpResponseForbidden("Not implemented\r\n")