예제 #1
0
 function indexAction()
 {
     $e = $this->getParam('e');
     if (!$e) {
         throw new Am_Exception_InputError("Empty e-mail parameter passed - wrong url");
     }
     $s = $this->getFiltered('s');
     if (!Am_Mail::validateUnsubscribeLink($e, $s, Am_Mail::LINK_USER)) {
         throw new Am_Exception_InputError(___('Wrongly signed URL, please contact site admin'));
     }
     $this->view->user = $this->getDi()->userTable->findFirstByEmail($e);
     if (!$this->view->user) {
         throw new Am_Exception_InputError(___("Wrong parameters, error #1253"));
     }
     if ($this->_request->get('yes')) {
         $this->view->user->unsubscribed = 1;
         $this->view->user->update();
         $this->getDi()->hook->call(Am_Event::USER_UNSUBSCRIBED_CHANGED, array('user' => $this->view->user, 'unsubscribed' => 1));
         return $this->_redirect('member?' . http_build_query(array('_msg' => ___('Status of your subscription has been changed.')), '', '&'));
     } elseif ($this->_request->get('no')) {
         return $this->_redirect('member');
     }
     $this->view->e = $e;
     $this->view->s = $s;
     if (!$this->getDi()->blocks->get($this->view, 'unsubscribe')) {
         $this->getDi()->blocks->add(new Am_Block('unsubscribe', ___('Unsubscribe'), 'unsubscribe-std', null, 'unsubscribe-std.phtml'));
     }
     $this->view->display('unsubscribe.phtml');
 }
 /**
  * display signup page
  */
 function indexAction()
 {
     $e = $this->getParam('e');
     if (!$e) {
         throw new Am_Exception_InputError("Empty e-mail parameter passed - wrong url");
     }
     $s = $this->getFiltered('s');
     if (!Am_Mail::validateUnsubscribeLink($e, $s, Am_Mail::LINK_GUEST)) {
         throw new Am_Exception_InputError(___('Wrongly signed URL, please contact site admin'));
     }
     $this->view->guest = $this->getDi()->newsletterGuestTable->findFirstByEmail($e);
     if (!$this->view->guest) {
         throw new Am_Exception_InputError(___("Your e-mail address was not found in database"));
     }
     $this->view->e = $e;
     $this->view->s = $s;
     $this->lists = $this->getDi()->newsletterListTable->findGuests();
     if (!$this->lists) {
         throw new Am_Exception_InputError("Guest subscriptions disabled - no lists available");
     }
     $this->view->form = $this->createForm();
     if ($this->view->form->isSubmitted() && $this->view->form->validate()) {
         $this->changeSubscriptions($this->view->guest, $this->view->form->getValue());
         $this->_redirect('index');
     }
     $this->view->display('newsletter/unsubscribe.phtml');
 }
예제 #3
0
 function updateSubscriptionAction()
 {
     if (($s = $this->getFiltered('s')) && ($e = $this->getParam('e')) && Am_Mail::validateUnsubscribeLink($e, $s)) {
         $user = $this->getDi()->userTable->findFirstByEmail($e);
     } else {
         $user = $this->getDi()->user;
     }
     if (!$user) {
         throw new Am_Exception_InputError("You must be logged-in to use this function");
     }
     $allowed = array();
     foreach ($this->getDi()->newsletterListTable->getAllowed($user) as $r) {
         $allowed[$r->pk()] = $r;
     }
     $subs = array();
     foreach ($this->getDi()->newsletterUserSubscriptionTable->findByUserId($user->pk()) as $s) {
         $subs[$s->list_id] = $s;
     }
     $post = $this->getRequest()->getPost();
     $ret = array('status' => 'OK');
     foreach ($post as $k => $v) {
         if (!is_int($k)) {
             continue;
         }
         switch ($v) {
             case 0:
                 if (!empty($subs[$k])) {
                     $subs[$k]->unsubscribe();
                 }
                 $ret[(int) $k] = (int) $v;
                 break;
             case 1:
                 $this->getDi()->newsletterUserSubscriptionTable->add($user->pk(), $k, NewsletterUserSubscription::TYPE_USER);
                 $ret[(int) $k] = (int) $v;
                 break;
             default:
                 throw new Am_Exception_InputError("Wrong value submitted");
         }
     }
     $this->ajaxResponse($ret);
 }
예제 #4
0
 function unsubscribedAction()
 {
     $v = $this->_request->getPost('unsubscribed');
     if (strlen($v) != 1) {
         throw new Am_Exception_InputError("Wrong input");
     }
     $v = $v > 0 ? 1 : 0;
     if (($s = $this->getFiltered('s')) && ($e = $this->getParam('e')) && Am_Mail::validateUnsubscribeLink($e, $s)) {
         $user = $this->getDi()->userTable->findFirstByEmail($e);
     } else {
         $user = $this->getDi()->user;
     }
     if (!$user) {
         return $this->ajaxError("You must be logged-in to run this action");
     }
     if ($user->unsubscribed != $v) {
         $user->set('unsubscribed', $v)->update();
         $this->getDi()->hook->call(Am_Event::USER_UNSUBSCRIBED_CHANGED, array('user' => $user, 'unsubscribed' => $v));
     }
     $this->ajaxResponse(array('status' => 'OK', 'value' => $v));
 }