public function validate($review) { $errors = array(); $config = wa()->getConfig(); if ($review['auth_provider'] == self::AUTH_GUEST) { if ($config->getGeneralSettings('require_authorization', false)) { return array('name' => _w('Only authorized users can post reviews')); } if ($config->getGeneralSettings('require_captcha') && !wa()->getCaptcha()->isValid()) { return array('captcha' => _w('Invalid captcha code')); } if (!empty($review['site']) && strpos($review['site'], '://') === false) { $review['site'] = "http://" . $review['site']; } if (empty($review['name']) || mb_strlen($review['name']) == 0) { $errors['name'] = _w('Name can not be left blank'); } if (mb_strlen($review['name']) > 255) { $errors['name'] = _w('Name length should not exceed 255 symbols'); } if (empty($review['email']) || mb_strlen($review['email']) == 0) { $errors['email'] = _w('Email can not be left blank'); } $validator = new waEmailValidator(); if (!$validator->isValid($review['email'])) { $errors['email'] = _w('Email is not valid'); } $validator = new waUrlValidator(); if (!empty($review['site']) && !$validator->isValid($review['site'])) { $errors['site'] = _w('Site URL is not valid'); } } if (empty($review['parent_id'])) { // review to product if (empty($review['title'])) { $errors['title'] = _w('Review title can not be left blank'); } } else { // comment ot review if (empty($review['text'])) { $errors['text'] = _w('Review text can not be left blank'); } } if (mb_strlen($review['text']) > 4096) { $errors['text'] = _w('Review length should not exceed 4096 symbols'); } return $errors; }
public function validate($comment) { $errors = array(); if ($comment['contact_id']) { $user = wa()->getUser(); if ($user->getId() && !$user->get('is_user')) { $user->addToCategory(wa()->getApp()); } } elseif ($comment['auth_provider'] == 'guest') { if (!empty($comment['site']) && strpos($comment['site'], '://') === false) { $comment['site'] = "http://" . $comment['site']; } if (empty($comment['name']) || mb_strlen($comment['name']) == 0) { $errors[]['name'] = _wp('Name can not be left blank'); } if (mb_strlen($comment['name']) > 255) { $errors[]['name'] = _wp('Name length should not exceed 255 symbols'); } if (empty($comment['name']) || mb_strlen($comment['email']) == 0) { $errors[]['email'] = _wp('Email can not be left blank'); } $validator = new waEmailValidator(); if (!$validator->isValid($comment['email'])) { $errors[]['email'] = _wp('Email is not valid'); } $validator = new waUrlValidator(); if (!empty($comment['site']) && !$validator->isValid($comment['site'])) { $errors[]['site'] = _wp('Site URL is not valid'); } if (!wa()->getUser()->isAuth() && !wa()->getCaptcha()->isValid()) { $errors[] = array('captcha' => _wp('Invalid captcha code')); } } else { $auth_adapters = wa()->getAuthAdapters(); if (!isset($auth_adapters[$comment['auth_provider']])) { $errors[] = _w('Invalid auth provider'); } } if (mb_strlen($comment['text']) == 0) { $errors[]['text'] = _wp('Comment text can not be left blank'); } if (mb_strlen($comment['text']) > 4096) { $errors[]['text'] = _wp('Comment length should not exceed 4096 symbols'); } return $errors; }
/** * Execute step * * @return bool */ public function execute() { $contact = $this->getContact(); if (!$contact) { $contact = new waContact(); } $data = waRequest::post('customer'); if ($data && is_array($data)) { foreach ($data as $field => $value) { $contact->set($field, $value); } } $this->form = shopHelper::getCustomerForm(); if ($shipping = $this->getSessionData('shipping') && !waRequest::post('ignore_shipping_error')) { $shipping_step = new shopOnestepCheckoutShipping(); $rate = $shipping_step->getRate($shipping['id'], isset($shipping['rate_id']) ? $shipping['rate_id'] : null, $contact); if (!$rate || is_string($rate)) { // remove selected shipping method $this->setSessionData('shipping', null); /* $errors = array(); $errors['all'] = sprintf(_w('We cannot ship to the specified address via %s.'), $shipping['name']); if ($rate) { $errors['all'] .= '<br> <strong>'.$rate.'</strong><br>'; } $errors['all'] .= '<br> '._w('Please double-check the address above, or return to the shipping step and select another shipping option.'); $errors['all'] .= '<input type="hidden" name="ignore_shipping_error" value="1">'; wa()->getView()->assign('errors', $errors); return false; */ } } if (wa()->getUser()->isAuth()) { $contact->save(); } else { $errors = array(); if (waRequest::post('create_user')) { $login = waRequest::post('login'); if (!$login) { $errors['email'][] = _ws('Required'); } if (!waRequest::post('password')) { $errors['password'] = _ws('Required'); } $email_validator = new waEmailValidator(); if (!$email_validator->isValid($login)) { $errors['email'] = $email_validator->getErrors(); } if (!$errors) { $contact_model = new waContactModel(); if ($contact_model->getByEmail($login, true)) { $errors['email'][] = _w('Email already registered'); } } if (!$errors) { $contact->set('email', $login); $contact->set('password', waRequest::post('password')); } else { if (isset($errors['email'])) { $errors['email'] = implode(', ', $errors['email']); } wa()->getView()->assign('errors', $errors); return false; } } $this->setSessionData('contact', $contact); } if ($comment = waRequest::post('comment')) { $this->setSessionData('comment', $comment); } if (!$this->form->isValid($contact)) { return false; } return true; }
public function execute() { $contact_model = new waContactModel(); if ($contact_model->countAll()) { $this->redirect($this->getConfig()->getBackendUrl(true)); } if (($locale = waRequest::get('lang')) && waLocale::getInfo($locale)) { // set locale wa()->setLocale($locale); // save to database default locale $app_settings_model = new waAppSettingsModel(); $app_settings_model->set('webasyst', 'locale', $locale); } if (file_exists($this->getConfig()->getRootPath() . '/install.php')) { @unlink($this->getConfig()->getRootPath() . '/install.php'); } if (waRequest::getMethod() == 'post') { $errors = array(); $login = waRequest::post('login'); $validator = new waLoginValidator(); if (!$validator->isValid($login)) { $errors['login'] = implode("<br />", $validator->getErrors()); } $password = waRequest::post('password'); $password_confirm = waRequest::post('password_confirm'); if ($password !== $password_confirm) { $errors['password'] = _w('Passwords do not match'); } $email = waRequest::post('email'); $validator = new waEmailValidator(); if (!$validator->isValid($email)) { $errors['email'] = implode("<br />", $validator->getErrors()); } if ($errors) { $this->view->assign('errors', $errors); } else { // save account name $app_settings_model = new waAppSettingsModel(); $app_settings_model->set('webasyst', 'name', waRequest::post('account_name')); if ($email) { $app_settings_model->set('webasyst', 'email', $email); $app_settings_model->set('webasyst', 'sender', $email); } // create user $user = new waUser(); $firstname = waRequest::post('firstname'); $user['firstname'] = $firstname ? $firstname : $login; $user['lastname'] = waRequest::post('lastname'); $user['is_user'] = 1; $user['login'] = $login; $user['password'] = $password; $user['email'] = $email; $user['locale'] = wa()->getLocale(); $user['create_method'] = 'install'; if ($errors = $user->save()) { $result = array(); foreach ($errors as $k => $v) { $result['all'][] = $k . ": " . (is_array($v) ? implode(', ', $v) : $v); } $result['all'] = implode("\r\n", $result['all']); $this->view->assign('errors', $result); } else { $user->setRight('webasyst', 'backend', 1); waSystem::getInstance()->getAuth()->auth(array('login' => $login, 'password' => $password)); $path = $this->getConfig()->getPath('config'); // check routing.php if (!file_exists($path . '/routing.php')) { $apps = wa()->getApps(); $data = array(); $domain = $this->getConfig()->getDomain(); $site = false; foreach ($apps as $app_id => $app) { if ($app_id == 'site') { $site = true; } elseif (!empty($app['frontend'])) { $routing = array('url' => $app_id . '/*', 'app' => $app_id); if (!empty($app['routing_params']) && is_array($app['routing_params'])) { $routing = array_merge($routing, $app['routing_params']); } $data[$domain][] = $routing; } } if ($site) { $data[$domain][] = array('url' => '*', 'app' => 'site'); } waUtils::varExportToFile($data, $path . '/routing.php'); } // redirect to backend $this->redirect($this->getConfig()->getBackendUrl(true)); } } } }
/** * @param string $to * @param array $errors * @return bool */ public function sendEmail($to, &$errors) { if (!$to) { $app_settings_model = new waAppSettingsModel(); $to = $app_settings_model->get('webasyst', 'email'); } if (!$to) { $errors['all'] = _ws('Recipient (administrator) email is not valid'); return false; } if (!wa($this->app_id)->getCaptcha()->isValid()) { $errors['captcha'] = _ws('Invalid captcha'); } $email = $this->post('email'); $email_validator = new waEmailValidator(); $subject = trim($this->post('subject', _ws('Website request'))); $body = trim($this->post('body')); if (!$body) { $errors['body'] = _ws('Please define your request'); } if (!$email) { $errors['email'] = _ws('Email is required'); } elseif (!$email_validator->isValid($email)) { $errors['email'] = implode(', ', $email_validator->getErrors()); } if (!$errors) { $m = new waMailMessage($subject, nl2br($body)); $m->setTo($to); $m->setFrom(array($email => $this->post('name'))); if (!$m->send()) { $errors['all'] = _ws('An error occurred while attempting to send your request. Please try again in a minute.'); } else { return true; } } return false; }
public function validate($comment) { $errors = array(); if (empty($comment['auth_provider'])) { $comment['auth_provider'] = self::AUTH_GUEST; } switch ($comment['auth_provider']) { case self::AUTH_GUEST: if (!empty($comment['site']) && strpos($comment['site'], '://') === false) { $comment['site'] = "http://" . $comment['site']; } if (empty($comment['name']) || mb_strlen($comment['name']) == 0) { $errors[]['name'] = _w('Name can not be left blank'); } if (mb_strlen($comment['name']) > 255) { $errors[]['name'] = _w('Name length should not exceed 255 symbols'); } if (empty($comment['name']) || mb_strlen($comment['email']) == 0) { $errors[]['email'] = _w('Email can not be left blank'); } $validator = new waEmailValidator(); if (!$validator->isValid($comment['email'])) { $errors[]['email'] = _w('Email is not valid'); } $validator = new waUrlValidator(); if (!empty($comment['site']) && !$validator->isValid($comment['site'])) { $errors[]['site'] = _w('Site URL is not valid'); } break; case self::AUTH_USER: $user = wa()->getUser(); if ($user->getId() && !$user->get('is_user')) { $user->addToCategory(wa()->getApp()); } break; default: break; } if (mb_strlen($comment['text']) == 0) { $errors[]['text'] = _w('Comment text can not be left blank'); } if (mb_strlen($comment['text']) > 4096) { $errors[]['text'] = _w('Comment length should not exceed 4096 symbols'); } /** * @event comment_validate * @param array[string]mixed $data * @param array['plugin']['%plugin_id%']mixed plugin data * @return array['%plugin_id%']['field']string error */ $plugin_erros = wa()->event('comment_validate', $comment); if (is_array($plugin_erros)) { foreach ($plugin_erros as $plugin) { if ($plugin !== true) { if ($plugin) { $errors[] = $plugin; } else { $errors[]['text'] = _w('Invalid data'); } } } } return $errors; }
private function isValidEmail($email) { $email_validator = new waEmailValidator(array('required' => true), array('required' => _wp('Email is required'))); return $email_validator->isValid($email); }
public function sendEmail($to, &$errors) { if (!$to) { $to = waMail::getDefaultFrom(); } if (!$to) { $errors['all'] = 'Recipient (administrator) email is not valid'; return false; } if (!$this->wa->getCaptcha()->isValid()) { $errors['captcha'] = _ws('Invalid captcha'); } $email = $this->post('email'); $email_validator = new waEmailValidator(); $subject = trim($this->post('subject', 'Website request')); $body = trim($this->post('body')); if (!$body) { $errors['body'] = 'Please define your request'; } if (!$email_validator->isValid($email)) { $errors['email'] = implode(', ', $email_validator->getErrors()); } if (!$errors) { $m = new waMailMessage($subject, $body); $m->setTo($to); $m->setFrom(array($email => $this->post('name'))); if (!$m->send()) { $errors['all'] = 'An error occurred while attempting to send your request. Please try again in a minute.'; } else { return true; } } return false; }