Created
April 21, 2015 00:02
-
-
Save drrobotnik/90856469661b3871c20d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register all of the routes for an application. | |
| It's a breeze. Simply tell Laravel the URIs it should respond to | |
| and give it the controller to call when that URI is requested. | |
| | |
*/ | |
use App\User; | |
use App\UserMeta; | |
$app->get('/', function() use ( $app ) { | |
$blog_header = './wordpress/wp-blog-header.php'; | |
$mc_api_key = MC_API_KEY; | |
$request = Request::instance(); | |
$request->setTrustedProxies(array('127.0.0.1')); // only trust proxy headers coming from the IP addresses on the array (change this to suit your needs) | |
$ip = $request->getClientIp(); | |
$fields = Request::all(); | |
if ( !Request::has('euid') ) { | |
$user_meta = UserMeta::where(array( 'meta_key' => 'ip', 'meta_value' => $ip ) )->first(); | |
if( is_null( $user_meta ) ) | |
return "unsubscribed user"; # ---------- | |
return 'no euid requested, but IP whitelisted in db.'; # +++++++ | |
}else{ | |
$chimp = new Mailchimp( $mc_api_key ); | |
$info = $chimp->lists->memberInfo( MC_LIST_ID, array(array('euid'=>$fields['euid']) ) ); | |
if( $info['error_count'] > 0 ) | |
return 'the supplied euid is not on the beta list.'; # ------ | |
if($info['data'][0]['status'] != 'subscribed' ) | |
return 'this user has unsubscribed from our list'; # ------- | |
$user = User::firstOrCreate(['euid' => $fields['euid']]); | |
$user_meta = UserMeta::where(array( 'user_id' => $user->id, 'meta_key' => 'ip', 'meta_value' => $ip ) )->first(); | |
if( is_null( $user_meta ) ) { | |
$user_meta = new UserMeta; | |
$user_meta->user_id = $user->id; | |
$user_meta->meta_key = 'ip'; | |
$user_meta->meta_value = $ip; | |
$user_meta->save(); | |
return 'euid validated and IP address whitelisted.'; # ++++++++ | |
} | |
return 'All done!'; # +++++++ | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment