示例#1
0
文件: Optin.php 项目: rukzuk/rukzuk
 /**
  * @param  \Orm\Entity\OptIn $optin
  *
  * @throws \Cms\Service\Optin\InvalidModeException
  */
 private function isValidMode(\Orm\Entity\OptIn $optin)
 {
     $mode = $optin->getMode();
     if (!in_array($mode, array(\Orm\Entity\OptIn::MODE_REGISTER, \Orm\Entity\OptIn::MODE_PASSWORD))) {
         throw new InvalidModeException(1038, __METHOD__, __LINE__, array('mode' => $mode));
     }
 }
示例#2
0
 /**
  * @param  array     $users
  * @param  string    $mode
  * @return \Orm\Entity\OptIn
  */
 public function create(array $users, $mode)
 {
     $entityManager = $this->getEntityManager();
     $entityManager->beginTransaction();
     $optins = array();
     foreach ($users as $user) {
         $optin = new OptIn();
         $optin->setUser($user);
         $optin->setUserid($user->getId());
         $optin->setTimestamp(new \DateTime());
         $optin->setMode($mode);
         $optin->setCode(OptinCode::generate());
         try {
             $entityManager->persist($optin);
             $entityManager->flush();
         } catch (Exception $e) {
             $entityManager->rollback();
             throw new CmsException(1004, __METHOD__, __LINE__, null, $e);
         }
         $optins[] = $optin;
     }
     $entityManager->commit();
     return $optins;
 }
示例#3
0
 /**
  * @param  \Orm\Entity\OptIn $optin
  * @param  string     $charset
  * @return \Cms\Mail
  */
 public function getRenewPasswordMail(\Orm\Entity\OptIn $optin, $charset = 'utf-8')
 {
     $config = Registry::getConfig();
     $baseUrl = Registry::getBaseUrl();
     $optinUser = $optin->getUser();
     $locale = self::getLocale($optinUser->getLanguage());
     $fromUser = $this->getMailFromUserData(array('email' => $config->user->mail->renew->password->from->address, 'name' => $config->user->mail->renew->password->from->name));
     $this->view->clearVars();
     $this->view->optin = $optin;
     $this->view->optinUser = $optinUser;
     $this->view->optinUrl = $baseUrl . $config->user->mail->renew->password->uri;
     $this->view->spaceUrl = $baseUrl;
     $this->view->fromName = $fromUser['name'];
     $this->view->fromEmail = $fromUser['email'];
     $renewMail = new \Cms\Mail($charset);
     $renewMail->setBodyText($this->view->render($this->getTemplateFilename(__FUNCTION__, $locale)));
     // the subject is set in mail template
     $subject = $this->view->subject;
     $renewMail->setFrom($fromUser['email'], $fromUser['name']);
     $renewMail->setSubject($subject);
     $renewMail->addTo($optinUser->getEmail(), $optinUser->getFirstname() . ' ' . $optinUser->getLastname());
     return $renewMail;
 }
示例#4
0
 /**
  * {@inheritDoc}
  */
 public function setMode($mode)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setMode', array($mode));
     return parent::setMode($mode);
 }