/** * 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; }
/** * @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 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)); } } } }
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; }