function onAuthCheckUser(Am_Event $event)
 {
     /* @var $user User */
     $user = $event->getUser();
     $recs = $this->getDi()->loginSessionTable->findBy(array('user_id' => $user->pk(), 'session_id' => '<>' . Zend_Session::getId(), 'modified' => '>' . sqlTime(sprintf('-%d minutes', $this->getConfig('timeout', 5))), 'need_logout' => 0));
     if ($recs) {
         switch ($this->getConfig('action', self::ACTION_LOGIN_REJECT)) {
             case self::ACTION_LOGIN_REJECT:
                 $event->setReturn(new Am_Auth_Result(-100, $this->getConfig('error', 'There is already exits active login session for your account.
                         Simultaneous login from different computers is not allowed.')));
                 $event->stop();
                 break;
             case self::ACTION_LOGOUT_OTHER:
                 foreach ($recs as $rec) {
                     $rec->updateQuick('need_logout', 1);
                 }
                 break;
             case self::ACTION_NOTHING:
                 break;
         }
         if ($this->getConfig('notify_admin') && !$this->getDi()->store->get('single-login-session-detected-' . $user->pk())) {
             $this->getDi()->store->set('single-login-session-detected-' . $user->pk(), 1, '+20 minutes');
             if ($et = Am_Mail_Template::load('misc.single-login-session.notify_admin')) {
                 $et->setUser($user);
                 $et->sendAdmin();
             }
         }
     }
 }
Example #2
0
 function onSignupUserAdded(Am_Event $event)
 {
     $user = $event->getUser();
     // validate if user is logged-in to Facebook
     $api = $this->getApi();
     if ($api->getSignedRequest() && ($fbuid = $api->getUser())) {
         $user->data()->set(self::FACEBOOK_UID, $fbuid)->update();
     }
 }
Example #3
0
 function onGetMemberLinks(Am_Event $event)
 {
     $user = $event->getUser();
     if ($user->status == User::STATUS_PENDING) {
         return;
     }
     // @todo fixme make it without loading of all of plugins
     foreach ($this->getPlugins() as $pl) {
         if ($pl->storesCcInfo() && $this->getDi()->ccRecordTable->findFirstByUserId($user->user_id)) {
             $event->addReturn(___("Update Credit Card Info"), ROOT_SURL . "/payment/" . $pl->getId() . "/update");
         }
     }
 }
Example #4
0
 function onBuildDemo(Am_Event $event)
 {
     $subjects = array('Please help', 'Urgent question', 'I have a problem', 'Important question', 'Pre-sale inquiry');
     $questions = array("My website is now working. Can you help?", "I have a problem with website script.\nWhere can I find documentation?", "I am unable to place an order, my credit card is not accepted.");
     $answers = array("Please call us to phone# 1-800-222-3334", "We are looking to your problem, and it will be resolved within 4 hours");
     $user = $event->getUser();
     /* @var $user User */
     while (rand(0, 10) < 4) {
         $ticket = $this->getDi()->helpdeskTicketRecord;
         $ticket->status = HelpdeskTicket::STATUS_AWAITING_ADMIN_RESPONSE;
         $ticket->subject = $subjects[rand(0, count($subjects) - 1)];
         $ticket->user_id = $user->pk();
         $ticket->created = sqlTime('now');
         $ticket->insert();
         //
         $msg = $this->getDi()->helpdeskMessageRecord;
         $msg->content = $questions[rand(0, count($questions) - 1)];
         $msg->type = 'message';
         $msg->ticket_id = $ticket->pk();
         $msg->dattm = $tm = sqlTime(time() - rand(3600, 3600 * 24 * 180));
         $msg->insert();
         //
         if (rand(0, 10) < 6) {
             $msg = $this->getDi()->helpdeskMessageRecord;
             $msg->content = $answers[rand(0, count($answers) - 1)];
             $msg->type = 'message';
             $msg->ticket_id = $ticket->pk();
             $msg->dattm = sqlTime(strtotime($tm) + rand(180, 3600 * 24));
             $msg->admin_id = $this->getDi()->adminTable->findFirstBy()->pk();
             $msg->insert();
             if (rand(0, 10) < 6) {
                 $ticket->status = HelpdeskTicket::STATUS_AWAITING_USER_RESPONSE;
             } else {
                 $ticket->status = HelpdeskTicket::STATUS_CLOSED;
             }
             $ticket->update();
         }
     }
 }
Example #5
0
 public function deleted(Am_Event $event)
 {
     $st = $event->getUser()->status;
     // change it to trick update function
     $event->getUser()->status = User::STATUS_EXPIRED;
     $this->updated($event);
     // change it back
     $event->getUser()->status = $st;
 }
Example #6
0
 public function triggerEvent(Am_Event $e)
 {
     $oldUser = $e->getOldUser();
     $user = $e->getUser();
     if ($oldUser->unsubscribed != $user->unsubscribed) {
         Am_Di::getInstance()->hook->call(Am_Event::USER_UNSUBSCRIBED_CHANGED, array('user' => $user, 'unsubscribed' => $user->unsubscribed));
     }
 }
Example #7
0
 public function handlePayment(Am_Event $e)
 {
     if ($this->getConfig('unsubscribe_after_signup') != self::UNSUBSCRIBE_AFTER_PAID) {
         return;
     }
     $user = $e->getUser();
     if ($user->data()->get('unsubscribe_after_signup')) {
         return;
     }
     $user->data()->set('unsubscribe_after_signup', self::UNSUBSCRIBE_AFTER_PAID)->update();
     if (!($lists = $this->getConfig('unsubscribe_after_signup_lists'))) {
         return;
     }
     try {
         $this->changeSubscription($e->getUser(), array(), $lists);
     } catch (Exception $e) {
         //just log
         $this->getDi()->errorLogTable->logException($e);
     }
 }
Example #8
0
 function onUserUnsubscribedChanged(Am_Event $event)
 {
     $this->getDi()->newsletterUserSubscriptionTable->checkSubscriptions($event->getUser());
 }
Example #9
0
 function onBuildDemo(Am_Event $event)
 {
     $referrers = array('http://example.com/some/url.html', 'http://example.com/some/other/url.html', 'http://example.com/page/offer.html', 'http://example.com/very/very/long/referrer/url.html', 'http://example.com/referrer.html');
     static $banners = null;
     if (is_null($banners)) {
         $banners = $this->getDi()->affBannerTable->findBy();
         array_push($banners, null);
     }
     $user = $event->getUser();
     $user->is_affiliate = 1;
     $user->aff_payout_type = 'check';
     if (rand(0, 10) < 4) {
         $aff_id = $this->getDi()->db->selectCell("SELECT `id`\n                FROM ?_data\n                WHERE `table`='user' AND `key`='demo-id' AND `value`=?\n                LIMIT ?d, 1", $event->getDemoId(), rand(0, $event->getUsersCreated()));
         if ($aff_id) {
             $aff = $this->getDi()->userTable->load($aff_id);
             $banner = $banners[array_rand($banners)];
             $banner_id = $banner ? $banner->pk() : null;
             $user->aff_id = $aff_id;
             $user->aff_added = $user->added;
             $user->data()->set('aff-source', 'cookie');
             $server = $_SERVER;
             $_SERVER['REMOTE_ADDR'] = $user->remote_addr;
             $_SERVER['HTTP_REFERER'] = $referrers[array_rand($referrers)];
             $this->getDi()->setService('time', amstrtotime($user->added) - rand(5 * 60, 3600));
             $aff_click_id = $this->getDi()->affClickTable->log($aff, $banner);
             $this->getDi()->setService('time', amstrtotime($user->added));
             $this->getDi()->affLeadTable->log($aff_id, $banner_id, $user->pk(), $aff_click_id);
             $_SERVER = $server;
             $this->getDi()->setService('time', time());
         }
     }
 }
Example #10
0
 function onSignupUserAdded(Am_Event $event)
 {
     $user = $event->getUser();
     // validate if user is logged-in to Facebook
     if ($fbuid = $this->getFbUid()) {
         $user->data()->set(self::FACEBOOK_UID, $fbuid)->update();
     }
 }
Example #11
0
 function onGetMemberLinks(Am_Event $event)
 {
     $user = $event->getUser();
     if ($user->status == User::STATUS_PENDING) {
         return;
     }
     foreach ($this->getPlugins() as $pl) {
         if ($pl instanceof Am_Paysystem_CreditCard && ($link = $pl->getUpdateCcLink($user))) {
             $event->addReturn(___("Update Credit Card Info"), $link);
         } elseif ($pl instanceof Am_Paysystem_Echeck && ($link = $pl->getUpdateEcheckLink($user))) {
             $event->addReturn(___("Update Echeck Info"), $link);
         }
     }
 }
Example #12
0
 function onUserAfterDelete(Am_Event $event)
 {
     $id = $event->getUser()->pk();
     $this->getDi()->subusersSubscriptionTable->deleteBy(array('user_id' => $id));
 }
Example #13
0
 function onBuildDemo(Am_Event $event)
 {
     $user = $event->getUser();
     $user->is_affiliate = 1;
     $user->aff_payout_type = 'check';
     if (rand(0, 10) < 4) {
         $user->aff_id = $this->getDi()->db->selectCell("SELECT `id` \n                FROM ?_data \n                WHERE `table`='user' AND `key`='demo-id' AND `value`=?\n                LIMIT ?d, 1", $event->getDemoId(), rand(0, $event->getUsersCreated()));
     }
 }
Example #14
0
 public function onUserBeforeDelete(Am_Event $event)
 {
     $user = $event->getUser();
     $products = $user->getActiveProductIds();
     if (!empty($products)) {
         return;
     }
     $list_ids = $this->getDi()->newsletterUserSubscriptionTable->getSubscribedIds($user->pk());
     $lists = array();
     foreach ($this->getDi()->newsletterListTable->loadIds($list_ids) as $list) {
         if ($list->plugin_id != $this->getId()) {
             continue;
         }
         $lists[] = $list->plugin_list_id;
     }
     if (empty($lists)) {
         return;
     }
     require_once 'lib/csrest_subscribers.php';
     foreach ($lists as $listId) {
         $wrap = new CS_REST_Subscribers($listId, array('api_key' => $this->getConfig('api_key')));
         $result = $wrap->get($user->email);
         if (!$result->was_successful()) {
             continue;
         }
         $result = $wrap->unsubscribe($user->email);
         if (!$result->was_successful()) {
             throw new Am_Exception_InternalError("Cannot unsubscribe user {$user->email} by reason: {$result->http_status_code}");
         }
     }
     $this->debugLog("onUserBeforeDelete: user #{$user->pk()} was unsubscribed from lists (" . json_encode($lists) . ")");
 }
Example #15
0
File: Tax.php Project: grlf/eyedock
 function onUserBeforeInsert(Am_Event $e)
 {
     $this->setSelfValidationCountry($e->getUser());
 }