public function formExtendModel($model) { $model->block_mail = MailBlocker::isBlockAll($model); $model->bindEvent('model.saveInternal', function () use($model) { unset($model->attributes['block_mail']); }); }
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); }); }
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.'); } }
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()); } }