Beispiel #1
0
def set_name():
  if name_available(request.form['username']):
    q = "insert into active_users (name,last_active) VALUES (?,datetime('now'))"
    g.insert_db(q, (request.form['username'],))
    session['username'] = request.form['username']
    return jsonify({'success': True})
  else:
    return jsonify({'success': False})
Beispiel #2
0
def post_message():
  if 'username' not in session:
    return jsonify({'success': False})
  q = '''insert into messages (color, speaker, message, sent_at) VALUES
        (?, ?, ?, datetime('now'))'''
  try:
    color = min(int(request.form['color'][1:], 16), 0xffffff)
  except ValueError:
    color = 0
  finally:
    color = hex(color)[2:] # chop off 0x
    # add leading 0's
    color = color if len(color) == 6 else '0'*(6-len(color)) + color
    # add leading #
    color = '#' + color
  g.insert_db(q, (color, escape(session['username']),
    escape(request.form['message'])))
  return jsonify({'success': True})