<commit_before>from flask import Blueprint, Response, render_template, request, session, redirect, jsonify,\
url_for, make_response, current_app
from flask.ext.security import current_user
import os
from twitter_model import Twitter_model, db
import urllib
from twython import Twython

app = Blueprint('twitter', __name__, template_folder='templates')

@app.route('/connect/twitter', methods=['GET', 'POST'])
def twitter_oauth_step_one():
	app_key = current_app.config['TWITTER_APP_KEY']
	app_secret = current_app.config['TWITTER_APP_SECRET']
	twitter_callback_url = current_app.config['TWITTER_APP_CALLBACK_URL'] 
	twitter = Twython(app_key, app_secret)
	auth = twitter.get_authentication_tokens(callback_url=twitter_callback_url)
	session['twitter_oauth_token'] = auth['oauth_token']
	session['twitter_oauth_token_secret'] = auth['oauth_token_secret']
	auth_url = auth['auth_url']
	return jsonify(redirect_url=auth_url,status=100)

@app.route('/connect/twitter/success/', methods=['GET', 'POST'])
def twitter_success():
	return redirect('/onboarding/pay')

@app.route('/connect/twitter/callback/',methods=['GET', 'POST'])
def twitter_oauth_callback():
	oauth_verifier = request.args.get('oauth_verifier')
	app_key = current_app.config['TWITTER_APP_KEY']
	app_secret = current_app.config['TWITTER_APP_SECRET']
	oauth_token = session['twitter_oauth_token']
	oauth_token_secret = session['twitter_oauth_token_secret'] 
	twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
	final_step = twitter.get_authorized_tokens(oauth_verifier)
	user_oauth_token = final_step['oauth_token']
	user_oauth_token_secret = final_step['oauth_token_secret']
	twitter_username = final_step['screen_name']
	twitter_row = Twitter_model({'username':current_user.email,
		'twitter_handle':twitter_username,
		'oauth_token':user_oauth_token,
		'oauth_token_secret':user_oauth_token_secret, 
		'company':current_user.company
	})
	db.session.add(twitter_row)
	db.session.commit()
	db.session.close()
	return render_template("oauth_success.html", service="Twitter")<commit_msg>redirect twitter back to virality so they can fb auth, instead of straight to pay<commit_after>from flask import Blueprint, Response, render_template, request, session, redirect, jsonify,\
url_for, make_response, current_app
from flask.ext.security import current_user
import os
from twitter_model import Twitter_model, db
import urllib
from twython import Twython

app = Blueprint('twitter', __name__, template_folder='templates')

@app.route('/connect/twitter', methods=['GET', 'POST'])
def twitter_oauth_step_one():
	app_key = current_app.config['TWITTER_APP_KEY']
	app_secret = current_app.config['TWITTER_APP_SECRET']
	twitter_callback_url = current_app.config['TWITTER_APP_CALLBACK_URL'] 
	twitter = Twython(app_key, app_secret)
	auth = twitter.get_authentication_tokens(callback_url=twitter_callback_url)
	session['twitter_oauth_token'] = auth['oauth_token']
	session['twitter_oauth_token_secret'] = auth['oauth_token_secret']
	auth_url = auth['auth_url']
	return jsonify(redirect_url=auth_url,status=100)

@app.route('/connect/twitter/success/', methods=['GET', 'POST'])
def twitter_success():
	return redirect('/onboarding/virality')

@app.route('/connect/twitter/callback/',methods=['GET', 'POST'])
def twitter_oauth_callback():
	oauth_verifier = request.args.get('oauth_verifier')
	app_key = current_app.config['TWITTER_APP_KEY']
	app_secret = current_app.config['TWITTER_APP_SECRET']
	oauth_token = session['twitter_oauth_token']
	oauth_token_secret = session['twitter_oauth_token_secret'] 
	twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
	final_step = twitter.get_authorized_tokens(oauth_verifier)
	user_oauth_token = final_step['oauth_token']
	user_oauth_token_secret = final_step['oauth_token_secret']
	twitter_username = final_step['screen_name']
	twitter_row = Twitter_model({'username':current_user.email,
		'twitter_handle':twitter_username,
		'oauth_token':user_oauth_token,
		'oauth_token_secret':user_oauth_token_secret, 
		'company':current_user.company
	})
	db.session.add(twitter_row)
	db.session.commit()
	db.session.close()
	return render_template("oauth_success.html", service="Twitter")
{'fraction_non_alphanumeric': 0.12003803185167577, 'fraction_numerical': 0.0014261944378416924, 'mean_word_length': 9.091127098321342, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5263062', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1415, 'n_words': 221}