Add are you a human to visualforce pages. You can check out a live demo here.
- Install
Ayah.cls
into your Salesforce Org - Under Setup->Remote Site Settings, add https://ws.areyouahuman.com
Initialize an Ayah object with your publisher key
and your scoring key
Ayah myAyah = new Ayah('mypublisherkey', 'myscoringkey');
Calling getPublisherHtml
will generate the html you need to drop into a page. You can do this in an apex:outputText
with escape="false"
<apex:outputText value="{!myAyah.publisherHtml}" escape="false" />
Then, in your controller, get the session_secret
parameter value. This is what we need to send to the service to check if the PlayThru was successful. Call the getScore
method with the session_secret
to see if we are successful or not.
public PageReference checkUserScore() {
String sessionSecret = ApexPages.currentPage().getParameters().get('session_secret');
if(sessionSecret == null) {
addError('No session secret found');
return null;
}
// call the getScore method to see if the PlayThru was successful
if(ayah.getScore(sessionSecret)) {
addInfo('Congrats! You are a human!');
} else {
addError('Sorry, you are not a human!');
}
return null;
}
The demo files used are also included in this repo.