Beispiel #1
0
 /**
  * Displays a form to register a new user.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionIndex()
 {
     if (XenForo_Visitor::getUserId()) {
         throw $this->responseException($this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, $this->getDynamicRedirect()));
     }
     $this->_assertRegistrationActive();
     $username = '';
     $email = '';
     if ($login = $this->_input->filterSingle('login', XenForo_Input::STRING)) {
         if (XenForo_Helper_Email::isEmailValid($login)) {
             $email = $login;
         } else {
             $username = $login;
         }
     }
     $fields = array('username' => $username, 'email' => $email);
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     if ($username !== '') {
         $writer->set('username', $username);
     }
     if ($email !== '') {
         $writer->set('email', $email);
     }
     return $this->_getRegisterFormResponse($fields, $writer->getErrors());
 }
Beispiel #2
0
 public function actionGetFind()
 {
     $users = array();
     $username = $this->_input->filterSingle('username', XenForo_Input::STRING);
     $email = $this->_input->filterSingle('user_email', XenForo_Input::STRING);
     if (empty($email)) {
         // backward compatibility
         $email = $this->_input->filterSingle('email', XenForo_Input::STRING);
     }
     if (XenForo_Helper_Email::isEmailValid($email)) {
         $visitor = XenForo_Visitor::getInstance();
         $session = bdApi_Data_Helper_Core::safeGetSession();
         if ($visitor->hasAdminPermission('user') && $session->checkScope(bdApi_Model_OAuth2::SCOPE_MANAGE_SYSTEM)) {
             // perform email search only if visitor is an admin and granted admincp scope
             $user = $this->_getUserModel()->getUserByEmail($email);
             if (!empty($user)) {
                 $users[$user['user_id']] = $user;
             }
         }
     }
     if (empty($users) && utf8_strlen($username) >= 2) {
         // perform username search only if nothing found and username is long enough
         $users = $this->_getUserModel()->getUsers(array('username' => array($username, 'r')), array('limit' => 10));
     }
     $data = array('users' => $this->_filterDataMany($this->_getUserModel()->prepareApiDataForUsers($users)));
     return $this->responseData('bdApi_ViewData_User_Find', $data);
 }
Beispiel #3
0
 /**
  * Determines if the specified email is banned. List of banned emails
  * is simply an array of strings with * as wildcards.
  *
  * @param string $email
  * @param array|null $bannedEmails List of banned emails; if null, uses the default value
  *
  * @return boolean
  */
 public static function isEmailBanned($email, array $bannedEmails = null)
 {
     if ($bannedEmails === null) {
         if (self::$_bannedEmailCache === null) {
             $bannedEmails = XenForo_Model::create('XenForo_Model_DataRegistry')->get('bannedEmails');
             if (!is_array($bannedEmails)) {
                 $bannedEmails = XenForo_Model::create('XenForo_Model_Banning')->rebuildBannedEmailCache();
             }
             self::$_bannedEmailCache = $bannedEmails;
         } else {
             $bannedEmails = self::$_bannedEmailCache;
         }
     }
     foreach ($bannedEmails as $bannedEmail) {
         $bannedEmail = str_replace('\\*', '(.*)', preg_quote($bannedEmail, '/'));
         if (preg_match('/^' . $bannedEmail . '$/i', $email)) {
             return true;
         }
     }
     return false;
 }
Beispiel #4
0
 public function verifyEmail($email, $userId = null)
 {
     if (!Zend_Validate::is($email, 'EmailAddress')) {
         return new XenForo_Phrase('please_enter_valid_email');
     }
     $existingUser = XenForo_Model::create('XenForo_Model_User')->getUserByEmail($email);
     if ($existingUser && (!$userId || $userId && $userId != $existingUser['user_id'])) {
         return new XenForo_Phrase('email_addresses_must_be_unique');
     }
     if (XenForo_Helper_Email::isEmailBanned($email)) {
         return new XenForo_Phrase('email_address_you_entered_has_been_banned_by_administrator');
     }
     return true;
 }
Beispiel #5
0
 /**
  * Verifies that a gravatar email address is valid, or empty
  *
  * @param string $gravatarEmail
  *
  * @return boolean
  */
 protected function _verifyGravatar(&$gravatarEmail)
 {
     if ($gravatarEmail !== '' && !XenForo_Helper_Email::isEmailValid($gravatarEmail)) {
         $this->error(new XenForo_Phrase('please_enter_valid_email'), 'gravatar');
         return false;
     }
     return true;
 }
