public function index() { $fingerprint = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum'); $identity = $this->getIdentity(); if (!empty($identity->id)) { $identity = $identity->reload(); $fingerprints = (array) $identity->{'affiliates.fingerprints'}; // is this a new fingerprint? if (!in_array($fingerprint, $fingerprints)) { $fingerprints[] = $fingerprint; $identity->{'affiliates.fingerprints'} = $fingerprints; $identity->save(); // is the user an affiliate? if so, add their fingerprint to all of their referrals $update = \Affiliates\Models\Referrals::collection()->update(array('affiliate_id' => $identity->id), array('$addToSet' => array('affiliate_fingerprints' => $fingerprint)), array('multiple' => true)); \Dsc\Queue::task('\\Affiliates\\Models\\Referrals::checkFingerprints', array('id' => $identity->id), array('title' => 'Checking browser fingerprints in referrals from affiliate: ' . $identity->fullName())); // is the user a referral? if so, add the fingerprint to their referral record if ($referral = \Affiliates\Models\Referrals::isUser($identity->id)) { $fingerprints = (array) $referral->referral_fingerprints; if (!in_array($fingerprint, $fingerprints)) { $fingerprints[] = $fingerprint; $referral->referral_fingerprints = $fingerprints; try { $referral->verifyFingerprint()->save(); } catch (\Exception $e) { $referral->log($e->getMessage(), 'ERROR', 'Affiliates\\Site\\Controllers\\Fingerprint.saveReferral'); } } } } } else { } }
protected function postSite() { /** * Handle the affiliate tracking! */ \Affiliates\Models\Referrals::handle(); }
protected function afterCreate() { parent::afterCreate(); if (!empty($this->__send_email)) { $this->sendEmailNewInvite(); } \Affiliates\Models\Referrals::calcAffiliateTotals($this->affiliate_id); }
public function initialize() { $f3 = \Base::instance(); $this->setDefaults(array('namespace' => '\\Affiliates\\Site\\Controllers', 'url_prefix' => '/affiliate')); $f3->route('GET /affiliate/@affiliate_id', function ($f3) { \Dsc\System::instance()->get('input')->set('affiliate_id', $f3->get('PARAMS.affiliate_id')); \Affiliates\Models\Referrals::handle(); $identity = \Dsc\System::instance()->get('auth')->getIdentity(); if (empty($identity->id)) { \Dsc\System::addMessage('Please register with us so we can complete the referral. Thanks!'); $f3->reroute('/register'); } $f3->reroute('/'); }); $f3->route('GET /invite/@invite_id', function ($f3) { \Dsc\System::instance()->get('input')->set('invite_id', $f3->get('PARAMS.invite_id')); \Affiliates\Models\Referrals::handle(); $identity = \Dsc\System::instance()->get('auth')->getIdentity(); if (empty($identity->id)) { \Dsc\System::addMessage('Please register with us so we can complete the referral. Thanks!'); $f3->reroute('/register'); } $f3->reroute('/'); }); $f3->route('GET /affiliate/share/thanks', function ($f3) { echo "Thanks!"; }); $this->add('/dashboard', 'GET', array('controller' => 'Dashboard', 'action' => 'index')); $this->add('/invite-friends', 'GET', array('controller' => 'Invite', 'action' => 'index')); $this->add('/invite-friends/email', 'GET', array('controller' => 'Invite', 'action' => 'email')); $this->add('/invite-friends/email', 'POST', array('controller' => 'Invite', 'action' => 'emailSubmit')); $this->add('/invite-friends/link', 'GET', array('controller' => 'Invite', 'action' => 'link')); $this->add('/invite-history', 'GET|POST', array('controller' => 'Invites', 'action' => 'index')); $this->add('/invite-history/page/@page', 'GET', array('controller' => 'Invites', 'action' => 'index')); $this->add('/fp/@id [ajax]', 'GET|POST', array('controller' => 'Fingerprint', 'action' => 'index')); }
public function afterSaveUsersModelsUsers($event) { $identity = $event->getArgument('model'); // if the active status of the user record from the DB (grabbed in beforeSave above) // differs from the active status of the $user, and $user->active = true // grant the affiliate a referral credit if (!empty($this->db_user)) { if ($affiliate_id = $this->db_user->{'affiliates.validation_triggers_referral'}) { // Make the user into a referral for affiliate_id // \Dsc\System::addMessage('Making you into a referral for an Affiliate ID'); try { $referral = \Affiliates\Models\Referrals::isUser($identity->id); if (empty($referral->id)) { // is this a valid affiliate? $affiliate = (new \Users\Models\Users())->load(array('_id' => new \MongoId((string) $affiliate_id))); if (!empty($affiliate->id)) { // make them into a referral $referral = new \Affiliates\Models\Referrals(); $referral->bind(array('referral_user_id' => $identity->id, 'referral_name' => $identity->fullName(), 'referral_email' => $identity->email, 'referral_fingerprints' => (array) $identity->{'affiliates.fingerprints'}, 'affiliate_fingerprints' => (array) $affiliate->{'affiliates.fingerprints'}, 'affiliate_id' => $affiliate_id))->save(); /* \Affiliates\Models\Referrals::createCommission($referral->id); */ \Dsc\Queue::task('\\Affiliates\\Models\\Referrals::createCommission', array('id' => $referral->id), array('title' => 'Verify and create commission for referral: ' . $referral->referral_email)); } } // referral created, clear it from the user $identity->{'affiliates.validation_triggers_referral'} = null; $identity->{'affiliates.validation_triggers_referral_invite'} = null; $identity = $identity->store(); } catch (\Exception $e) { // Log the failure in the system logger $identity->log('Could not create referral for affiliate ' . $affiliate_id . ' (' . $affiliate->email . ') for referral of user ' . $identity->id . ' (' . $identity->email . ') because of error ' . $e->getMessage()); $identity->{'affiliates.validation_triggers_referral'} = null; $identity->{'affiliates.validation_triggers_referral_invite'} = null; $identity = $identity->store(); } } elseif ($invite_id = $this->db_user->{'affiliates.validation_triggers_referral_invite'}) { try { if ($invite = \Affiliates\Models\Invites::idValid($invite_id)) { $affiliate = (new \Users\Models\Users())->load(array('_id' => new \MongoId((string) $invite->affiliate_id))); if (!empty($affiliate->id)) { // make them into a referral $referral = new \Affiliates\Models\Referrals(); $referral->bind(array('referral_user_id' => $identity->id, 'referral_name' => $identity->fullName(), 'referral_email' => $invite->recipient_email, 'referral_fingerprints' => (array) $identity->{'affiliates.fingerprints'}, 'affiliate_fingerprints' => (array) $affiliate->{'affiliates.fingerprints'}, 'affiliate_id' => $invite->affiliate_id, 'affiliate_email' => $affiliate->email, 'invite_id' => $invite_id))->save(); /* \Affiliates\Models\Referrals::createCommission($referral->id); */ \Dsc\Queue::task('\\Affiliates\\Models\\Referrals::createCommission', array('id' => $referral->id), array('title' => 'Verify and create commission for referral: ' . $referral->referral_email)); } // referral created, clear it from the user $identity->{'affiliates.validation_triggers_referral'} = null; $identity->{'affiliates.validation_triggers_referral_invite'} = null; $identity = $identity->store(); } } catch (\Exception $e) { // Log the failure in the system logger $identity->log('Could not create referral for invite ' . $invite_id . ' for referral of user ' . $identity->id . ' (' . $identity->email . ') because of error ' . $e->getMessage()); $identity->{'affiliates.validation_triggers_referral'} = null; $identity->{'affiliates.validation_triggers_referral_invite'} = null; $identity = $identity->store(); } } } }
public static function checkFingerprints($affiliate_id) { // loop through all of an affilaite's referrals, and check whether or not their is browser fingerprint duplication // if so, flag it if ($referrals = \Affiliates\Models\Referrals::collection()->find(array('affiliate_id' => new \MongoId((string) $affiliate_id)))) { foreach ($referrals as $referral_doc) { if (empty($referral_doc['admin_status'])) { $referral = new static($referral_doc); $same_browser = array_intersect($referral->referral_fingerprints, $referral->affiliate_fingerprints); if (!empty($same_browser)) { if ($referral->commission()) { $referral->admin_status = 'suspicious_browser_commission_issued'; } else { $referral->admin_status = 'suspicious_browser'; } $referral->admin_status_messages[] = "One of this referral's browser fingerprints matches one of the affiliate's browser fingerprints."; $referral->save(); } } } } }