def add_entry():
  if not session.get('logged_in'):
	abort(401)
  entry = Entry(request.form['title'], request.form['text'])
  db_session.add(entry)
  db_session.commit()
  flash('New entry was succesfully posted')
  return redirect(url_for('show_entries'))
Example #2
0
def add_entry():
    if not session.get('logged_in'):
        abort(401)
    entry = Entry(request.form['title'], request.form['text'])
    db_session.add(entry)
    db_session.commit()
    flash('New entry was succesfully posted')
    return redirect(url_for('show_entries'))
def remove_entry(entryid):
  if not session.get('logged_in'):
	abort(401)
  
  entry = Entry.query.filter_by(id = entryid).first()

  db_session.delete(entry);
  db_session.commit();
  flash('Entry with Title:' + entry.title + ' was removed')
  return redirect(url_for('show_entries'))
Example #4
0
def remove_entry(entryid):
    if not session.get('logged_in'):
        abort(401)

    entry = Entry.query.filter_by(id=entryid).first()

    db_session.delete(entry);
    db_session.commit();
    flash('Entry with Title:' + entry.title + ' was removed')
    return redirect(url_for('show_entries'))
Example #5
0
File: views.py Project: ybv/twitlyt
def oauth_authorized(resp):
    """Called after authorization.  After this function finished handling,
    the OAuth information is removed from the session again.  When this
    happened, the tokengetter from above is used to retrieve the oauth
    token and secret.

    Because the remote application could have re-authorized the application
    it is necessary to update the values in the database.

    If the application redirected back after denying, the response passed
    to the function will be `None`.  Otherwise a dictionary with the values
    the application submitted.  Note that Twitter itself does not really
    redirect back unless the user clicks on the application name.
    """
    next_url = request.args.get('next') or url_for('index')
    if resp is None:
        flash(u'You denied the request to sign in.')
        return redirect(next_url)

    user = User.query.filter_by(name=resp['screen_name']).first()

    # user never signed on
    if user is None:
        user = User(resp['screen_name'])
        db_session.add(user)

    # in any case we update the authenciation token in the db
    # In case the user temporarily revoked access we will have
    # new tokens here.
    user.oauth_token = resp['oauth_token']
    user.oauth_secret = resp['oauth_token_secret']
    db_session.commit()

    session['user_id'] = user.user_id
    flash('You were signed in')
    return redirect(next_url)
Example #6
0
def oauth_authorized(resp):
    """Called after authorization.  After this function finished handling,
    the OAuth information is removed from the session again.  When this
    happened, the tokengetter from above is used to retrieve the oauth
    token and secret.

    Because the remote application could have re-authorized the application
    it is necessary to update the values in the database.

    If the application redirected back after denying, the response passed
    to the function will be `None`.  Otherwise a dictionary with the values
    the application submitted.  Note that Twitter itself does not really
    redirect back unless the user clicks on the application name.
    """
    next_url = request.args.get('next') or url_for('index')
    if resp is None:
        flash(u'You denied the request to sign in.')
        return redirect(next_url)

    user = User.query.filter_by(name=resp['screen_name']).first()

    # user never signed on
    if user is None:
        user = User(resp['screen_name'])
        db_session.add(user)

    # in any case we update the authenciation token in the db
    # In case the user temporarily revoked access we will have
    # new tokens here.
    user.oauth_token = resp['oauth_token']
    user.oauth_secret = resp['oauth_token_secret']
    db_session.commit()

    session['user_id'] = user.user_id
    flash('You were signed in')
    return redirect(next_url)