Verified Commit 2220541a authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(public-forms) Add support for captcha using securimage

Path needs to be specified in the configuration.
Only works if installed in html/ for now, maybe we’ll have to add an
 second configuration option for the base URI.
Captcha validation does not seem to work, maybe a session problem.
CSS or smarty template will need to be adapted, the captcha image is not
 aligned correctly.

issue #6001
Showing with 54 additions and 2 deletions
+54 -2
......@@ -90,6 +90,11 @@ class publicForm extends simplePlugin
_('TOS URL'), _('Terms of service URL. If filled, this adds a mandatory checkbox to agree to the terms at this URL.'),
'fdPublicFormTosUrl', FALSE
),
new BooleanAttribute(
_('Captcha'), _('Add a captcha to the form'),
'fdPublicFormCaptcha', FALSE,
FALSE
),
]
],
];
......@@ -97,6 +102,8 @@ class publicForm extends simplePlugin
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE, $attributesInfo = NULL)
{
global $config;
if ($attributesInfo === NULL) {
$attributesInfo = $this->getAttributesInfo();
}
......@@ -111,6 +118,12 @@ class publicForm extends simplePlugin
$this->typeChanged();
$this->attributesAccess['fdPublicFormTemplateType']->setSubmitForm('typeChanged');
if ($config->get_cfg_value('PublicFormSecurimagePath', '') == '') {
$this->attributesAccess['fdPublicFormCaptcha']->setDisabled(TRUE);
$this->attributesAccess['fdPublicFormCaptcha']->setValue(FALSE);
$this->attributesAccess['fdPublicFormCaptcha']->setVisible(FALSE);
}
}
function typeChanged ()
......
......@@ -44,6 +44,10 @@ class publicFormsConfig extends simplePlugin
'fdPublicFormRDN', TRUE,
'ou=forms'
),
new StringAttribute(
_('Securimage path'), _('If you wish to use captchas in your forms, you need to install securimage'),
'fdPublicFormSecurimagePath', FALSE
),
]
],
];
......
......@@ -10,9 +10,16 @@ attributetype ( 1.3.6.1.4.1.38414.68.1.1 NAME 'fdPublicFormRDN'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE)
attributetype ( 1.3.6.1.4.1.38414.68.1.2 NAME 'fdPublicFormSecurimagePath'
DESC 'FusionDirectory - Public forms securimage path'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE)
# Object Class
objectclass ( 1.3.6.1.4.1.38414.68.2.1 NAME 'fdPublicFormsPluginConf'
DESC 'FusionDirectory - Public forms plugin configuration'
SUP top AUXILIARY
MUST ( cn )
MAY ( fdPublicFormRDN ) )
MAY ( fdPublicFormRDN $ fdPublicFormSecurimagePath ) )
......@@ -66,6 +66,12 @@ attributetype ( 1.3.6.1.4.1.38414.67.10.9 NAME 'fdPublicFormTosUrl'
SUBSTR caseExactSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
attributetype ( 1.3.6.1.4.1.38414.67.10.10 NAME 'fdPublicFormCaptcha'
DESC 'FusionDirectory - Whether this form should contain a captcha'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE )
# Objectclasses
objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm'
......@@ -75,4 +81,4 @@ objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm'
fdPublicFormTitle $ fdPublicFormText $
fdPublicFormTemplateType $ fdPublicFormTemplateDN $
fdPublicFormFinalText $ fdPublicFormPrivate $ fdPublicFormCreationBase $
fdPublicFormAlteredAttributes $ fdPublicFormTosUrl ) )
fdPublicFormAlteredAttributes $ fdPublicFormTosUrl $ fdPublicFormCaptcha ) )
......@@ -35,6 +35,9 @@
{if (!$done and $form.fdPublicFormTosUrl)}
<label for="tosCheckBox"><input type="checkbox" id="tosCheckBox" name="tosCheckBox"/> {t 1=$form.fdPublicFormTosUrl escape=no}I agree to the <a target="_blank" href="%1">terms of service</a>{/t}</label>
{/if}
{if (!$done and $captcha)}
{$captcha}
{/if}
</div>
{if !$done}
<div id="window-footer" class="plugbottom">
......
......@@ -120,6 +120,7 @@ class publicFormPage extends standAlonePage
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1,
'fdPublicFormTosUrl' => 1,
'fdPublicFormCaptcha' => 1,
'fdPublicFormAlteredAttributes' => '*',
],
$this->invitation['fdInvitationFormDN'],
......@@ -141,6 +142,7 @@ class publicFormPage extends standAlonePage
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1,
'fdPublicFormTosUrl' => 1,
'fdPublicFormCaptcha' => 1,
'fdPublicFormAlteredAttributes' => '*',
],
NULL,
......@@ -219,6 +221,16 @@ class publicFormPage extends standAlonePage
{
global $config, $ui;
/* Check Captcha */
if (isset($this->form['fdPublicFormCaptcha']) && ($this->form['fdPublicFormCaptcha'] == 'TRUE')) {
require_once($config->get_cfg_value('PublicFormSecurimagePath'));
$securimage = new Securimage();
if (!$securimage->check($_POST['captcha_code'])) {
msg_dialog::display(_('Error'), _('Captcha code was wrong!'), ERROR_DIALOG);
return;
}
}
/* Check TOS checkbox */
if (isset($this->form['fdPublicFormTosUrl']) && !isset($_POST['tosCheckBox'])) {
msg_dialog::display(_('Error'), _('You need to accept the terms of service to continue!'), ERROR_DIALOG);
......@@ -307,6 +319,8 @@ class publicFormPage extends standAlonePage
function execute ()
{
global $config;
if (!$this->activated) {
return;
}
......@@ -321,6 +335,11 @@ class publicFormPage extends standAlonePage
$templateOutput = $this->template->execute();
// TODO - Check that no dialogs are opened?
$smarty->assign('template_dialog', $templateOutput);
if (isset($this->form['fdPublicFormCaptcha']) && ($this->form['fdPublicFormCaptcha'] == 'TRUE')) {
require_once($config->get_cfg_value('PublicFormSecurimagePath'));
$smarty->assign('captcha', Securimage::getCaptchaHtml(['securimage_path' => 'securimage/']));
}
}
$smarty->assign('done', $this->done);
......
Supports Markdown
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