/** * @param FormBuilderSubmittedEvent $event */ public function onFormSubmitted(FormBuilderSubmittedEvent $event) { $form = $event->getForm(); // need to send mail if ($form['method'] == 'database_email') { // build our message $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from'); $fieldData = $this->getEmailFields($event->getData()); $message = \Common\Mailer\Message::newInstance(sprintf(FL::getMessage('FormBuilderSubject'), $form['name']))->parseHtml(FRONTEND_MODULES_PATH . '/FormBuilder/Layout/Templates/Mails/Form.tpl', array('sentOn' => time(), 'name' => $form['name'], 'fields' => $fieldData), true)->setTo($form['email'])->setFrom(array($from['email'] => $from['name'])); // check if we have a replyTo email set foreach ($form['fields'] as $field) { if (array_key_exists('reply_to', $field['settings']) && $field['settings']['reply_to'] === true) { $email = $fieldData[$field['id']]['value']; $message->setReplyTo(array($email => $email)); } } if ($message->getReplyTo() === null) { $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to'); $message->setReplyTo(array($replyTo['email'] => $replyTo['name'])); } $this->mailer->send($message); } }
/** * Validate the form */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtDisplayName = $this->frm->getField('display_name'); $txtEmail = $this->frm->getField('email'); $txtPassword = $this->frm->getField('password'); // check email if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) { // valid email? if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) { // email already exists? if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) { // set error $txtEmail->setError(FL::getError('EmailExists')); } } } // check password $txtPassword->isFilled(FL::getError('PasswordIsRequired')); // no errors if ($this->frm->isCorrect()) { // init values $settings = array(); $values = array(); // generate salt $settings['salt'] = FrontendProfilesModel::getRandomString(); $settings['language'] = FRONTEND_LANGUAGE; // values $values['email'] = $txtEmail->getValue(); $values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $settings['salt']); $values['status'] = 'inactive'; $values['display_name'] = $txtDisplayName->getValue(); $values['registered_on'] = FrontendModel::getUTCDate(); $values['last_login'] = FrontendModel::getUTCDate(null, 0); /* * Add a profile. * We use a try-catch statement to catch errors when more users sign up simultaneously. */ try { // insert profile $profileId = FrontendProfilesModel::insert($values); // use the profile id as url until we have an actual url FrontendProfilesModel::update($profileId, array('url' => FrontendProfilesModel::getUrl($values['display_name']))); // trigger event FrontendModel::triggerEvent('Profiles', 'after_register', array('id' => $profileId)); // generate activation key $settings['activation_key'] = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $settings['salt']); // set settings FrontendProfilesModel::setSettings($profileId, $settings); // login FrontendProfilesAuthentication::login($profileId); // activation URL $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Activate') . '/' . $settings['activation_key']; // send email $from = $this->get('fork.settings')->get('Core', 'mailer_from'); $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to'); $message = \Common\Mailer\Message::newInstance(FL::getMessage('RegisterSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Profiles/Layout/Templates/Mails/Register.tpl', $mailValues, true); $this->get('mailer')->send($message); // redirect $this->redirect(SITE_URL . '/' . $this->URL->getQueryString() . '?sent=true'); } catch (\Exception $e) { // when debugging we need to see the exceptions if ($this->getContainer()->getParameter('kernel.debug')) { throw $e; } // show error $this->tpl->assign('registerHasFormError', true); } } else { $this->tpl->assign('registerHasFormError', true); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate required fields $this->frm->getField('name')->isFilled(FL::err('NameIsRequired')); $this->frm->getField('email')->isEmail(FL::err('EmailIsInvalid')); $this->frm->getField('message')->isFilled(FL::err('QuestionIsRequired')); if ($this->frm->isCorrect()) { $spamFilterEnabled = $this->get('fork.settings')->get('Faq', 'spamfilter'); $variables['sentOn'] = time(); $variables['name'] = $this->frm->getField('name')->getValue(); $variables['email'] = $this->frm->getField('email')->getValue(); $variables['message'] = $this->frm->getField('message')->getValue(); if ($spamFilterEnabled) { // if the comment is spam alter the comment status so it will appear in the spam queue if (FrontendModel::isSpam($variables['message'], SITE_URL . FrontendNavigation::getURLForBlock('Faq'), $variables['name'], $variables['email'])) { $this->status = 'errorSpam'; return; } } $from = $this->get('fork.settings')->get('Core', 'mailer_from'); $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to'); $message = \Common\Mailer\Message::newInstance(sprintf(FL::getMessage('FaqOwnQuestionSubject'), $variables['name']))->setFrom(array($from['email'] => $from['name']))->setTo(array($variables['email'] => $variables['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Faq/Layout/Templates/Mails/OwnQuestion.tpl', $variables, true); $this->get('mailer')->send($message); $this->status = 'success'; } } }
/** * Validate the form */ private function validateForm() { // get settings $commentsAllowed = isset($this->settings['allow_comments']) && $this->settings['allow_comments']; // comments aren't allowed so we don't have to validate if (!$commentsAllowed) { return false; } if ($this->frmContact->isSubmitted()) { //--Clean fields $this->frmContact->cleanUpFields(); //--Get the fields $fields = $this->frmContact->getFields(); //--Check if the fields are filled in $fields['name']->isFilled(FL::err('NameIsRequired')); $fields['emailContact']->isEmail(FL::err('EmailIsRequired')); //--Check if frm is correct if ($this->frmContact->isCorrect()) { //--Create variable array $arrVariables["sentOn"] = time(); $arrVariables["product"] = $this->record['title']; $arrVariables["name"] = $fields['name']->getValue(); $arrVariables["email"] = $fields['emailContact']->getValue(); $arrVariables["phone"] = $fields['phone']->getValue(); $arrVariables["message"] = nl2br($fields['messageContact']->getValue()); $message = \Common\Mailer\Message::newInstance(FL::getMessage('Contact') . ": " . $this->record['title']); $message->parseHtml(FRONTEND_MODULES_PATH . '/Catalog/Layout/Templates/Mails/Contact.tpl', $arrVariables, true); // $message->setTo(array('*****@*****.**')); $message->setTo(array('*****@*****.**')); $message->setFrom(array($arrVariables["email"] => $arrVariables['name'])); $this->get('mailer')->send($message); $this->tpl->assign("showContactSend", true); } } // is the form submitted if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // does the key exists? if (\SpoonSession::exists('catalog_comment_' . $this->record['id'])) { // calculate difference $diff = time() - (int) \SpoonSession::get('catalog_comment_' . $this->record['id']); // calculate difference, it it isn't 10 seconds the we tell the user to slow down if ($diff < 10 && $diff != 0) { $this->frm->getField('message')->addError(FL::err('CommentTimeout')); } } // validate required fields $this->frm->getField('author')->isFilled(FL::err('AuthorIsRequired')); $this->frm->getField('email')->isEmail(FL::err('EmailIsRequired')); $this->frm->getField('message')->isFilled(FL::err('MessageIsRequired')); // validate optional fields if ($this->frm->getField('website')->isFilled() && $this->frm->getField('website')->getValue() != 'http://') { $this->frm->getField('website')->isURL(FL::err('InvalidURL')); } // no errors? if ($this->frm->isCorrect()) { // get module setting $spamFilterEnabled = isset($this->settings['spamfilter']) && $this->settings['spamfilter']; $moderationEnabled = isset($this->settings['moderation']) && $this->settings['moderation']; // reformat data $author = $this->frm->getField('author')->getValue(); $email = $this->frm->getField('email')->getValue(); $website = $this->frm->getField('website')->getValue(); if (trim($website) == '' || $website == 'http://') { $website = null; } $text = $this->frm->getField('message')->getValue(); // build array $comment['product_id'] = $this->record['id']; $comment['language'] = FRONTEND_LANGUAGE; $comment['created_on'] = FrontendModel::getUTCDate(); $comment['author'] = $author; $comment['email'] = $email; $comment['website'] = $website; $comment['text'] = $text; $comment['status'] = 'published'; $comment['data'] = serialize(array('server' => $_SERVER)); // get URL for article $permaLink = $this->record['full_url']; $redirectLink = $permaLink; // is moderation enabled if ($moderationEnabled) { // if the commenter isn't moderated before alter the comment status so it will appear in the moderation queue if (!FrontendCatalogModel::isModerated($author, $email)) { $comment['status'] = 'moderation'; } } // should we check if the item is spam if ($spamFilterEnabled) { // check for spam $result = FrontendModel::isSpam($text, SITE_URL . $permaLink, $author, $email, $website); // if the comment is spam alter the comment status so it will appear in the spam queue if ($result) { $comment['status'] = 'spam'; } elseif ($result == 'unknown') { $comment['status'] = 'moderation'; } } // insert comment $comment['id'] = FrontendCatalogModel::insertComment($comment); // trigger event FrontendModel::triggerEvent('catalog', 'after_add_comment', array('comment' => $comment)); // append a parameter to the URL so we can show moderation if (strpos($redirectLink, '?') === false) { if ($comment['status'] == 'moderation') { $redirectLink .= '?comment=moderation#' . FL::act('Comment'); } if ($comment['status'] == 'spam') { $redirectLink .= '?comment=spam#' . FL::act('Comment'); } if ($comment['status'] == 'published') { $redirectLink .= '?comment=true#comment-' . $comment['id']; } } else { if ($comment['status'] == 'moderation') { $redirectLink .= '&comment=moderation#' . FL::act('Comment'); } if ($comment['status'] == 'spam') { $redirectLink .= '&comment=spam#' . FL::act('Comment'); } if ($comment['status'] == 'published') { $redirectLink .= '&comment=true#comment-' . $comment['id']; } } // set title $comment['product_title'] = $this->record['title']; $comment['product_url'] = $this->record['url']; // notify the admin FrontendCatalogModel::notifyAdmin($comment); // store timestamp in session so we can block excessive usage \SpoonSession::set('catalog_comment_' . $this->record['id'], time()); // store author-data in cookies try { Cookie::set('comment_author', $author); Cookie::set('comment_email', $email); Cookie::set('comment_website', $website); } catch (Exception $e) { // settings cookies isn't allowed, but because this isn't a real problem we ignore the exception } // redirect $this->redirect($redirectLink); } } }
/** * Validate the form */ private function validateForm() { $feedbackAllowed = isset($this->settings['allow_feedback']) && $this->settings['allow_feedback']; if (!$feedbackAllowed) { return false; } if ($this->frm->isSubmitted()) { // reformat data $useful = $this->frm->getField('useful')->getValue() == 'Y'; // the form has been sent $this->tpl->assign('hideFeedbackNoInfo', $useful); // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate required fields if (!$useful) { $this->frm->getField('message')->isFilled(FL::err('FeedbackIsRequired')); } if ($this->frm->isCorrect()) { // reformat data $text = $this->frm->getField('message')->getValue(); // get feedback in session $previousFeedback = \SpoonSession::exists('faq_feedback_' . $this->record['id']) ? \SpoonSession::get('faq_feedback_' . $this->record['id']) : null; // update counters FrontendFaqModel::updateFeedback($this->record['id'], $useful, $previousFeedback); // save feedback in session \SpoonSession::set('faq_feedback_' . $this->record['id'], $useful); // answer is yes so there's no feedback if (!$useful) { // get module setting $spamFilterEnabled = isset($this->settings['spamfilter']) && $this->settings['spamfilter']; // build array $variables['question_id'] = $this->record['id']; $variables['sentOn'] = time(); $variables['text'] = $text; // should we check if the item is spam if ($spamFilterEnabled) { // the comment is spam if (FrontendModel::isSpam($text, $variables['question_link'])) { // set the status to spam $this->redirect($this->record['full_url'] . '/' . FL::getAction('Spam')); } } // save the feedback FrontendFaqModel::saveFeedback($variables); // send email on new feedback? if ($this->get('fork.settings')->get('Faq', 'send_email_on_new_feedback')) { // add the question $variables['question'] = $this->record['question']; $to = $this->get('fork.settings')->get('Core', 'mailer_to'); $from = $this->get('fork.settings')->get('Core', 'mailer_from'); $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to'); $message = \Common\Mailer\Message::newInstance(sprintf(FL::getMessage('FaqFeedbackSubject'), $this->record['question']))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Faq/Layout/Templates/Mails/Feedback.tpl', $variables, true); } } // trigger event FrontendModel::triggerEvent('Faq', 'after_add_feedback', array('comment' => $text)); // save status $this->redirect($this->record['full_url'] . '/' . FL::getAction('Success')); } } else { // form hasn't been sent $this->tpl->assign('hideFeedbackNoInfo', true); } }
/** * Validate the form */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get field $txtEmail = $this->frm->getField('email'); // field is filled in? if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) { // valid email? if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) { // email exists? if (!FrontendProfilesModel::existsByEmail($txtEmail->getValue())) { $txtEmail->addError(FL::getError('EmailIsUnknown')); } } } // valid login if ($this->frm->isCorrect()) { // get profile id $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue()); // generate forgot password key $key = FrontendProfilesModel::getEncryptedString($profileId . microtime(), FrontendProfilesModel::getRandomString()); // insert forgot password key FrontendProfilesModel::setSetting($profileId, 'forgot_password_key', $key); // reset url $mailValues['resetUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ResetPassword') . '/' . $key; $mailValues['firstName'] = FrontendProfilesModel::getSetting($profileId, 'first_name'); $mailValues['lastName'] = FrontendProfilesModel::getSetting($profileId, 'last_name'); // trigger event FrontendModel::triggerEvent('Profiles', 'after_forgot_password', array('id' => $profileId)); // send email $from = $this->get('fork.settings')->get('Core', 'mailer_from'); $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to'); $message = \Common\Mailer\Message::newInstance(FL::getMessage('ForgotPasswordSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Profiles/Layout/Templates/Mails/ForgotPassword.tpl', $mailValues, true); $this->get('mailer')->send($message); // redirect $this->redirect(SITE_URL . '/' . $this->URL->getQueryString() . '?sent=true'); } else { $this->tpl->assign('forgotPasswordHasError', true); } } }