Debug v24 - Must check siren and email in registration page
This commit is contained in:
parent
af08694e9d
commit
54eb261e5a
6 changed files with 90 additions and 60 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
|
||||
* Copyright (C) 2017-2018 Laurent Destailleur <eldy@destailleur.fr>
|
||||
* Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
|
||||
/* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
|
||||
* Copyright (C) 2017-2026 Laurent Destailleur <ldestailleur@dolicloud.com>
|
||||
* Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
|
@ -99,6 +99,25 @@ if ($action == 'update') {
|
|||
$error++;
|
||||
}
|
||||
|
||||
$country_code = GETPOST("BLOCKEDLOG_REGISTRATION_COUNTRY_CODE");
|
||||
$tmpthirdparty = new Societe($db);
|
||||
$tmpthirdparty->country_code = $country_code;
|
||||
$tmpthirdparty->country_id = getCountry($country_code, '3', $db, $langs, 0);
|
||||
$tmpthirdparty->idprof1 = GETPOST("BLOCKEDLOG_REGISTRATION_IDPROF1");
|
||||
|
||||
// Check validity of email
|
||||
if (!isValidEMail(GETPOST("BLOCKEDLOG_REGISTRATION_EMAIL"))) {
|
||||
setEventMessages($langs->trans("ErrorBadEMail", GETPOST("BLOCKEDLOG_REGISTRATION_EMAIL")), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Check validity of prof id
|
||||
if ($tmpthirdparty->idprof1 && isValidProfIds(1, $tmpthirdparty) <= 0) {
|
||||
$langs->loadLangs(array("errors", "companies"));
|
||||
setEventMessages($langs->trans("ErrorBadValueForParameter", $tmpthirdparty->idprof1, $langs->transcountry("ProfId1Short", $tmpthirdparty->country_code)), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
$company_name = GETPOST("BLOCKEDLOG_REGISTRATION_NAME");
|
||||
$company_email = GETPOST("BLOCKEDLOG_REGISTRATION_EMAIL");
|
||||
$company_country_code = GETPOST("BLOCKEDLOG_REGISTRATION_COUNTRY_CODE");
|
||||
|
|
|
|||
|
|
@ -246,3 +246,52 @@ function isValidTinForES($str)
|
|||
//Can not be verified
|
||||
return -4;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check the validity of a professional identifier according to the properties (country) of the company (siren, siret, ...)
|
||||
*
|
||||
* @param int $idprof 1,2,3,4 (Example: 1=siren, 2=siret, 3=naf, 4=rcs/rm)
|
||||
* @param Societe $thirdparty Object societe
|
||||
* @return int Return integer <=0 if KO, >0 if OK
|
||||
*/
|
||||
function isValidProfIds($idprof, $thirdparty)
|
||||
{
|
||||
$ok = 1;
|
||||
|
||||
if (getDolGlobalString('MAIN_DISABLEPROFIDRULES')) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check SIREN
|
||||
if ($idprof == 1 && $thirdparty->country_code == 'FR' && !isValidSiren($thirdparty->idprof1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check SIRET
|
||||
if ($idprof == 2 && $thirdparty->country_code == 'FR' && !isValidSiret($thirdparty->idprof2)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Verify CIF/NIF/NIE if pays ES
|
||||
if ($idprof == 1 && $thirdparty->country_code == 'ES') {
|
||||
return isValidTinForES($thirdparty->idprof1);
|
||||
}
|
||||
|
||||
// Verify NIF if country is PT
|
||||
if ($idprof == 1 && $thirdparty->country_code == 'PT' && !isValidTinForPT($thirdparty->idprof1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Verify NIF if country is DZ
|
||||
if ($idprof == 1 && $thirdparty->country_code == 'DZ' && !isValidTinForDZ($thirdparty->idprof1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Verify ID Prof 1 if country is BE
|
||||
if ($idprof == 1 && $thirdparty->country_code == 'BE' && !isValidTinForBE($thirdparty->idprof1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class ActionsCardCompany extends ActionsCardCommon
|
|||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
$this->tpl['langprofid'.$i] = $langs->transcountry('ProfId'.$i, $this->object->country_code);
|
||||
$this->tpl['checkprofid'.$i] = $this->object->id_prof_check($i, $this->object);
|
||||
$this->tpl['checkprofid'.$i] = $this->object->id_prof_check($i);
|
||||
$this->tpl['urlprofid'.$i] = $this->object->id_prof_url($i, $this->object);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3112,8 +3112,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayactio
|
|||
print '<td>'.$idprof.'</td><td>';
|
||||
$key = 'idprof'.$i;
|
||||
print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1);
|
||||
if ($object->$key) {
|
||||
if ($object->id_prof_check($i, $object) > 0) {
|
||||
if (!empty($object->$key)) {
|
||||
if ($object->id_prof_check($i) > 0) {
|
||||
$profidurl = $object->id_prof_url($i, $object);
|
||||
if (!empty($profidurl)) {
|
||||
print ' '.$profidurl;
|
||||
|
|
|
|||
|
|
@ -4271,67 +4271,29 @@ class Societe extends CommonObject
|
|||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Check the validity of a professional identifier according to the country of the company (siren, siret, ...)
|
||||
* Check the validity of a professional identifier according to the properties (country) of the thirdparty (siren, siret, ...)
|
||||
*
|
||||
* @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
|
||||
* @param Societe $soc Object societe
|
||||
* @return int Return integer <=0 if KO, >0 if OK
|
||||
* TODO better to have this in a lib than into a business class
|
||||
*/
|
||||
public function id_prof_check($idprof, $soc)
|
||||
public function id_prof_check($idprof)
|
||||
{
|
||||
// phpcs:enable
|
||||
|
||||
$ok = 1;
|
||||
|
||||
if (getDolGlobalString('MAIN_DISABLEPROFIDRULES')) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// load the library necessary to check the professional identifiers
|
||||
// Load the library necessary to check the professional identifiers
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/profid.lib.php';
|
||||
|
||||
// Check SIREN
|
||||
if ($idprof == 1 && $soc->country_code == 'FR' && !isValidSiren($this->idprof1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check SIRET
|
||||
if ($idprof == 2 && $soc->country_code == 'FR' && !isValidSiret($this->idprof2)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Verify CIF/NIF/NIE if pays ES
|
||||
if ($idprof == 1 && $soc->country_code == 'ES') {
|
||||
return isValidTinForES($this->idprof1);
|
||||
}
|
||||
|
||||
//Verify NIF if country is PT
|
||||
if ($idprof == 1 && $soc->country_code == 'PT' && !isValidTinForPT($this->idprof1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Verify NIF if country is DZ
|
||||
if ($idprof == 1 && $soc->country_code == 'DZ' && !isValidTinForDZ($this->idprof1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Verify ID Prof 1 if country is BE
|
||||
if ($idprof == 1 && $soc->country_code == 'BE' && !isValidTinForBE($this->idprof1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $ok;
|
||||
return isValidProfIds($idprof, $this);
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return an url to check online a professional id or empty string
|
||||
* Return an url to check online a professional id or empty string
|
||||
*
|
||||
* @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
|
||||
* @param Societe $thirdparty Object thirdparty
|
||||
* @return string Url or empty string if no URL known
|
||||
* TODO better in a lib than into business class
|
||||
* @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
|
||||
* @param Societe $thirdparty Object thirdparty
|
||||
* @return string Url or empty string if no URL known
|
||||
* TODO better to have this in the lib profid.lib.php rather than into this business class
|
||||
*/
|
||||
public function id_prof_url($idprof, $thirdparty)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -225,10 +225,10 @@ class SocieteTest extends CommonClassTest
|
|||
$localobject->country_code = 'FR';
|
||||
$localobject->idprof1 = 493861496;
|
||||
$localobject->idprof2 = 49386149600021;
|
||||
$result = $localobject->id_prof_check(1, $localobject); // Must be > 0
|
||||
$result = $localobject->id_prof_check(1); // Must be > 0
|
||||
print __METHOD__." OK FR idprof1 result=".$result."\n";
|
||||
$this->assertGreaterThanOrEqual(1, $result);
|
||||
$result = $localobject->id_prof_check(2, $localobject); // Must be > 0
|
||||
$result = $localobject->id_prof_check(2); // Must be > 0
|
||||
print __METHOD__." OK FR idprof2 result=".$result."\n";
|
||||
$this->assertGreaterThanOrEqual(1, $result);
|
||||
|
||||
|
|
@ -236,17 +236,17 @@ class SocieteTest extends CommonClassTest
|
|||
$localobject->country_code = 'FR';
|
||||
$localobject->idprof1 = 'id1ko';
|
||||
$localobject->idprof2 = 'id2ko';
|
||||
$result = $localobject->id_prof_check(1, $localobject); // Must be <= 0
|
||||
$result = $localobject->id_prof_check(1); // Must be <= 0
|
||||
print __METHOD__." KO FR idprof1 result=".$result."\n";
|
||||
$this->assertLessThan(1, $result);
|
||||
$result = $localobject->id_prof_check(2, $localobject); // Must be <= 0
|
||||
$result = $localobject->id_prof_check(2); // Must be <= 0
|
||||
print __METHOD__." KO FR idprof2 result=".$result."\n";
|
||||
$this->assertLessThan(1, $result);
|
||||
|
||||
// KO ES
|
||||
$localobject->country_code = 'ES';
|
||||
$localobject->idprof1 = 'id1ko';
|
||||
$result = $localobject->id_prof_check(1, $localobject); // Must be <= 0
|
||||
$result = $localobject->id_prof_check(1); // Must be <= 0
|
||||
print __METHOD__." KO ES idprof1 result=".$result."\n";
|
||||
$this->assertLessThan(1, $result);
|
||||
|
||||
|
|
@ -254,10 +254,10 @@ class SocieteTest extends CommonClassTest
|
|||
$localobject->country_code = 'AR';
|
||||
$localobject->idprof1 = 'id1ko';
|
||||
$localobject->idprof2 = 'id2ko';
|
||||
$result = $localobject->id_prof_check(1, $localobject); // Must be > 0
|
||||
$result = $localobject->id_prof_check(1); // Must be > 0
|
||||
print __METHOD__." OK AR idprof1 result=".$result."\n";
|
||||
$this->assertGreaterThanOrEqual(0, $result);
|
||||
$result = $localobject->id_prof_check(2, $localobject); // Must be > 0
|
||||
$result = $localobject->id_prof_check(2); // Must be > 0
|
||||
print __METHOD__." OK AR idprof2 result=".$result."\n";
|
||||
$this->assertGreaterThanOrEqual(1, $result);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue