mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
WIP Captcha architecture
This commit is contained in:
parent
dc505909fa
commit
0e55db7caf
|
|
@ -91,11 +91,7 @@ print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
|
|||
print '<span class="opacitymedium">'.$langs->trans("CaptchaDesc")."</span><br>\n";
|
||||
print "<br>\n";
|
||||
|
||||
$dirModCaptcha = array_merge(array('/core/modules/security/captcha'), is_array($conf->modules_parts['captcha']) ? $conf->modules_parts['captcha'] : array());
|
||||
foreach ($conf->modules_parts['captcha'] as $mo) {
|
||||
//Add more models
|
||||
$dirModCaptcha[] = $mo.'core/modules/security/captcha';
|
||||
}
|
||||
$dirModCaptcha = array_merge(array('/core/modules/security/captcha/'), is_array($conf->modules_parts['captcha']) ? $conf->modules_parts['captcha'] : array());
|
||||
|
||||
// Load array with all captcha generation modules
|
||||
$arrayhandler = array();
|
||||
|
|
|
|||
|
|
@ -793,21 +793,36 @@ class FormTicket
|
|||
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
|
||||
$captcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard');
|
||||
|
||||
$classfile = DOL_DOCUMENT_ROOT."/core/modules/security/captcha/modCaptcha".ucfirst($captcha).'.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
$captchaobj = null;
|
||||
if (dol_is_file($classfile)) {
|
||||
// Charging the numbering class
|
||||
$classname = "modCaptcha".ucfirst($captcha);
|
||||
require_once $classfile;
|
||||
// List of directories where we can find captcha handlers
|
||||
$dirModCaptcha = array_merge(array('main' => '/core/modules/security/captcha/'), is_array($conf->modules_parts['captcha']) ? $conf->modules_parts['captcha'] : array());
|
||||
|
||||
$captchaobj = new $classname($this->db, $conf, $langs, $user);
|
||||
$fullpathclassfile = '';
|
||||
foreach ($dirModCaptcha as $dir) {
|
||||
$fullpathclassfile = dol_buildpath($dir."modCaptcha".ucfirst($captcha).'.class.php', 0, 2);
|
||||
if ($fullpathclassfile) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) {
|
||||
print $captchaobj->getCaptchaCodeForForm();
|
||||
if ($fullpathclassfile) {
|
||||
include_once $fullpathclassfile;
|
||||
$captchaobj = null;
|
||||
|
||||
// Charging the numbering class
|
||||
$classname = "modCaptcha".ucfirst($captcha);
|
||||
if (class_exists($classname)) {
|
||||
$captchaobj = new $classname($this->db, $conf, $langs, $user);
|
||||
|
||||
if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) {
|
||||
print $captchaobj->getCaptchaCodeForForm();
|
||||
} else {
|
||||
print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method getCaptchaCodeForForm()';
|
||||
}
|
||||
} else {
|
||||
print 'Error, the captcha handler class '.$classname.' was not found after the include';
|
||||
}
|
||||
} else {
|
||||
print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method getCaptchaCodeForForm()';
|
||||
print 'Error, the captcha handler '.$captcha.' has no class file found modCaptcha'.ucfirst($captcha);
|
||||
}
|
||||
|
||||
print '<br></td></tr>';
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class modCaptchaStandard extends ModeleCaptcha
|
|||
* Return the HTML content to output on a form that need the captcha
|
||||
*
|
||||
* @param string $php_self An URL for the a href link
|
||||
* @return int 0 if KO, >0 if OK
|
||||
* @return string The HTML code to output
|
||||
*/
|
||||
public function getCaptchaCodeForForm($php_self = '')
|
||||
{
|
||||
|
|
|
|||
|
|
@ -307,21 +307,35 @@ if (!empty($captcha)) {
|
|||
$php_self .= '?time='.dol_print_date(dol_now(), 'dayhourlog');
|
||||
}
|
||||
|
||||
$classfile = DOL_DOCUMENT_ROOT."/core/modules/security/captcha/modCaptcha".ucfirst($captcha).'.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
$captchaobj = null;
|
||||
if (dol_is_file($classfile)) {
|
||||
// Charging the numbering class
|
||||
$classname = "modCaptcha".ucfirst($captcha);
|
||||
require_once $classfile;
|
||||
|
||||
$captchaobj = new $classname($db, $conf, $langs, $user);
|
||||
// List of directories where we can find captcha handlers
|
||||
$dirModCaptcha = array_merge(array('main' => '/core/modules/security/captcha/'), is_array($conf->modules_parts['captcha']) ? $conf->modules_parts['captcha'] : array());
|
||||
$fullpathclassfile = '';
|
||||
foreach ($dirModCaptcha as $dir) {
|
||||
$fullpathclassfile = dol_buildpath($dir."modCaptcha".ucfirst($captcha).'.class.php', 0, 2);
|
||||
if ($fullpathclassfile) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) {
|
||||
print $captchaobj->getCaptchaCodeForForm($php_self);
|
||||
if ($fullpathclassfile) {
|
||||
include_once $fullpathclassfile;
|
||||
$captchaobj = null;
|
||||
|
||||
// Charging the numbering class
|
||||
$classname = "modCaptcha".ucfirst($captcha);
|
||||
if (class_exists($classname)) {
|
||||
$captchaobj = new $classname($db, $conf, $langs, $user);
|
||||
|
||||
if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) {
|
||||
print $captchaobj->getCaptchaCodeForForm();
|
||||
} else {
|
||||
print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method getCaptchaCodeForForm()';
|
||||
}
|
||||
} else {
|
||||
print 'Error, the captcha handler class '.$classname.' was not found after the include';
|
||||
}
|
||||
} else {
|
||||
print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method getCaptchaCodeForForm()';
|
||||
print 'Error, the captcha handler '.$captcha.' has no class file found modCaptcha'.ucfirst($captcha);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -174,21 +174,35 @@ if (!empty($captcha)) {
|
|||
$php_self .= '?time='.dol_print_date(dol_now(), 'dayhourlog');
|
||||
}
|
||||
|
||||
$classfile = DOL_DOCUMENT_ROOT."/core/modules/security/captcha/modCaptcha".ucfirst($captcha).'.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
$captchaobj = null;
|
||||
if (dol_is_file($classfile)) {
|
||||
// Charging the numbering class
|
||||
$classname = "modCaptcha".ucfirst($captcha);
|
||||
require_once $classfile;
|
||||
|
||||
$captchaobj = new $classname($db, $conf, $langs, $user);
|
||||
// List of directories where we can find captcha handlers
|
||||
$dirModCaptcha = array_merge(array('main' => '/core/modules/security/captcha/'), is_array($conf->modules_parts['captcha']) ? $conf->modules_parts['captcha'] : array());
|
||||
$fullpathclassfile = '';
|
||||
foreach ($dirModCaptcha as $dir) {
|
||||
$fullpathclassfile = dol_buildpath($dir."modCaptcha".ucfirst($captcha).'.class.php', 0, 2);
|
||||
if ($fullpathclassfile) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) {
|
||||
print $captchaobj->getCaptchaCodeForForm($php_self);
|
||||
if ($fullpathclassfile) {
|
||||
include_once $fullpathclassfile;
|
||||
$captchaobj = null;
|
||||
|
||||
// Charging the numbering class
|
||||
$classname = "modCaptcha".ucfirst($captcha);
|
||||
if (class_exists($classname)) {
|
||||
$captchaobj = new $classname($db, $conf, $langs, $user);
|
||||
|
||||
if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) {
|
||||
print $captchaobj->getCaptchaCodeForForm();
|
||||
} else {
|
||||
print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method getCaptchaCodeForForm()';
|
||||
}
|
||||
} else {
|
||||
print 'Error, the captcha handler class '.$classname.' was not found after the include';
|
||||
}
|
||||
} else {
|
||||
print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method getCaptchaCodeForForm()';
|
||||
print 'Error, the captcha handler '.$captcha.' has no class file found modCaptcha'.ucfirst($captcha);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user