Beispiel #6
0
 /**
  * Verifies that the value for the specified field is valid.
  *
  * @param array $field
  * @param mixed $value
  * @param mixed $error Returned error message
  *
  * @return boolean
  */
 public function verifyUserFieldValue(array $field, &$value, &$error = '')
 {
     $error = false;
     switch ($field['field_type']) {
         case 'textbox':
             $value = preg_replace('/\\r?\\n/', ' ', strval($value));
             // break missing intentionally
         // break missing intentionally
         case 'textarea':
             $value = trim(strval($value));
             if ($field['max_length'] && utf8_strlen($value) > $field['max_length']) {
                 $error = new XenForo_Phrase('please_enter_value_using_x_characters_or_fewer', array('count' => $field['max_length']));
                 return false;
             }
             $matched = true;
             if ($value !== '') {
                 switch ($field['match_type']) {
                     case 'number':
                         $matched = preg_match('/^[0-9]+(\\.[0-9]+)?$/', $value);
                         break;
                     case 'alphanumeric':
                         $matched = preg_match('/^[a-z0-9_]+$/i', $value);
                         break;
                     case 'email':
                         $matched = XenForo_Helper_Email::isEmailValid($value);
                         break;
                     case 'url':
                         if ($value === 'http://') {
                             $value = '';
                             break;
                         }
                         if (substr(strtolower($value), 0, 4) == 'www.') {
                             $value = 'http://' . $value;
                         }
                         $matched = Zend_Uri::check($value);
                         break;
                     case 'regex':
                         $matched = preg_match('#' . str_replace('#', '\\#', $field['match_regex']) . '#sU', $value);
                         break;
                     case 'callback':
                         $matched = call_user_func_array(array($field['match_callback_class'], $field['match_callback_method']), array($field, &$value, &$error));
                     default:
                         // no matching
                 }
             }
             if (!$matched) {
                 if (!$error) {
                     $error = new XenForo_Phrase('please_enter_value_that_matches_required_format');
                 }
                 return false;
             }
             break;
         case 'radio':
         case 'select':
             $choices = XenForo_Helper_Php::safeUnserialize($field['field_choices']);
             $value = strval($value);
             if (!isset($choices[$value])) {
                 $value = '';
             }
             break;
         case 'checkbox':
         case 'multiselect':
             $choices = XenForo_Helper_Php::safeUnserialize($field['field_choices']);
             if (!is_array($value)) {
                 $value = array();
             }
             $newValue = array();
             foreach ($value as $key => $choice) {
                 $choice = strval($choice);
                 if (isset($choices[$choice])) {
                     $newValue[$choice] = $choice;
                 }
             }
             $value = $newValue;
             break;
     }
     return true;
 }
Beispiel #7
0
 public function actionContact()
 {
     $options = XenForo_Application::get('options');
     if ($options->contactUrl['type'] == 'custom') {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, $options->contactUrl['custom']);
     } else {
         if (!$options->contactUrl['type']) {
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, XenForo_Link::buildPublicLink('index'));
         }
     }
     if ($this->_request->isPost()) {
         if (!XenForo_Captcha_Abstract::validateDefault($this->_input)) {
             return $this->responseCaptchaFailed();
         }
         $user = XenForo_Visitor::getInstance()->toArray();
         if (!$user['user_id']) {
             $user['email'] = $this->_input->filterSingle('email', XenForo_Input::STRING);
             if (!XenForo_Helper_Email::isEmailValid($user['email'])) {
                 return $this->responseError(new XenForo_Phrase('please_enter_valid_email'));
             }
         }
         $input = $this->_input->filter(array('subject' => XenForo_Input::STRING, 'message' => XenForo_Input::STRING));
         if (!$user['username'] || !$input['subject'] || !$input['message']) {
             return $this->responseError(new XenForo_Phrase('please_complete_required_fields'));
         }
         $this->assertNotFlooding('contact');
         $ip = $this->_request->getClientIp(false);
         $mailParams = array('user' => $user, 'subject' => $input['subject'], 'message' => $input['message'], 'ip' => $ip);
         $mail = XenForo_Mail::create('contact', $mailParams, 0);
         $headers = array('X-Contact-IP' => $ip);
         if ($options->contactEmailSenderHeader) {
             $headers['Sender'] = $options->contactEmailAddress;
             $fromEmail = $user['email'];
         } else {
             $fromEmail = '';
         }
         $toEmail = $options->contactEmailAddress ? $options->contactEmailAddress : $options->defaultEmailAddress;
         $mailObj = $mail->getPreparedMailHandler($toEmail, '', $headers, $fromEmail, $user['username']);
         if ($user['email'] && !$options->contactEmailSenderHeader) {
             $mailObj->setReplyTo($user['email'], $user['username']);
         }
         $mail->sendMail($mailObj);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(), new XenForo_Phrase('your_message_has_been_sent'));
     } else {
         $viewParams = array('redirect' => $this->getDynamicRedirect(), 'isOverlay' => $this->_noRedirect() ? true : false, 'captcha' => XenForo_Captcha_Abstract::createDefault());
         return $this->responseView('XenForo_ViewPublic_Misc_Contact', 'contact', $viewParams);
     }
 }
