Esempio n. 1
0
 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 {
     }
 }
Esempio n. 2
0
 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();
             }
         }
     }
 }