<s> from flask import render_template , redirect , request , current_app , session , flash , url_for <EOL> from flask . ext . security import LoginForm , current_user , login_required , login_user <EOL> from flask . ext . social . utils import get_provider_or_404 <EOL> from flask . ext . social . views import connect_handler <EOL> from . import app , db <EOL> from . forms import RegisterForm <EOL> from . models import User <EOL> from . tools import requires_auth <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return render_template ( '<STR_LIT>' , total_users = User . query . count ( ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def login ( ) : <EOL> if current_user . is_authenticated ( ) : <EOL> return redirect ( request . referrer or '<STR_LIT:/>' ) <EOL> return render_template ( '<STR_LIT>' , form = LoginForm ( ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def register ( provider_id = None ) : <EOL> if current_user . is_authenticated ( ) : <EOL> return redirect ( request . referrer or '<STR_LIT:/>' ) <EOL> form = RegisterForm ( ) <EOL> if provider_id : <EOL> provider = get_provider_or_404 ( provider_id ) <EOL> connection_values = session . get ( '<STR_LIT>' , None ) <EOL> else : <EOL> provider = None <EOL> connection_values = None <EOL> if form . validate_on_submit ( ) : <EOL> ds = current_app . security . datastore <EOL> user = ds . create_user ( email = form . email . data , password = form . password . data ) <EOL> ds . commit ( ) <EOL> connection_values = session . pop ( '<STR_LIT>' , None ) <EOL> if connection_values : <EOL> connection_values [ '<STR_LIT>' ] = user . id <EOL> connect_handler ( connection_values , provider ) <EOL> if login_user ( user ) : <EOL> ds . commit ( ) <EOL> flash ( '<STR_LIT>' , '<STR_LIT:info>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , user = user ) <EOL> login_failed = int ( request . args . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> return render_template ( '<STR_LIT>' , <EOL> form = form , <EOL> provider = provider , <EOL> login_failed = login_failed , <EOL> connection_values = connection_values ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ login_required <EOL> def profile ( ) : <EOL> return render_template ( '<STR_LIT>' , <EOL> twitter_conn = current_app . social . twitter . get_connection ( ) , <EOL> facebook_conn = current_app . social . facebook . get_connection ( ) , <EOL> github_conn = current_app . social . github . get_connection ( ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ login_required <EOL> def social_post ( provider_id ) : <EOL> message = request . form . get ( '<STR_LIT:message>' , None ) <EOL> if message : <EOL> provider = get_provider_or_404 ( provider_id ) <EOL> api = provider . get_api ( ) <EOL> if provider_id == '<STR_LIT>' : <EOL> display_name = '<STR_LIT>' <EOL> api . PostUpdate ( message ) <EOL> if provider_id == '<STR_LIT>' : <EOL> display_name = '<STR_LIT>' <EOL> api . put_object ( "<STR_LIT>" , "<STR_LIT>" , message = message ) <EOL> flash ( '<STR_LIT>' % ( display_name , message ) , '<STR_LIT:info>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ requires_auth <EOL> def admin ( ) : <EOL> users = User . query . all ( ) <EOL> return render_template ( '<STR_LIT>' , users = users ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT>' ] ) <EOL> @ requires_auth <EOL> def delete_user ( user_id ) : <EOL> user = User . query . get_or_404 ( user_id ) <EOL> db . session . delete ( user ) <EOL> db . session . commit ( ) <EOL> flash ( '<STR_LIT>' , '<STR_LIT:info>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) </s>