Beispiel #8
0
 /**
  * Checks whether a Gravatar exists for a given email address
  *
  * @param string $email
  *
  * @return string|boolean Gravatar URL on success
  */
 public static function gravatarExists($email, &$errorText = '', $size = 1, &$gravatarUrl = '')
 {
     if (!XenForo_Helper_Email::isEmailValid($email)) {
         $errorText = new XenForo_Phrase('gravatars_require_valid_email_addresses');
         return false;
     }
     try {
         $client = XenForo_Helper_Http::getClient(self::_getGravatarUrl($email, 1, 404), array('maxredirects' => 0, 'timeout' => 5));
         if ($client->request('HEAD')->getStatus() !== 200) {
             $errorText = new XenForo_Phrase('no_gravatar_found_for_specified_email_address');
             return false;
         }
     } catch (Exception $e) {
         if (strpos($e->getMessage(), 'Read timed out') === false) {
             // don't log timeouts - they're most likely on Gravatar's side
             XenForo_Error::logException($e, false);
         }
         $errorText = new XenForo_Phrase('there_was_problem_communicating_with_gravatar');
         return false;
     }
     $gravatarUrl = self::_getGravatarUrl($email, $size, false);
     return true;
 }
Beispiel #9
0
 public static function getFinalTransportForMail(Zend_Mail $mailObj, Zend_Mail_Transport_Abstract $transport)
 {
     $returnPath = $mailObj->getReturnPath();
     if ($returnPath && $transport instanceof Zend_Mail_Transport_Sendmail) {
         $transportOption = XenForo_Application::getOptions()->get('emailTransport', false);
         if (!empty($transportOption['sendmailReturnPath']) && XenForo_Helper_Email::isEmailValid($returnPath)) {
             $config = '-f "' . $returnPath . '"';
         } else {
             $config = null;
         }
         $transport = new Zend_Mail_Transport_Sendmail($config);
     }
     return $transport;
 }
 /**
  * Verification callback to check the email address is in a valid form
  *
  * @param string Email Address
  *
  * @return bool
  */
 protected function _verifyEmail(&$email)
 {
     if ($this->isUpdate() && $email === $this->getExisting('paypal_email')) {
         return true;
     }
     if ($email === '') {
         return true;
     }
     if (!XenForo_Helper_Email::isEmailValid($email)) {
         $this->error(new XenForo_Phrase('please_enter_valid_email'), 'email');
         return false;
     }
     if (XenForo_Helper_Email::isEmailBanned($email)) {
         $this->error(new XenForo_Phrase('email_address_you_entered_has_been_banned_by_administrator'), 'email');
         return false;
     }
     return true;
 }
Beispiel #11
0
 /**
  * Verification callback to check the email address is in a valid form
  *
  * @param string Email Address
  *
  * @return bool
  */
 protected function _verifyEmail($email)
 {
     if ($this->isUpdate() && $email === $this->getExisting('email')) {
         return true;
     }
     if ($this->getOption(self::OPTION_ADMIN_EDIT) && $email === '') {
         return true;
     }
     if (!Zend_Validate::is($email, 'EmailAddress')) {
         $this->error(new XenForo_Phrase('please_enter_valid_email'), 'email');
         return false;
     }
     $existingUser = $this->_getUserModel()->getUserByEmail($email);
     if ($existingUser && $existingUser['user_id'] != $this->get('user_id')) {
         $this->error(new XenForo_Phrase('email_addresses_must_be_unique'), 'email');
         return false;
     }
     if (XenForo_Helper_Email::isEmailBanned($email)) {
         $this->error(new XenForo_Phrase('email_address_you_entered_has_been_banned_by_administrator'), 'email');
         return false;
     }
     return true;
 }