Commit 233dc06b authored by Jogi Hofmüller's avatar Jogi Hofmüller

Let AddHandler add new geruecht

parent a447a4cf
......@@ -139,9 +139,29 @@ class AddHandler(RestHandler):
@tornado.web.asynchronous
def put(self):
sentence = tornado.escape.json_decode(self.request.body)
gdb.addNewGeruecht(sentence)
self.finish(json.dumps({'status': 'success', 'message': sentence}))
user = self.get_secure_cookie('user')
if not user:
user = 'anonymous'
data = tornado.escape.json_decode(self.request.body)
if data['type'] == 'name':
self.finish(json.dumps({'status': 'error', 'message': 'not implemented yet'}))
logmsg('AddHandler: adding new name not implemented yet')
return
if data['type'] == 'geruecht':
if len(data['payload']) < 20:
self.finish(json.dumps({'status': 'error', 'message': 'Fehler! Gerücht zu kurz.'}))
logmsg('AddHandler: refused to add new geruecht (too short)')
return
gdb.addNewGeruecht(data['payload'], user)
self.finish(json.dumps({'status': 'success', 'message': 'Gerücht hinzugefügt.'}))
logmsg('AddHandler: added new geruecht from remote_ip={}'.format(self.request.remote_ip))
return
# fallthrough
self.finish(json.dumps({'status': 'error', 'message': 'unknown type'}))
class LoginHandler(RestHandler):
def set_default_headers(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment