#!/usr/bin/perl -w use Smart::Comments '####'; use FindBin qw($Bin); use lib "$Bin/../lib"; use lib "$Bin/../../lib"; use lib "$Bin/../../../www/lib"; use CGI::Fast qw(:standard); use Net::SSL; use SRlocal::Constants; use SRlocal::Templates; use SR::Auth::Users; use SR::Auth::Favorites; use SR::Auth::Sponsor; use SR::Defaults; use Data::Dumper; sub auth_login { # get param my $cgi = shift; # get options my $u = $cgi->param('username') || $cgi->param('user_ID'); # for backwards compatibility my $p = $cgi->param('password') || $cgi->param('user_password'); # for backwards compatibility my $js = $cgi->param('callback'); ## this sets the header SR::Auth::Users::login( $u, $p, $js, $cgi ); } sub auth_logout { my $cgi = shift; ## this sets the header SR::Auth::Users::logout($cgi); } sub js_login { my $cgi = shift; # get options my $js = $cgi->param('callback'); ## this sets the header SR::Auth::Users::js_login( $js, $cgi ); } sub bounce { my $cgi = shift; SR::Auth::Users::bounce($cgi); } sub fb_login { my $cgi = shift; SR::Auth::Users::fb_login($cgi); } sub register { my $cgi = shift; ## this sets the header SR::Auth::Users::register($cgi); } sub edit { my $cgi = shift; ## this sets the header SR::Auth::Users::edit($cgi); } sub save { my $cgi = shift; ## this sets the header SR::Auth::Users::save($cgi); } sub validate { my $cgi = shift; SR::Auth::Users::validate($cgi); } sub forgot { my $cgi = shift; SR::Auth::Users::forgot($cgi); } sub forgot_username { my $cgi = shift; SR::Auth::Users::forgot_username($cgi); } sub resend { my $cgi = shift; SR::Auth::Users::resend($cgi); } sub password_reset { my $cgi = shift; SR::Auth::Users::password_reset($cgi); } sub oauth_login { my $cgi = shift; SR::Auth::Users::oauth_login($cgi); } sub oauth_token { my $cgi = shift; SR::Auth::Users::oauth_token($cgi); } sub id_check { my $cgi = shift; SR::Auth::Users::id_check($cgi); } sub alert_me { my $cgi = shift; SR::Auth::Sponsor::alert_me($cgi); } sub pi_subscribe { my $cgi = shift; SR::Auth::Sponsor::pi_subscribe($cgi); } sub sponsor { my $cgi = shift; SR::Auth::Sponsor::add_sponsor($cgi); } sub save_sponsorship { my $cgi = shift; SR::Auth::Sponsor::save_sponsorship($cgi); } sub stripe_process { my $cgi = shift; SR::Auth::Sponsor::stripe_process($cgi); } sub edit_entry { my $cgi = shift; SR::Auth::Sponsor::edit_entry($cgi); } sub save_entry { my $cgi = shift; SR::Auth::Sponsor::save_entry($cgi); } sub change_entry { my $cgi = shift; SR::Auth::Sponsor::change_entry($cgi); } sub save_change { my $cgi = shift; SR::Auth::Sponsor::save_change($cgi); } sub add_funds { my $cgi = shift; SR::Auth::Sponsor::add_funds($cgi); } sub submit_payment { my $cgi = shift; SR::Auth::Sponsor::submit_payment($cgi); } sub list_transactions { my $cgi = shift; SR::Auth::Sponsor::all_transactions($cgi); } sub list_sponsorships { my $cgi = shift; SR::Auth::Users::list_sponsorships($cgi); } my %functions = ( 'login' => \&auth_login, 'logout' => \&auth_logout, 'register' => \®ister, 'edit' => \&edit, 'save' => \&save, 'validate' => \&validate, 'oauth_login' => \&oauth_login, 'oauth_token' => \&oauth_token, 'js_login' => \&js_login, 'fb_login' => \&fb_login, 'bounce' => \&bounce, 'forgot' => \&forgot, 'forgot_username' => \&forgot_username, 'resend' => \&resend, 'password_reset' => \&password_reset, 'id_check' => \&id_check, 'alert_me' => \&alert_me, 'sponsor' => \&sponsor, 'pi_subscribe' => \&pi_subscribe, 'save_sponsorship' => \&save_sponsorship, 'list_sponsorships' => \&list_sponsorships, 'edit_entry' => \&edit_entry, 'change_entry' => \&change_entry, 'save_entry' => \&save_entry, 'add_funds' => \&add_funds, 'stripe_process' => \&stripe_process, 'submit_payment' => \&submit_payment, 'list_transactions' => \&list_transactions, # favorites stuff 'add_favorite' => \&SR::Auth::Favorites::add_favorite, 'delete_favorite' => \&SR::Auth::Favorites::delete_favorite, 'get_favorites' => \&SR::Auth::Favorites::get_favorites, # ad-free browsing 'ad_free_browsing' => \&SR::Auth::Sponsor::ad_free_browsing, # user coupon redemption 'redeem_coupon' => \&SR::Auth::Sponsor::redeem_coupon, # session key stuff 'auth_session_key' => \&SR::Auth::Users::auth_session_key, 'auth_session_check' => \&SR::Auth::Users::auth_session_check # 'openid_login' => \&openid_login ); MAIN: { #my $cgi = CGI->new; #my $f = $cgi->param('do'); while ( my $cgi = new CGI::Fast ) { my $srtemplates = new SRlocal::Templates; my $f = $cgi->param('do'); #use Data::Dumper; #print STDERR Dumper($cgi); if ( !$f && $cgi->param('txn_id') ) { # this is from paypal $f = 'submit_payment'; } if ( $f && defined $functions{$f} ) { my $data = $functions{$f}->($cgi); if ( $data->{page} ) { # we want to print this as a full-on page my $login_form = SR::Auth::Users::login_form( $data->{referrer} ); my $site_params_ref = $sr_site_params_ref; my $output = ''; $output = $cgi->header( ( $data->{cookie} ) ? ( '-cookie' => $data->{cookie} ) : () ); my $you_are_here = generate_you_are_here( [ 'Your Account', $data->{page_title} ] ); my %model; $model{header} = { page_title => $data->{page_title}, page_description => $data->{page_title}, page_url => $SRlocal::Constants::SITE_URL . '/my/index.fcgi', you_are_here => $you_are_here, qi_section => "sponsors", }; $model{inner_nav} = [ { label => 'Account Home', link => $SR::Auth::Users::AUTH_SCRIPT, index => 1 }, { label => 'Play Index Subscriptions', nomobile_only => 1, link => $SR::Auth::Users::AUTH_SCRIPT . '?do=pi_subscribe', current => ( $f eq 'pi_subscribe' ) ? 1 : 0 }, { label => 'Browse Ad Free', nomobile_only => 1, link => $SR::Auth::Users::AUTH_SCRIPT . '?do=ad_free_browsing', current => ( $f eq 'ad_free_browsing' ) ? 1 : 0 } ]; if ( $data->{login_error} ) { # there's an error logging in, show an error and the form again push @{ $model{pagecontent} }, $data->{login_error}; push @{ $model{pagecontent} }, $login_form; } else { push @{ $model{pagecontent} }, $data->{content}; } $output .= $srtemplates->process( 'Pages/General.tt2', \%model ); if ( $data->{track} ) { # we want to be able to track specific analytics events for auth.cgi actions my $track_key = $data->{track}; $output .= < ga('send','event','auth', '$track_key'); JS } print $output; } else { # it's assumed that this is just JS we're outputting if ( $data->{redirect} ) { print $cgi->redirect( -uri => $data->{redirect}, ( ( $data->{cookie} ) ? ( '-cookie' => $data->{cookie} ) : () ) ); } else { print $cgi->header( ( ( $data->{cookie} ) ? ( '-cookie' => $data->{cookie} ) : () ), ( ( $data->{location} ) ? ( '-location' => $data->{location} ) : () ) ); } print $data->{content} if ( $data->{content} ); } } else { # just output our login form or the user info my $login_form = SR::Auth::Users::login_form(); my $site_params_ref = $sr_site_params_ref; my $output = $cgi->header; my $user = SR::Auth::Users::get_user($cgi); my $you_are_here = generate_you_are_here( ['Your Account'] ); my %model; $model{header} = { page_description => "Sports Reference User Auth ", page_url => $SRlocal::Constants::SITE_URL . '/my/index.fcgi', qi_section => "sponsors", you_are_here => $you_are_here }; $model{inner_nav} = [ { label => 'Account Home', link => $SR::Auth::Users::AUTH_SCRIPT, index => 1, current => ( defined $f ) ? 1 : 0 }, { label => 'Play Index Subscriptions', nomobile_only => 1, link => $SR::Auth::Users::AUTH_SCRIPT . '?do=pi_subscribe' }, { label => 'Browse Ad Free', nomobile_only => 1, link => $SR::Auth::Users::AUTH_SCRIPT . '?do=ad_free_browsing' } ]; if ( defined $user->{user_ID} ) { # this is a logged in user $model{header}{page_title} = "User Profile"; my $data = edit(); push @{ $model{pagecontent} }, $data->{content}; } else { $model{header}{page_title} = "Log In or Sign Up"; push @{ $model{pagecontent} }, $login_form; } $output .= $srtemplates->process( 'Pages/General.tt2', \%model ); print $output; } } } 1;