addBlock() public static method

Adds a block for a user and a mail view/template code.
public static addBlock ( string $template, RainLab\User\Models\User $user ) : boolean
$template string
$user RainLab\User\Models\User
return boolean
Exemplo n.º 1
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.');
     }
 }