Compare commits

...

4 Commits

Author SHA1 Message Date
Isaac Vallee
d162ce8ed6 Update folder structure & remove unecessary redundant directory 2021-12-22 13:39:34 -08:00
Isaac Vallee
ade208263e Merge branch 'master' of http://24.121.68.9:3333/max/LearningSalesForceCommerceCloud 2021-12-22 10:32:44 -08:00
Isaac Vallee
91355f8903 Properly extends ContactUs controller 2021-12-22 10:20:13 -08:00
Isaac Vallee
8a0742d9a8 change append to prepend 2021-12-22 10:05:38 -08:00
6 changed files with 15 additions and 4 deletions

View File

@ -1,9 +1,15 @@
'use strict';
var base = module.superModule;
var server = require('server');
server.extend(base);
// First, let's extend the ContactUs-Landing route
// to add recaptcha data to the template view
server.append('Landing', function(req, res, next) {
res.setViewData({
// Recaptcha API script URL
recaptchaUrl: 'https://www.google.com/recaptcha/api.js',
siteKey: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' // Test Site Key from Google
});
@ -11,21 +17,26 @@ server.append('Landing', function(req, res, next) {
next();
});
server.append('Subscribe', function(req, res, next) {
// Now we need to extend ContactUs-Subscribe, to add our logic
// that invokes the recaptcha service
// We prepend here to ensure that an invalid response is caught before the email is sent
server.prepend('Subscribe', function(req, res, next) {
var recaptchaService = require('*/cartridge/scripts/services/recaptcha');
// Token automatically added to request by recaptcha
var token = req.form['g-recaptcha-response'];
// Add required parameters for validation call
var params = {
// This is a test secret from Google
// In practice, do not hardcode this. It's better to store
// In a custom preference or service credential Configuration
secret: '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe', // Test secret key from Google
// In practice, do not hardcode this.
// It's better to store in a custom preference or service credential configuration
secret: '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe',
response: token
};
// Calls recaptcha service
// Returns a Service class instance
// (start with a hardcoded fail)
var validationResult = recaptchaService.call(params);
// Actual response from Google