public function prepareView(&$comments)
 {
     $email = wa_make_pattern(trim($this->getSettingValue('email')));
     if ($email) {
         $pattern = '/(.*' . preg_replace('/[,\\n\\s]{1,}/', '|.*', $email) . ')/i';
         if (wa()->getEnv() == 'backend' && wa()->getUser()->isAdmin($this->app_id)) {
             $label = '<a href="?module=plugins&amp;slug=troll"><i class="icon16 troll"  title="' . ($title = _wp('Troll')) . '"><!-- trollface --></i></a>';
         } else {
             $label = '<i class="icon16 troll"  title="' . ($title = _wp('Troll!')) . '"><!-- trollface --></i>';
         }
         // Fetch emails of registered users
         $contact_troll = array();
         $check_emails = array();
         foreach ($comments as $comment) {
             if (!empty($comment['contact_id'])) {
                 $contact_troll[$comment['contact_id']] = preg_match($pattern, $comment['name']);
                 if (!$contact_troll[$comment['contact_id']]) {
                     $check_emails[$comment['contact_id']] = 1;
                 }
             }
         }
         $contact_model = new waContactEmailsModel();
         foreach ($contact_model->getByField('contact_id', array_keys($check_emails), true) as $row) {
             if (empty($contact_troll[$row['contact_id']]) && preg_match($pattern, $row['email'])) {
                 $contact_troll[$row['contact_id']] = true;
             }
         }
         foreach ($comments as &$comment) {
             if (!empty($comment['contact_id'])) {
                 if (!empty($contact_troll[$comment['contact_id']])) {
                     $comment['plugins']['authorname_suffix'][$this->id] = $label;
                 }
             } else {
                 if ($comment['email'] && preg_match($pattern, $comment['email']) || $comment['site'] && preg_match($pattern, $comment['site']) || $comment['name'] && preg_match($pattern, $comment['name'])) {
                     $comment['plugins']['authorname_suffix'][$this->id] = $label;
                 }
             }
             unset($comment);
         }
     }
 }
예제 #2
0
    /**
     * @param $params
     * @return array|bool
     * @throws waException
     */
    protected function _auth($params)
    {
        if ($params && isset($params['id'])) {
            $contact_model = new waContactModel();
            $user_info = $contact_model->getById($params['id']);
            if ($user_info && ($user_info['is_user'] > 0 || !$this->options['is_user'])) {
                waSystem::getInstance()->getResponse()->setCookie('auth_token', null, -1);
                return $this->getAuthData($user_info);
            }
            return false;
        } elseif ($params && isset($params['login']) && isset($params['password'])) {
            $login = $params['login'];
            $password = $params['password'];
        } elseif (waRequest::getMethod() == 'post' && waRequest::post('wa_auth_login')) {
            $login = waRequest::post('login');
            $password = waRequest::post('password');
            if (!strlen($login)) {
                throw new waException(_ws('Login is required'));
            }
        } else {
            $login = null;
        }
        if ($login && strlen($login)) {
            $user_info = $this->getByLogin($login);
            if ($user_info && ($user_info['is_user'] > 0 || !$this->options['is_user']) && waContact::getPasswordHash($password) === $user_info['password']) {
                $auth_config = wa()->getAuthConfig();
                if (wa()->getEnv() == 'frontend' && !empty($auth_config['params']['confirm_email'])) {
                    $contact_emails_model = new waContactEmailsModel();
                    $email_row = $contact_emails_model->getByField(array('contact_id' => $user_info['id'], 'sort' => 0));
                    if ($email_row && $email_row['status'] == 'unconfirmed') {
                        $login_url = wa()->getRouteUrl((isset($auth_config['app']) ? $auth_config['app'] : '') . '/login', array());
                        $html = sprintf(_ws('A confirmation link has been sent to your email address provided during the signup. Please click this link to confirm your email and to sign in. <a class="send-email-confirmation" href="%s">Resend the link</a>'), $login_url . '?send_confirmation=1');
                        $html = '<div class="block-confirmation-email">' . $html . '</div>';
                        $html .= <<<HTML
<script type="text/javascript">
    \$(function () {
        \$('a.send-email-confirmation').click(function () {
            \$.post(\$(this).attr('href'), {
                    login: \$(this).closest('form').find("input[name='login']").val()
                }, function (response) {
                \$('.block-confirmation-email').html(response);
            });
            return false;
        });
    });
</script>
HTML;
                        throw new waException($html);
                    }
                }
                $response = waSystem::getInstance()->getResponse();
                // if remember
                if (waRequest::post('remember')) {
                    $cookie_domain = ifset($this->options['cookie_domain'], '');
                    $response->setCookie('auth_token', $this->getToken($user_info), time() + 2592000, null, $cookie_domain, false, true);
                    $response->setCookie('remember', 1);
                } else {
                    $response->setCookie('remember', 0);
                }
                // return array with compact user info
                return $this->getAuthData($user_info);
            } else {
                if ($this->options['login'] == 'email') {
                    throw new waException(_ws('Invalid email or password'));
                } else {
                    throw new waException(_ws('Invalid login or password'));
                }
            }
        } else {
            // try auth by cookie
            return $this->_authByCookie();
        }
    }
예제 #3
0
 private function sendConfirmationLink(waContact $contact)
 {
     $config = wa()->getAuthConfig();
     if (!empty($config['params']['confirm_email'])) {
         $confirmation_hash = md5(time() . 'rfb2:zfbdbawrsddswr4$h5t3/.`w' . mt_rand() . mt_rand() . mt_rand());
         $contact->setSettings(wa()->getApp(), "email_confirmation_hash", $confirmation_hash);
         $ce = new waContactEmailsModel();
         $unconfirmed_email = $ce->getByField(array('contact_id' => $contact->getId(), 'email' => $contact->get('email', 'default'), 'status' => 'unconfirmed'));
         $hash = substr($confirmation_hash, 0, 16) . $unconfirmed_email['id'] . substr($confirmation_hash, -16);
         $this->view->assign('email_confirmation_hash', $hash);
         return true;
     }
     return false;
 }