Commit 0d9bc40a authored by Simon's avatar Simon

Email send to vilniuscv if blocked

parent 72e23f8a
......@@ -256,10 +256,14 @@ class Biuro_Contacts_Public {
return '';
}
public static function isCaptchaValid($code, $name = '') {
// public static function isCaptchaValid($code, $name = '') {
public static function isCaptchaValid($post) {
$code = $post['captcha'] ? $post['captcha'] : '';
$name = $post['name'] ? $post['name'] : '';
if ($code) {
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Lc76qoUAAAAAHfGWVZFEzFeYAVpCkhDSoMYvVUi&response=".$code."&remoteip=".$_SERVER['REMOTE_ADDR']);
$response = json_decode($response,true);
$response = json_decode($response, true);
if ( !$response['success'] || $response['score'] < 0.5 ) {
......@@ -282,6 +286,8 @@ class Biuro_Contacts_Public {
fwrite($handle, $content);
fclose($handle);
static::sendBlockedEmail( static::emailBlockedContent($post, true, $response) );
return false;
}
......@@ -294,6 +300,8 @@ class Biuro_Contacts_Public {
fwrite($handle, $content);
fclose($handle);
static::sendBlockedEmail( static::emailBlockedContent($post, false) );
return false;
}
......@@ -376,7 +384,7 @@ class Biuro_Contacts_Public {
$_SESSION[$str . '--' . $key . '-message'] = $validation['message'];
}
if ($canSubmit && !static::isCaptchaValid($_POST['captcha'], $_POST['name'])) {
if ($canSubmit && !static::isCaptchaValid($_POST)) {
$_SESSION[$str . '--captcha-status'] = 'error';
wp_redirect( $referer );
exit;
......@@ -397,7 +405,7 @@ class Biuro_Contacts_Public {
elseif ($_POST['s'] == "2" && $_SESSION['employees--id']):
if (!static::isCaptchaValid($_POST['captcha'])) {
if (!static::isCaptchaValid($_POST)) {
$_SESSION[$str . '--captcha-status'] = 'error';
wp_redirect( $referer );
exit;
......@@ -534,7 +542,7 @@ class Biuro_Contacts_Public {
$_SESSION[$str . '--' . $key . '-message'] = $validation['message'];
}
if ($canSubmit && !static::isCaptchaValid($_POST['captcha'], $_POST['name'])) {
if ($canSubmit && !static::isCaptchaValid($_POST)) {
$_SESSION[$str . '--captcha-status'] = 'error';
wp_redirect( $referer );
exit;
......@@ -564,7 +572,7 @@ class Biuro_Contacts_Public {
elseif ($_POST['s'] == "2"):
if (!static::isCaptchaValid($_POST['captcha'])) {
if (!static::isCaptchaValid($_POST)) {
$_SESSION[$str . '--captcha-status'] = 'error';
wp_redirect( $referer );
exit;
......@@ -703,6 +711,20 @@ class Biuro_Contacts_Public {
return json_decode($return, true);
}
public static function sendBlockedEmail($message) {
$to = 'vilniuscv@biuro.lt';
$subject = 'Biuro blocked contact form';
$headers = "From: Biuro <no-reply@biuro.lt>" . "\r\n";
try {
wp_mail( $to, $subject, $message, $headers );
} catch (Exception $e) {
debug($e);
}
}
public static function sendEmail($message, $name) {
$to = 'pardavimai@biuro.lt';
......@@ -715,7 +737,48 @@ class Biuro_Contacts_Public {
} catch (Exception $e) {
debug($e);
}
}
public static function emailBlockedContent($post, $captcha, $response = array()) {
$message = '';
$message .= 'Date: ' . date('Y-m-d H:i:s') . "\r\n";
$message .= 'Website: ' . $_SERVER['SERVER_NAME'] . "\r\n";
$message .= 'Location: ' . $_SERVER['HTTP_REFERER'] . "\r\n" . "\r\n";
$message .= 'Name: ' . $post['name'] . "\r\n";
$message .= 'Phone: ' . $post['phone'] . "\r\n";
$message .= 'Email: ' . $post['email'] . "\r\n";
if ($post['city']):
$message .= 'City: ' . $post['city'] . "\r\n";
endif;
if ($post['company']):
$message .= 'Company: ' . $post['company'] . "\r\n";
endif;
if ($post['message']):
$message .= 'Message: ' . $post['message'] . "\r\n";
endif;
$message .= "\r\n";
if ($captcha):
if (isset($response['error-codes']) && is_array($response['error-codes']) && !empty($response['error-codes'])):
$message .= 'Error codes:';
foreach ($response['error-codes'] as &$code) :
$message .= ' ' . $code;
endforeach;
$message .= "\r\n";
endif;
else:
$message .= 'Reason: No recaptcha code' . "\r\n";
endif;
return $message;
}
public static function emailContent($firstName, $lastName, $phone, $email, $organization = null, $comment = null) {
......@@ -817,7 +880,7 @@ class Biuro_Contacts_Public {
$_SESSION[$str . '--' . $key . '-message'] = $validation['message'];
}
if ($canSubmit && !static::isCaptchaValid($_POST['captcha'], $_POST['name'])) {
if ($canSubmit && !static::isCaptchaValid($_POST)) {
$_SESSION[$str . '--captcha-status'] = 'error';
wp_redirect( $referer );
exit;
......
......@@ -15,3 +15,4 @@ a.k.a. Base, unclassed html elements, e.g. headings, lists, tables, this is the
@import '_element--paragraph.css';
@import '_element--strong.css';
@import '_element--table.css';
@import '_element--textarea.css';
/* ------------- Elements: textarea ------------- */
textarea { resize: vertical; }
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -63,7 +63,7 @@
/******/
/******/ var hotApplyOnUpdate = true;
/******/ // eslint-disable-next-line no-unused-vars
/******/ var hotCurrentHash = "6ba16587ff77a3dfa1af";
/******/ var hotCurrentHash = "0c2459a27894265c6149";
/******/ var hotRequestTimeout = 10000;
/******/ var hotCurrentModuleData = {};
/******/ var hotCurrentChildModule;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment