Ejemplo n.º 1
0
 public function unsubscribe()
 {
     $message = 'There was an error unsubscribing you.';
     $confirmLink = null;
     $unsubscriberEmail = $this->validateUnsubscriberEmail($this->getParam('email'));
     $unsubscriberHash = $this->getParam('hash', '');
     if ($unsubscriberEmail && $unsubscriberHash && $this->getParam('confirmed')) {
         $unsubscriber['email'] = $unsubscriberEmail;
         $contact = $this->contactStore->findContact($unsubscriber);
         if ($unsubscriberHash === $this->contactStore->getUnsubscribeHash($contact->getId(), $unsubscriberEmail)) {
             $contact->setMarketingOptin(0);
             $this->contactStore->saveByUpdate($contact);
             $message = 'Good-bye! You’ve successfully unsubscribed yourself from the email list.';
         }
     } elseif ($unsubscriberEmail && $unsubscriberHash && !$this->getParam('confirmed')) {
         //Show confirmation
         $message = null;
         $confirmLink = '/contact/unsubscribe?email=' . $unsubscriberEmail;
         $confirmLink .= '&hash=' . $unsubscriberHash . '&confirmed=1';
     } else {
         $this->response = new RedirectResponse();
         $redirect = $this->config->get('site.url');
         $this->response->setHeader('Location', $redirect);
         return;
     }
     $view = Template::load('Mailshot/unsubscribe');
     $view->message = $message;
     $view->confirmLink = $confirmLink;
     return $view->render();
 }