From 5267cf3fbe9a6fb0ded6db43200fe433d508d1b8 Mon Sep 17 00:00:00 2001 From: bensonpaul Date: Wed, 26 Jun 2024 09:15:55 +0530 Subject: [PATCH] Added Google Captcha in the contact and register form --- config.toml | 3 + layouts/partials/footer-new.html | 3 + layouts/partials/header.html | 4 + layouts/partials/register.html | 2 + layouts/section/register.html | 1 + static/js/main-new.js | 202 +++++++++++++++---------------- 6 files changed, 108 insertions(+), 107 deletions(-) diff --git a/config.toml b/config.toml index d2990a4f..8337d186 100644 --- a/config.toml +++ b/config.toml @@ -19,6 +19,9 @@ unsafe = true Description = "The first-in-class comprehensive digital healthcare suite of patient advocacy tools for patients and consumers who are determined to be empowered in their health care journey. Unblock Health is revolutionizing patient autonomy and healthcare consumerism." logotitle ="Comprehensive Healthcare Suite of Patient Advocacy Services designed for Patients and Consumers - Unblock Health" footersectionaboutcontent ="Unblock Health rejects traditional barriers to patient health information. We empower patients to play an active role in their care and help HIM professionals deliver a positive experience." + recaptchaSiteKey = "6LfG8v8pAAAAAL_bNl24ICh0nOSe5Yx2GnXOmhVD" + recaptchaSecretKey = "6LfG8v8pAAAAAEgxJXOK7v0ko5Z-7HLPQ7f8DdfN" + recaptchaurl = "https://www.google.com/recaptcha/api.js" # Navigation [params.navigation] logo = "images/logo.png" diff --git a/layouts/partials/footer-new.html b/layouts/partials/footer-new.html index ef3d1d30..0954713c 100644 --- a/layouts/partials/footer-new.html +++ b/layouts/partials/footer-new.html @@ -177,6 +177,9 @@

+
+
+
diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 2efdfd6b..775210db 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -71,6 +71,10 @@ */}} {{/* */}} + + + + diff --git a/layouts/partials/register.html b/layouts/partials/register.html index 4e25d510..a190c2fc 100644 --- a/layouts/partials/register.html +++ b/layouts/partials/register.html @@ -36,6 +36,8 @@

{{ . }}

+
+
diff --git a/layouts/section/register.html b/layouts/section/register.html index f3e249a8..b265b5ee 100644 --- a/layouts/section/register.html +++ b/layouts/section/register.html @@ -37,6 +37,7 @@

{{ . }}

