A utility model that allows a user to block specific mail views/templates from being sent to their address.
Наследование: extends Mode\Model
Пример #1
0
 public function formExtendModel($model)
 {
     $model->block_mail = MailBlocker::isBlockAll($model);
     $model->bindEvent('model.saveInternal', function () use($model) {
         unset($model->attributes['block_mail']);
     });
 }
Пример #2
0
 public function register()
 {
     $alias = AliasLoader::getInstance();
     $alias->alias('Auth', 'RainLab\\User\\Facades\\Auth');
     App::singleton('user.auth', function () {
         return \RainLab\User\Classes\AuthManager::instance();
     });
     /*
      * Apply user-based mail blocking 
      */
     Event::listen('mailer.prepareSend', function ($mailer, $view, $message) {
         return MailBlocker::filterMessage($view, $message);
     });
 }
Пример #3
0
 protected function handleOptOutLinks()
 {
     if (!($topic = $this->getTopic())) {
         return;
     }
     if (!($action = post('action'))) {
         return;
     }
     if (!in_array($action, ['unfollow', 'unsubscribe'])) {
         return;
     }
     /*
      * Attempt to find member using dry authentication
      */
     if (!($member = $this->getMember())) {
         if (!($authCode = post('auth')) || !strpos($authCode, '!')) {
             return;
         }
         list($hash, $userId) = explode('!', $authCode);
         if (!($user = UserModel::find($userId))) {
             return;
         }
         if (!($member = MemberModel::getFromUser($user))) {
             return;
         }
         $expectedCode = TopicFollow::makeAuthCode($action, $topic, $member);
         if ($authCode != $expectedCode) {
             Flash::error('Invalid authentication code, please sign in and try the link again.');
             return;
         }
     }
     /*
      * Unfollow link
      */
     if ($action == 'unfollow') {
         TopicFollow::unfollow($topic, $member);
         Flash::success('You will no longer receive notifications about this topic.');
     }
     /*
      * Unsubscribe link
      */
     if ($action == 'unsubscribe' && $member->user) {
         MailBlocker::addBlock('rainlab.forum::mail.topic_reply', $member->user);
         Flash::success('You will no longer receive notifications about any topics in this forum.');
     }
 }
Пример #4
0
 public function onUpdate()
 {
     try {
         if (!$this->canEdit()) {
             throw new ApplicationException('Permission denied.');
         }
         $member = $this->getMember();
         if (!$member) {
             return;
         }
         /*
          * Process mail preferences
          */
         if ($member->user) {
             MailBlocker::toggleBlocks(post('MailPreferences'), $member->user, $this->getMailTemplates());
         }
         /*
          * Save member
          */
         $data = array_except(post(), 'MailPreferences');
         $member->save($data);
         Flash::success(post('flash', 'Settings successfully saved!'));
         return $this->redirectToSelf();
     } catch (Exception $ex) {
         Flash::error($ex->getMessage());
     }
 }