Skip to content

Commit

Permalink
Dev: Factor out testCaptcha()
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 30, 2016
1 parent a21598e commit bf0a34d
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions application/helpers/frontend_helper.php
Expand Up @@ -974,27 +974,12 @@ function buildsurveysession($surveyid,$preview=false)
$aEnterTokenData['sLoadpass'] = htmlspecialchars($loadpass);
}


$FlashError = "";

// Scenario => Captcha required
if($scenarios['captchaRequired'] && !$preview)
{
//Apply the captchaEnabled flag to the partial
$aEnterTokenData['bCaptchaEnabled'] = true;
// IF CAPTCHA ANSWER IS NOT CORRECT OR NOT SET
if (!$subscenarios['captchaCorrect'])
{
if (isset($loadsecurity))
{ // was a bad answer
$FlashError.=gT("Your answer to the security question was not correct - please try again.")."<br/>\n";
}
$renderCaptcha='main';
}
else{
$_SESSION['survey_'.$surveyid]['captcha_surveyaccessscreen']=true;
$renderCaptcha='correct';
}
list($renderCaptcha, $FlashError) = testCaptcha($aEnterTokenData, $subscenarios, $surveyid);
}
// Scenario => Token required
if ($scenarios['tokenRequired'] && !$preview){
Expand Down Expand Up @@ -1451,6 +1436,35 @@ function buildsurveysession($surveyid,$preview=false)
Yii::trace('end', 'survey.buildsurveysession');
}

/**
* @param array $aEnterTokenData
* @param array $subscenarios
* @param int $surveyid
* @return array ($renderCaptcha, $FlashError)
*/
function testCaptcha(array $aEnterTokenData, array $subscenarios, $surveyid)
{
$FlashError = '';

//Apply the captchaEnabled flag to the partial
$aEnterTokenData['bCaptchaEnabled'] = true;
// IF CAPTCHA ANSWER IS NOT CORRECT OR NOT SET
if (!$subscenarios['captchaCorrect'])
{
if (isset($loadsecurity))
{ // was a bad answer
$FlashError.=gT("Your answer to the security question was not correct - please try again.")."<br/>\n";
}
$renderCaptcha='main';
}
else{
$_SESSION['survey_'.$surveyid]['captcha_surveyaccessscreen']=true;
$renderCaptcha='correct';
}

return array ($renderCaptcha, $FlashError);
}

/**
* Test if token is valid
* @param array $subscenarios
Expand Down

0 comments on commit bf0a34d

Please sign in to comment.