+
diff --git a/static/js/main-new.js b/static/js/main-new.js index e978ac4f..c3a8a3ea 100644 --- a/static/js/main-new.js +++ b/static/js/main-new.js @@ -259,116 +259,104 @@ $('#contact-submit-live').prop('disabled', 'disabled'); $('#contact-submit').click(function (e) { e.preventDefault(); - var uid = 0; - uid = uuidv4(); - var first_name = $('#quickname').val(); - var email = $('#quickemail').val(); - var subject = $('#quicksubject').val(); - var message = $('#quickmessage').val(); - var o = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i; - if (first_name == '') { - $('#quicknamealert').css('display', 'block'); - return false; - } - else { - $('#quicknamealert').css('display', 'none'); - } - if (email == '' || email.search(o) == -1) { - $('#quickemailalert').css('display', 'block'); - return false; - } - else { - $('#quickemailalert').css('display', 'none'); - } - if (subject == '') { - $('#quicksubjectalert').css('display', 'block'); - return false; - } - else { - $('#quicksubjectalert').css('display', 'none'); - } - if (message == '') { - $('#messagealert').css('display', 'block'); - return false; - } - else { - $('#messagealert').css('display', 'none'); - } - var description = 'Subject: '+subject; - //description += ' '; - description += '
'; - description += 'Message: '+message; - var form = new FormData(); - form.append("grant_type", "client_credentials"); - form.append("client_id", "2876ba3c-cae4-e1a5-7d8e-6673cf6a799f"); - form.append("client_secret", "ioDlA7#09yyM"); - var settings = { - "async": true, - "crossDomain": true, - "url": "https://uat.crm.unblock.health/legacy/Api/access_token", - "method": "POST", - "headers": { - "Accept": "application/vnd.api+json" - }, - "processData": false, - "contentType": false, - "mimeType": "multipart/form-data", - "data": form - } - - $.ajax(settings).done(function (response) { - - var obj = $.parseJSON(response); - var access_token = obj.access_token; - var settings = { - "url": "https://uat.crm.unblock.health/legacy/Api/V8/module", - "method": "POST", - "headers": { - "Accept": "application/vnd.api+json", - "Authorization": "Bearer " + access_token + "", - "Content-Type": "application/json" - }, - "processData": false, - "data": "{\r\n \"data\": {\r\n \"type\": \"Contacts\",\r\n \"id\": \"" + uid + "\",\r\n \"attributes\": {\r\n \"first_name\":\"" + first_name + "\",\r\n \"email1\":\"" + email + "\"\r\n,\r\n \"lead_source\":\"Web Site\"\r\n,\r\n \"title\":\"GEN\"\r\n,\r\n \"description\":\"" + description + "\"\r\n,\r\n \"account_id\":\"aba27ce2-d758-bdeb-adef-5da4294bf9e8\"\r\n }\r\n }\r\n}\r\n" - } - $.ajax(settings).done(function (response) { - //console.log(response.data.id); - if (response.data.id !='') { - $("#contactform").trigger("reset"); - var $success = $('#successfooter'); // get the reference of the div - $success.show().html('Your Message was sent successfully'); - + var recaptcha = $("#g-recaptcha-response").val(); + var $errorfooter = $('#errorfooter'); // get the reference of the div + if (recaptcha === "") { + $errorfooter.show().html('Recaptcha Error'); + return false; + } else { + var $success = $('#successfooter'); // get the reference of the div + $success.show().html('Your Message was sent successfully'); + /*var uid = uuidv4(); + var first_name = $('#quickname').val(); + var email = $('#quickemail').val(); + var subject = $('#quicksubject').val(); + var message = $('#quickmessage').val(); + var o = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i; + if (first_name == '') { + $('#quicknamealert').css('display', 'block'); + return false; + } else { + $('#quicknamealert').css('display', 'none'); } - }); - /*$.ajax(settings).done(function (response) { - //console.log(response); - var contactid = response.data.id; - var settings = { - "async": true, - "crossDomain": true, - "url": "https://uat.crm.unblock.health/legacy/Api/V8/module/Accounts/aba27ce2-d758-bdeb-adef-5da4294bf9e8/relationships", - "method": "POST", - "headers": { - "Accept": "application/vnd.api+json", - "Authorization": "Bearer " + access_token + "", - "Content-Type": "application/json" - }, - "processData": false, - "data": "{ \r\n \"data\":{ \r\n \"type\":\"Contacts\",\r\n \"id\":\"" + contactid + "\"\r\n\t \r\n }\r\n}" + if (email == '' || email.search(o) == -1) { + $('#quickemailalert').css('display', 'block'); + return false; + } else { + $('#quickemailalert').css('display', 'none'); } - + if (subject == '') { + $('#quicksubjectalert').css('display', 'block'); + return false; + } else { + $('#quicksubjectalert').css('display', 'none'); + } + if (message == '') { + $('#messagealert').css('display', 'block'); + return false; + } else { + $('#messagealert').css('display', 'none'); + } + + var description = 'Subject: ' + subject + '
' + 'Message: ' + message; + var form = new FormData(); + form.append("grant_type", "client_credentials"); + form.append("client_id", "2876ba3c-cae4-e1a5-7d8e-6673cf6a799f"); + form.append("client_secret", "ioDlA7#09yyM"); + + var settings = { + "async": true, + "crossDomain": true, + "url": "https://uat.crm.unblock.health/legacy/Api/access_token", + "method": "POST", + "headers": { + "Accept": "application/vnd.api+json" + }, + "processData": false, + "contentType": false, + "mimeType": "multipart/form-data", + "data": form + }; + $.ajax(settings).done(function (response) { - //console.log(response); - if (response.meta.message != "") { - $("#contactform").trigger("reset"); - var $success = $('#successfooter'); // get the reference of the div - $success.show().html('Your Message was sent successfully'); - - } - }); - });*/ - }); - }); + var obj = $.parseJSON(response); + var access_token = obj.access_token; + var settings = { + "url": "https://uat.crm.unblock.health/legacy/Api/V8/module", + "method": "POST", + "headers": { + "Accept": "application/vnd.api+json", + "Authorization": "Bearer " + access_token + "", + "Content-Type": "application/json" + }, + "processData": false, + "data": JSON.stringify({ + "data": { + "type": "Contacts", + "id": uid, + "attributes": { + "first_name": first_name, + "email1": email, + "lead_source": "Web Site", + "title": "GEN", + "description": description, + "account_id": "aba27ce2-d758-bdeb-adef-5da4294bf9e8" + } + } + }) + }; + + $.ajax(settings).done(function (response) { + if (response.data.id !== '') { + $("#contactform").trigger("reset"); + var $success = $('#successfooter'); // get the reference of the div + $success.show().html('Your Message was sent successfully'); + } + }); + });*/ + } +}); + $('#contact-submit').prop('disabled', 'disabled'); $('#contact-submit').addClass('is-disabled');