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 {
     }
 }
Beispiel #2
0
 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();
                 }
             }
         }
     }
 }