Exemplo n.º 1
0
def index():
    """Setup username and log into the Comments app."""
    error = None

    # Username already supplied, redirect to threads list
    if g.username:
        return to_threads()

    if request.method == 'POST':
        username = request.form.get('username') or ''
        if len(username) > 2:
            prefix = current_app.config['KEY_PREFIX']
            username_key = USERNAME_KEY.format(prefix)
            session[username_key] = username

            flash('Welcome, {0}!'.format(username), 'success')
            return to_threads()

        error = True

    status = 400 if error else 200
    return make_response(render_template('index.html', error=error), status)
Exemplo n.º 2
0
def quit():
    """Clear username from session and quit from Comments app."""
    username_key = USERNAME_KEY.format(current_app.config['KEY_PREFIX'])
    session.pop(username_key, None)
    return to_index()