diff --git a/src/mibew/js/source/features.js b/src/mibew/js/source/features.js index b6df4aab..46354560 100644 --- a/src/mibew/js/source/features.js +++ b/src/mibew/js/source/features.js @@ -17,6 +17,14 @@ */ (function($) { + function updateSendEmail() { + if ($("#user-can-send-email").is(":checked")) { + $(".under-user-can-send-email").show(); + } else { + $(".under-user-can-send-email").hide(); + } + } + function updateSurvey() { if ($("#enable-presurvey").is(":checked")) { $(".under-survey").show(); @@ -58,6 +66,9 @@ } $(function() { + $("#user-can-send-email").change(function() { + updateSendEmail(); + }); $("#enable-presurvey").change(function() { updateSurvey(); }); @@ -73,6 +84,7 @@ $("#enable-privacy-policy").change(function() { updatePrivacyPolicy(); }); + updateSendEmail(); updateSurvey(); updateSSL(); updateGroups(); diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/MailController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/MailController.php index 8216798c..4c741f57 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/MailController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/MailController.php @@ -52,6 +52,8 @@ class MailController extends AbstractController // Use errors list stored in the request. We need to do so to have // an ability to pass the request from the "submitForm" action. 'errors' => $request->attributes->get('errors', array()), + // Setup CAPTCHA if needed + 'showCaptcha' => Settings::get('enableemailcaptcha'), ); $thread_id = $request->attributes->get('thread_id'); @@ -113,14 +115,26 @@ class MailController extends AbstractController throw new NotFoundException('The thread is not found.'); } + // Check email $email = $request->request->get('email'); - $group = $thread->groupId ? group_by_id($thread->groupId) : null; if (!$email) { $errors[] = no_field('Your email'); } elseif (!MailUtils::isValidAddress($email)) { $errors[] = wrong_field('Your email'); } + // Check captcha + if (Settings::get('enableemailcaptcha') == '1' && can_show_captcha()) { + $captcha = $request->request->get('captcha'); + $original = isset($_SESSION[SESSION_PREFIX . 'mibew_captcha']) + ? $_SESSION[SESSION_PREFIX . 'mibew_captcha'] + : ''; + unset($_SESSION[SESSION_PREFIX . 'mibew_captcha']); + if (empty($original) || empty($captcha) || $captcha != $original) { + $errors[] = 'The letters you typed don\'t match the letters that were shown in the picture.'; + } + } + if (count($errors) > 0) { $request->attributes->set('errors', $errors); @@ -156,6 +170,7 @@ class MailController extends AbstractController ); } + $group = $thread->groupId ? group_by_id($thread->groupId) : null; $page = setup_logo($group); $page['email'] = $email; diff --git a/src/mibew/libs/classes/Mibew/Controller/Settings/FeaturesController.php b/src/mibew/libs/classes/Mibew/Controller/Settings/FeaturesController.php index 640d211f..0e84574a 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Settings/FeaturesController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Settings/FeaturesController.php @@ -117,6 +117,7 @@ class FeaturesController extends AbstractController 'enableban', 'usercanchangename', 'usercansendemail', + 'enableemailcaptcha', 'enablegroups', 'enablegroupsisolation', 'enablestatistics', diff --git a/src/mibew/libs/classes/Mibew/Settings.php b/src/mibew/libs/classes/Mibew/Settings.php index f264dd91..dc92b51b 100644 --- a/src/mibew/libs/classes/Mibew/Settings.php +++ b/src/mibew/libs/classes/Mibew/Settings.php @@ -87,6 +87,7 @@ class Settings 'forcessl' => '0', 'usercanchangename' => '1', 'usercansendemail' => '1', + 'enableemailcaptcha' => '0', 'enablegroups' => '0', 'enablegroupsisolation' => '0', 'enablestatistics' => '1', diff --git a/src/mibew/styles/chats/dark/templates_src/server_side/mail.handlebars b/src/mibew/styles/chats/dark/templates_src/server_side/mail.handlebars index afa53ad6..0ce3ac95 100644 --- a/src/mibew/styles/chats/dark/templates_src/server_side/mail.handlebars +++ b/src/mibew/styles/chats/dark/templates_src/server_side/mail.handlebars @@ -14,6 +14,14 @@ {{l10n "Enter your email:"}} + + {{#if showCaptcha}} +