예제 #1
0
 public static function changePassword($password, $confirm)
 {
     $errors = [];
     if (empty($password)) {
         $errors[] = 'Password is required';
     } else {
         if (strlen($password) < 4 || strlen($password) > 50) {
             $errors[] = 'Password length must me between 4 and 50';
         } else {
             if (empty($confirm)) {
                 $errors[] = 'Password confirmation is required';
             } else {
                 if ($confirm != $password) {
                     $errors[] = 'Password confirmation is wrong';
                 } else {
                     UsersPDO::setPassword(self::getUserName(), $password);
                 }
             }
         }
     }
     if (!empty($errors)) {
         $ex = new SiteException('Password Change Exception');
         $ex->setErrors($errors);
         throw $ex;
     }
 }
예제 #2
0
 function setPersonalInfo($firstName, $lastName, $birthDate)
 {
     $errors = [];
     if (empty($firstName)) {
         $errors[] = "FirstName is required";
     } else {
         if (strlen($firstName) < 2 || strlen($firstName) > 30) {
             $errors[] = "FirstName must be between 2 and 30";
         }
     }
     if (empty($lastName)) {
         $errors[] = "LastName is required";
     } else {
         if (strlen($lastName) < 2 || strlen($lastName) > 30) {
             $errors[] = "LastName must be between 2 and 30";
         }
     }
     if (empty($birthDate)) {
         $errors[] = "BirthDate is required";
     }
     if (!empty($errors)) {
         $ex = new SiteException('Personal info change failed');
         $ex->setErrors($errors);
         throw $ex;
     } else {
         $user = UsersPDO::get($this->userName);
         if ($user['PersonId'] == null) {
             $personId = PersonsPDO::add($firstName, $lastName, $birthDate);
             UsersPDO::setPersonId($this->userName, $personId);
         } else {
             $personId = $user['PersonId'];
             PersonsPDO::update($personId, $firstName, $lastName, $birthDate);
         }
     }
 }
예제 #3
0
 protected function updateNewsletterStats()
 {
     // the url for stats can only be generated once the campaign has sent.
     // It may not be immediately available, so try to grab it if we've sent
     // the campaign but it hasn't been saved yet.
     if ($this->newsletter->isSent() && $this->newsletter->campaign_report_url === null) {
         $list = DeliveranceListFactory::get($this->app, 'default', DeliveranceNewsletter::getDefaultList($this->app, $this->newsletter->instance));
         $list->setTimeout($this->app->config->deliverance->list_admin_connection_timeout);
         try {
             $this->newsletter->campaign_report_url = $list->getCampaignReportUrl($this->newsletter->campaign_id);
             $this->newsletter->save();
         } catch (Exception $e) {
             $e = new SiteException($e);
             $e->processAndContinue();
         }
     }
 }
 protected function handleResult($result, $success_message)
 {
     $clear_queued = parent::handleResult($result, $success_message);
     if (is_array($result)) {
         $clear_queued = true;
         $this->debug(sprintf($success_message, $result['success_count']));
         // add count doesn't always exist.
         if (isset($result['add_count']) && $result['add_count']) {
             $this->debug(sprintf(Deliverance::_('%s addresses added.') . "\n", $result['add_count']));
         }
         // update count doesn't always exist.
         if (isset($result['update_count']) && $result['update_count']) {
             $this->debug(sprintf(Deliverance::_('%s addresses updated.') . "\n", $result['update_count']));
         }
         // Queued requests can exist in errors or in the result message
         // depending on the request type.
         $queued_count = 0;
         if (isset($result['queued_count']) && $result['queued_count']) {
             $queued_count = $result['queued_count'];
         }
         if ($result['error_count']) {
             $errors = array();
             $not_found_count = 0;
             $bounced_count = 0;
             $previously_unsubscribed_count = 0;
             $invalid_count = 0;
             // don't throw errors for codes we know can be ignored.
             foreach ($result['errors'] as $error) {
                 switch ($error['code']) {
                     case DeliveranceMailChimpList::NOT_FOUND_ERROR_CODE:
                     case DeliveranceMailChimpList::NOT_SUBSCRIBED_ERROR_CODE:
                         $not_found_count++;
                         break;
                     case DeliveranceMailChimpList::PREVIOUSLY_UNSUBSCRIBED_ERROR_CODE:
                         $previously_unsubscribed_count++;
                         break;
                     case DeliveranceMailChimpList::BOUNCED_ERROR_CODE:
                         $bounced_count++;
                         break;
                     case DeliveranceMailChimpList::INVALID_ADDRESS_ERROR_CODE:
                         $invalid_count++;
                         break;
                     case DeliveranceList::QUEUED:
                         $queued_count++;
                         break;
                     default:
                         $error_message = sprintf(Deliverance::_('code: %s - message: %s.'), $error['code'], $error['message']);
                         $errors[] = $error_message;
                         $execption = new SiteException($error_message);
                         // don't exit on returned errors
                         $execption->processAndContinue();
                 }
             }
             if ($not_found_count > 0) {
                 $this->debug(sprintf(Deliverance::_('%s addresses not found.') . "\n", $not_found_count));
             }
             if ($previously_unsubscribed_count > 0) {
                 $this->debug(sprintf(Deliverance::_('%s addresses have previously subscribed, ' . 'and cannot be resubscribed.') . "\n", $previously_unsubscribed_count));
             }
             if ($bounced_count > 0) {
                 $this->debug(sprintf(Deliverance::_('%s addresses have bounced, and cannot be ' . 'resubscribed.') . "\n", $bounced_count));
             }
             if ($invalid_count > 0) {
                 $this->debug(sprintf(Deliverance::_('%s invalid addresses.') . "\n", $invalid_count));
             }
             if (count($errors)) {
                 $this->debug(sprintf(Deliverance::_('%s errors:') . "\n", count($errors)));
                 foreach ($errors as $error) {
                     $this->debug($error . "\n");
                 }
             }
         }
         if ($queued_count > 0) {
             $clear_queued = false;
             $this->debug(sprintf(Deliverance::_('%s addresses queued.') . "\n", $queued_count));
         }
     }
     return $clear_queued;
 }