public function validate($data, $contact_id = null) { $errors = parent::validate($data, $contact_id); $email_model = new waContactEmailsModel(); $contact_model = new waContactModel(); if ($this->isMulti()) { if (!empty($data[0]) && $contact_id) { $c = $contact_model->getById($contact_id); if (!$c['password']) { return $errors; } $value = $this->format($data[0], 'value'); $id = $email_model->getContactWithPassword($value); if ($id && $id != $contact_id) { $errors[0] = sprintf(_ws('User with the same %s is already registered'), 'email'); } } } else { $value = $this->format($data, 'value'); if ($value) { if ($contact_id) { $c = $contact_model->getById($contact_id); if (!$c['password']) { return $errors; } } $id = $email_model->getContactWithPassword($value); if ($id && $id != $contact_id) { $errors = sprintf(_ws('User with the same %s is already registered'), 'email'); } } } return $errors; }
/** * Delete one or more contacts and fire event сontacts.delete * * @event contacts.delete * * @param int|array $id - contact id or array of contact ids * @return bool */ public function delete($id, $send_event = true) { if ($send_event) { // Fire @event contacts.delete allowing other applications to clean up their data if (!is_array($id)) { $id = array($id); } wa()->event(array('contacts', 'delete'), $id); } if (is_array($id)) { $nid = array(); foreach ($id as $i) { $nid[] = -(int) $i; } } else { $nid = -(int) $id; } // Delete rights $right_model = new waContactRightsModel(); $right_model->deleteByField('group_id', $nid); // Delete settings $setting_model = new waContactSettingsModel(); $setting_model->deleteByField('contact_id', $id); // Delete emails $contact_email_model = new waContactEmailsModel(); $contact_email_model->deleteByField('contact_id', $id); // Delete from groups $user_groups_model = new waUserGroupsModel(); $user_groups_model->deleteByField('contact_id', $id); // Delete from contact lists if (class_exists('contactsContactListsModel')) { // @todo: Use plugin for contacts $contact_lists_model = new contactsContactListsModel(); $contact_lists_model->deleteByField('contact_id', $id); } // Delete from contact rights $contact_rights_model = new contactsRightsModel(); $contact_rights_model->deleteByField('group_id', $nid); // Delete data $contact_data_model = new waContactDataModel(); $contact_data_model->deleteByField('contact_id', $id); $contact_data_text_model = new waContactDataTextModel(); $contact_data_text_model->deleteByField('contact_id', $id); // // Delete contact from logs // $login_log_model = new waLoginLogModel(); // $login_log_model->deleteByField('contact_id', $id); // Clear references $this->updateByField(array('company_contact_id' => $id), array('company_contact_id' => 0)); // Delete contact return $this->deleteById($id); }
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&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); } } }
/** * @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(); } }
/** * @param $confirmation_hash * @param array $errors * @return bool|waContact */ protected function confirmEmail($confirmation_hash, &$errors = array()) { $email_id = substr(substr($confirmation_hash, 16), 0, -16); $confirmation_hash = substr($confirmation_hash, 0, 16) . substr($confirmation_hash, -16); $ce = new waContactEmailsModel(); $contact_email = $ce->getById($email_id); $contact = new waContact($contact_email['contact_id']); $user_confirm_hash = $contact->getSettings(wa()->getApp(), "email_confirmation_hash", false); if ($user_confirm_hash && $confirmation_hash === $user_confirm_hash) { // try auth new contact try { if (wa()->getAuth()->auth($contact)) { $ce->updateById($email_id, array('status' => 'confirmed')); $contact->delSettings(wa()->getApp(), "email_confirmation_hash"); } } catch (waException $e) { $errors = array('auth' => $e->getMessage()); } return $contact; } return false; }