From 9f7b51938ff4361c98c457d5f77d7bb55749625e Mon Sep 17 00:00:00 2001 From: AdrianDominik Date: Tue, 28 Jan 2020 10:52:33 +0100 Subject: [PATCH] FIX: #12908 User login with credentials from self-subscription form fails --- htdocs/adherents/class/adherent.class.php | 34 +-- htdocs/user/class/user.class.php | 343 +++++++++++----------- 2 files changed, 189 insertions(+), 188 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 4dbdb519831..0aa7bcbf6ea 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -641,7 +641,7 @@ class Adherent extends CommonObject $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED)?0:1; // If password to set differs from the one found into database - $result=$this->setPassword($user, $this->pass, $this->pass_indatabase_crypted, $isencrypted, $notrigger, $nosyncuserpass); + $result=$this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass); if (! $nbrowsaffected) $nbrowsaffected++; } } @@ -964,9 +964,10 @@ class Adherent extends CommonObject * @param int $isencrypted 0 ou 1 si il faut crypter le mot de passe en base (0 par defaut) * @param int $notrigger 1=Ne declenche pas les triggers * @param int $nosyncuser Do not synchronize linked user + * @param int $alreadyencrypted 1 = password is already encrypted (0 by default) * @return string If OK return clear password, 0 if no change, < 0 if error */ - public function setPassword($user, $password = '', $password_indatabase_crypted = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0) + public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0, $alreadyencrypted = 0) { global $conf, $langs; @@ -974,23 +975,22 @@ class Adherent extends CommonObject dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted); - // If password_crypted not provided, try crypt password provided - if(!$password_indatabase_crypted) + // If new password not provided, we generate one + if (! $password) { - // If new password not provided, we generate one - if (!$password) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; - $password=getRandomPassword(false); - } - - // Crypt password - $password_crypted = dol_hash($password); - - } else { - $password_crypted = $password_indatabase_crypted; + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; + $password=getRandomPassword(false); } + // Crypt password + if ($alreadyencrypted != 1) $password_crypted = dol_hash($password); + else $password_crypted = $password; + + $password_indatabase = ''; + if (! $isencrypted) + { + $password_indatabase = $password; + } $this->db->begin(); @@ -1032,7 +1032,7 @@ class Adherent extends CommonObject if ($result >= 0) { - $result=$luser->setPassword($user, $this->pass, $this->pass_indatabase_crypted, 0, 0, 1); + $result=$luser->setPassword($user, $this->pass, 0, 0, 1, 1); if ($result < 0) { $this->error=$luser->error; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 8809873acc6..98bc2a7c7b0 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -75,34 +75,34 @@ class User extends CommonObject public $personal_email; - /** - * @var array array of socialnetworks - */ - public $socialnetworks; + /** + * @var array array of socialnetworks + */ + public $socialnetworks; - /** - * Skype username - * @var string - * @deprecated - */ + /** + * Skype username + * @var string + * @deprecated + */ public $skype; - /** - * Twitter username - * @var string - * @deprecated - */ + /** + * Twitter username + * @var string + * @deprecated + */ public $twitter; - /** - * Facebook username - * @var string - * @deprecated - */ + /** + * Facebook username + * @var string + * @deprecated + */ public $facebook; - /** - * Linkedin username - * @var string - * @deprecated - */ + /** + * Linkedin username + * @var string + * @deprecated + */ public $linkedin; public $job; // job position @@ -121,7 +121,7 @@ class User extends CommonObject public $office_phone; public $office_fax; public $user_mobile; - public $personal_mobile; + public $personal_mobile; public $admin; public $login; public $api_key; @@ -139,18 +139,18 @@ class User extends CommonObject public $pass_indatabase_crypted; /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; + * Date creation record (datec) + * + * @var integer + */ + public $datec; /** - * Date modification record (tms) - * - * @var integer - */ - public $datem; + * Date modification record (tms) + * + * @var integer + */ + public $datem; //! If this is defined, it is an external user /** @@ -167,8 +167,8 @@ class User extends CommonObject public $contactid; /** - * @var int ID - */ + * @var int ID + */ public $fk_member; /** @@ -176,7 +176,7 @@ class User extends CommonObject */ public $fk_user; public $fk_user_expense_validator; - public $fk_user_holiday_validator; + public $fk_user_holiday_validator; public $clicktodial_url; public $clicktodial_login; @@ -222,10 +222,10 @@ class User extends CommonObject public $fk_warehouse; public $fields = array( - 'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), - 'lastname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20, 'searchall'=>1, 'comment'=>'Reference of object'), - 'firstname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), - ); + 'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), + 'lastname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20, 'searchall'=>1, 'comment'=>'Reference of object'), + 'firstname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), + ); const STATUS_DISABLED = 0; @@ -391,7 +391,7 @@ class User extends CommonObject $this->office_phone = $obj->office_phone; $this->office_fax = $obj->office_fax; $this->user_mobile = $obj->user_mobile; - $this->personal_mobile = $obj->personal_mobile; + $this->personal_mobile = $obj->personal_mobile; $this->email = $obj->email; $this->personal_email = $obj->personal_email; $this->socialnetworks = (array) json_decode($obj->socialnetworks, true); @@ -427,8 +427,8 @@ class User extends CommonObject $this->contactid = $obj->fk_socpeople; $this->fk_member = $obj->fk_member; $this->fk_user = $obj->fk_user; - $this->fk_user_expense_validator = $obj->fk_user_expense_validator; - $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator; + $this->fk_user_expense_validator = $obj->fk_user_expense_validator; + $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator; $this->default_range = $obj->default_range; $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat; @@ -1032,7 +1032,7 @@ class User extends CommonObject * Existing categories are left untouch. * * @param int[]|int $categories Category or categories IDs - * @return void + * @return void */ public function setCategories($categories) { @@ -1122,24 +1122,24 @@ class User extends CommonObject // Remove extrafields if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { - $result = $this->deleteExtraFields(); - if ($result < 0) - { - $error++; - dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); - } + $result = $this->deleteExtraFields(); + if ($result < 0) + { + $error++; + dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); + } } // Remove user if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - if (!$this->db->query($sql)) - { - $error++; - $this->error = $this->db->lasterror(); - } + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + if (!$this->db->query($sql)) + { + $error++; + $this->error = $this->db->lasterror(); + } } if (!$error) @@ -1180,7 +1180,7 @@ class User extends CommonObject if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); $this->login = trim($this->login); if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value @@ -1302,7 +1302,7 @@ class User extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a user from a contact object. User will be internal but if contact is linked to a third party, user will be external * @@ -1313,7 +1313,7 @@ class User extends CommonObject */ public function create_from_contact($contact, $login = '', $password = '') { - // phpcs:enable + // phpcs:enable global $conf, $user, $langs; $error = 0; @@ -1381,7 +1381,7 @@ class User extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a user into database from a member object * @@ -1391,7 +1391,7 @@ class User extends CommonObject */ public function create_from_member($member, $login = '') { - // phpcs:enable + // phpcs:enable global $conf, $user, $langs; // Positionne parametres @@ -1418,7 +1418,9 @@ class User extends CommonObject $result = $this->create($user); if ($result > 0) { - $newpass = $this->setPassword($user, $this->pass, $this->pass_indatabase_crypted); + if(!$this->pass && $this->pass_indatabase_crypted) $newpass = $this->setPassword($user, $this->pass_indatabase_crypted, 0, 0, 0, 1); + else $newpass = $this->setPassword($user, $this->pass); + if (is_numeric($newpass) && $newpass < 0) $result = -2; if ($result > 0 && $member->fk_soc) // If member is linked to a thirdparty @@ -1457,7 +1459,7 @@ class User extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Assign rights by default * @@ -1465,7 +1467,7 @@ class User extends CommonObject */ public function set_default_rights() { - // phpcs:enable + // phpcs:enable global $conf; $sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def"; @@ -1524,7 +1526,7 @@ class User extends CommonObject if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); $this->lastname = trim($this->lastname); $this->firstname = trim($this->firstname); @@ -1542,9 +1544,9 @@ class User extends CommonObject $this->office_phone = trim($this->office_phone); $this->office_fax = trim($this->office_fax); $this->user_mobile = trim($this->user_mobile); - $this->personal_mobile = trim($this->personal_mobile); + $this->personal_mobile = trim($this->personal_mobile); $this->email = trim($this->email); - $this->personal_email = trim($this->personal_email); + $this->personal_email = trim($this->personal_email); $this->job = trim($this->job); $this->signature = trim($this->signature); @@ -1595,10 +1597,10 @@ class User extends CommonObject $sql .= ", office_phone = '".$this->db->escape($this->office_phone)."'"; $sql .= ", office_fax = '".$this->db->escape($this->office_fax)."'"; $sql .= ", user_mobile = '".$this->db->escape($this->user_mobile)."'"; - $sql .= ", personal_mobile = '".$this->db->escape($this->personal_mobile)."'"; + $sql .= ", personal_mobile = '".$this->db->escape($this->personal_mobile)."'"; $sql .= ", email = '".$this->db->escape($this->email)."'"; - $sql .= ", personal_email = '".$this->db->escape($this->personal_email)."'"; - $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; + $sql .= ", personal_email = '".$this->db->escape($this->personal_email)."'"; + $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; $sql .= ", job = '".$this->db->escape($this->job)."'"; $sql .= ", signature = '".$this->db->escape($this->signature)."'"; $sql .= ", accountancy_code = '".$this->db->escape($this->accountancy_code)."'"; @@ -1610,8 +1612,8 @@ class User extends CommonObject $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null"); $sql .= ", openid = ".($this->openid ? "'".$this->db->escape($this->openid)."'" : "null"); $sql .= ", fk_user = ".($this->fk_user > 0 ? "'".$this->db->escape($this->fk_user)."'" : "null"); - $sql .= ", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? "'".$this->db->escape($this->fk_user_expense_validator)."'" : "null"); - $sql .= ", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? "'".$this->db->escape($this->fk_user_holiday_validator)."'" : "null"); + $sql .= ", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? "'".$this->db->escape($this->fk_user_expense_validator)."'" : "null"); + $sql .= ", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? "'".$this->db->escape($this->fk_user_holiday_validator)."'" : "null"); if (isset($this->thm) || $this->thm != '') $sql .= ", thm= ".($this->thm != '' ? "'".$this->db->escape($this->thm)."'" : "null"); if (isset($this->tjm) || $this->tjm != '') $sql .= ", tjm= ".($this->tjm != '' ? "'".$this->db->escape($this->tjm)."'" : "null"); if (isset($this->salary) || $this->salary != '') $sql .= ", salary= ".($this->salary != '' ? "'".$this->db->escape($this->salary)."'" : "null"); @@ -1811,7 +1813,7 @@ class User extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Mise a jour en base de la date de derniere connexion d'un utilisateur * Fonction appelee lors d'une nouvelle connexion @@ -1820,7 +1822,7 @@ class User extends CommonObject */ public function update_last_login_date() { - // phpcs:enable + // phpcs:enable $now = dol_now(); $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; @@ -1853,9 +1855,10 @@ class User extends CommonObject * @param int $changelater 1=Change password only after clicking on confirm email * @param int $notrigger 1=Does not launch triggers * @param int $nosyncmember Do not synchronize linked member + * @param int $alreadyencrypted 1 = password is already encrypted (0 by default) * @return string If OK return clear password, 0 if no change, < 0 if error */ - public function setPassword($user, $password = '', $password_indatabase_crypted = '', $changelater = 0, $notrigger = 0, $nosyncmember = 0) + public function setPassword($user, $password = '', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $alreadyencrypted = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; @@ -1864,21 +1867,15 @@ class User extends CommonObject dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." changelater=".$changelater." notrigger=".$notrigger." nosyncmember=".$nosyncmember, LOG_DEBUG); - // If password_crypted not provided, try crypt password provided - if(!$password_indatabase_crypted) + // If new password not provided, we generate one + if (!$password) { - // If new password not provided, we generate one - if (!$password) - { - $password = getRandomPassword(false); - } - - // Crypt password - $password_crypted = dol_hash($password); - } else { - $password_crypted = $password_indatabase_crypted; + $password = getRandomPassword(false); } + // Crypt password + if ($alreadyencrypted != 1) $password_crypted = dol_hash($password); + else $password_crypted = $password; // Mise a jour @@ -1922,7 +1919,11 @@ class User extends CommonObject if ($result >= 0) { - $result = $adh->setPassword($user, $this->pass, $this->pass_indatabase_crypted, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1); // Cryptage non gere dans module adherent + + if ($alreadyencrypted != 1) $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1); // Cryptage non gere dans module adherent + else $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1, 0, 1); // Dont encrypt the password cause is already encrypted + + if ($result < 0) { $this->error = $adh->error; @@ -1986,7 +1987,7 @@ class User extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Send new password by email * @@ -1997,7 +1998,7 @@ class User extends CommonObject */ public function send_password($user, $password = '', $changelater = 0) { - // phpcs:enable + // phpcs:enable global $conf, $langs; global $dolibarr_main_url_root; @@ -2011,19 +2012,19 @@ class User extends CommonObject $outputlangs = new Translate("", $conf); if (isset($this->conf->MAIN_LANG_DEFAULT) - && $this->conf->MAIN_LANG_DEFAULT != 'auto') + && $this->conf->MAIN_LANG_DEFAULT != 'auto') { // If user has defined its own language (rare because in most cases, auto is used) $outputlangs->getDefaultLang($this->conf->MAIN_LANG_DEFAULT); } if ($user->conf->MAIN_LANG_DEFAULT) { - $outputlangs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT); - } + $outputlangs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT); + } else { // If user has not defined its own language, we used current language $outputlangs = $langs; } - // Load translation files required by the page + // Load translation files required by the page $outputlangs->loadLangs(array("main", "errors", "users", "other")); $appli = constant('DOL_APPLICATION_TITLE'); @@ -2066,8 +2067,8 @@ class User extends CommonObject dol_syslog(get_class($this)."::send_password changelater is on, url=".$url); } - $mailfile = new CMailFile( - $subject, + $mailfile = new CMailFile( + $subject, $this->email, $conf->global->MAIN_MAIL_EMAIL_FROM, $mesg, @@ -2077,8 +2078,8 @@ class User extends CommonObject '', '', 0, - $msgishtml - ); + $msgishtml + ); if ($mailfile->sendfile()) { @@ -2103,7 +2104,7 @@ class User extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Read clicktodial information for user * @@ -2111,7 +2112,7 @@ class User extends CommonObject */ public function fetch_clicktodial() { - // phpcs:enable + // phpcs:enable $sql = "SELECT url, login, pass, poste "; $sql .= " FROM ".MAIN_DB_PREFIX."user_clicktodial as u"; $sql .= " WHERE u.fk_user = ".$this->id; @@ -2141,15 +2142,15 @@ class User extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update clicktodial info * * @return int <0 if KO, >0 if OK - */ - public function update_clicktodial() - { - // phpcs:enable + */ + public function update_clicktodial() + { + // phpcs:enable $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_clicktodial"; @@ -2179,10 +2180,10 @@ class User extends CommonObject $this->error = $this->db->lasterror(); return -1; } - } + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Add user into a group * @@ -2193,7 +2194,7 @@ class User extends CommonObject */ public function SetInGroup($group, $entity, $notrigger = 0) { - // phpcs:enable + // phpcs:enable global $conf, $langs, $user; $error = 0; @@ -2244,7 +2245,7 @@ class User extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Remove a user from a group * @@ -2255,7 +2256,7 @@ class User extends CommonObject */ public function RemoveFromGroup($group, $entity, $notrigger = 0) { - // phpcs:enable + // phpcs:enable global $conf, $langs, $user; $error = 0; @@ -2342,7 +2343,7 @@ class User extends CommonObject global $dolibarr_main_authentication, $dolibarr_main_demo; global $menumanager; - if (!$user->rights->user->user->lire && $user->id != $this->id) $option = 'nolink'; + if (!$user->rights->user->user->lire && $user->id != $this->id) $option = 'nolink'; if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg = 0; @@ -2436,8 +2437,8 @@ class User extends CommonObject $result .= (($option == 'nolink') ? '' : $linkstart); if ($withpictoimg) { - $paddafterimage = ''; - if (abs($withpictoimg) == 1) $paddafterimage = 'style="margin-'.($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right').': 3px;"'; + $paddafterimage = ''; + if (abs($withpictoimg) == 1) $paddafterimage = 'style="margin-'.($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right').': 3px;"'; // Only picto if ($withpictoimg > 0) $picto = ''.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).''; // Picto must be a photo @@ -2491,7 +2492,7 @@ class User extends CommonObject $linkend = ''; } - if ($option == 'nolink') + if ($option == 'nolink') { $linkstart = ''; $linkend = ''; @@ -2515,17 +2516,17 @@ class User extends CommonObject return $this->LibStatut($this->statut, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return label of a status of user (active, inactive) - * - * @param int $status Id status + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return label of a status of user (active, inactive) + * + * @param int $status Id status * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status - */ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable + * @return string Label of status + */ + public function LibStatut($status, $mode = 0) + { + // phpcs:enable global $langs; if (empty($this->labelStatus) || empty($this->labelStatusShort)) @@ -2558,7 +2559,7 @@ class User extends CommonObject */ public function _load_ldap_dn($info, $mode = 0) { - // phpcs:enable + // phpcs:enable global $conf; $dn = ''; if ($mode == 0) $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN; @@ -2576,7 +2577,7 @@ class User extends CommonObject */ public function _load_ldap_info() { - // phpcs:enable + // phpcs:enable global $conf, $langs; $info = array(); @@ -2602,7 +2603,7 @@ class User extends CommonObject 'LDAP_FIELD_SKYPE' => 'skype', 'LDAP_FIELD_TWITTER' => 'twitter', 'LDAP_FIELD_FACEBOOK' => 'facebook', - 'LDAP_FIELD_LINKEDIN' => 'linkedin' + 'LDAP_FIELD_LINKEDIN' => 'linkedin' ); // Champs @@ -2686,22 +2687,22 @@ class User extends CommonObject if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile; } - if (!empty($conf->global->LDAP_FIELD_USERID))$info[$conf->global->LDAP_FIELD_USERID] = $this->id; - if (!empty($info[$conf->global->LDAP_FIELD_GROUPID])) { - $usergroup = new UserGroup($this->db); - $groupslist = $usergroup->listGroupsForUser($this->id); - $info[$conf->global->LDAP_FIELD_GROUPID] = '1'; - if (!empty($groupslist)) { - foreach ($groupslist as $groupforuser) { - $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id; //Select first group in list - break; - } - } - } - if (!empty($this->firstname) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] = "{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->firstname"; + if (!empty($conf->global->LDAP_FIELD_USERID))$info[$conf->global->LDAP_FIELD_USERID] = $this->id; + if (!empty($info[$conf->global->LDAP_FIELD_GROUPID])) { + $usergroup = new UserGroup($this->db); + $groupslist = $usergroup->listGroupsForUser($this->id); + $info[$conf->global->LDAP_FIELD_GROUPID] = '1'; + if (!empty($groupslist)) { + foreach ($groupslist as $groupforuser) { + $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id; //Select first group in list + break; + } + } + } + if (!empty($this->firstname) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] = "{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->firstname"; - return $info; - } + return $info; + } /** @@ -2728,7 +2729,7 @@ class User extends CommonObject $this->note_public = 'This is a note public'; $this->note_private = 'This is a note private'; $this->email = 'email@specimen.com'; - $this->personal_email = 'personalemail@specimen.com'; + $this->personal_email = 'personalemail@specimen.com'; $this->socialnetworks = array( 'skype' => 'skypepseudo', 'twitter' => 'twitterpseudo', @@ -2738,7 +2739,7 @@ class User extends CommonObject $this->office_phone = '0999999999'; $this->office_fax = '0999999998'; $this->user_mobile = '0999999997'; - $this->personal_mobile = '0999999996'; + $this->personal_mobile = '0999999996'; $this->admin = 0; $this->login = 'dolibspec'; $this->pass = 'dolibspec'; @@ -2863,7 +2864,7 @@ class User extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update user using data from the LDAP * @@ -2872,7 +2873,7 @@ class User extends CommonObject */ public function update_ldap2dolibarr(&$ldapuser) { - // phpcs:enable + // phpcs:enable // TODO: Voir pourquoi le update met à jour avec toutes les valeurs vide (global $user écrase ?) global $user, $conf; @@ -2903,7 +2904,7 @@ class User extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return and array with all instanciated first level children users of current user * @@ -2912,7 +2913,7 @@ class User extends CommonObject */ public function get_children() { - // phpcs:enable + // phpcs:enable $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."user"; $sql .= " WHERE fk_user = ".$this->id; @@ -2971,7 +2972,7 @@ class User extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Build the hierarchy/tree of users into an array. * Set and return this->users that is an array sorted according to tree with arrays of: @@ -2985,9 +2986,9 @@ class User extends CommonObject * @param string $filter SQL filter on users * @return array Array of users $this->users. Note: $this->parentof is also set. */ - public function get_full_tree($deleteafterid = 0, $filter = '') - { - // phpcs:enable + public function get_full_tree($deleteafterid = 0, $filter = '') + { + // phpcs:enable global $conf, $user; global $hookmanager; @@ -3087,8 +3088,8 @@ class User extends CommonObject * @return array Array of user id lower than user (all levels under user). This overwrite this->users. * @see get_children() */ - public function getAllChildIds($addcurrentuser = 0) - { + public function getAllChildIds($addcurrentuser = 0) + { $childids = array(); if (isset($this->cache_childids[$this->id])) @@ -3116,7 +3117,7 @@ class User extends CommonObject return $childids; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * For user id_user and its childs available in this->users, define property fullpath and fullname. * Function called by get_full_tree(). @@ -3125,9 +3126,9 @@ class User extends CommonObject * @param int $protection Deep counter to avoid infinite loop (no more required, a protection is added with array useridfound) * @return int < 0 if KO (infinit loop), >= 0 if OK */ - public function build_path_from_id_user($id_user, $protection = 0) - { - // phpcs:enable + public function build_path_from_id_user($id_user, $protection = 0) + { + // phpcs:enable dol_syslog(get_class($this)."::build_path_from_id_user id_user=".$id_user." protection=".$protection, LOG_DEBUG); if (!empty($this->users[$id_user]['fullpath'])) @@ -3180,7 +3181,7 @@ class User extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load metrics this->nb for dashboard * @@ -3188,7 +3189,7 @@ class User extends CommonObject */ public function load_state_board() { - // phpcs:enable + // phpcs:enable $this->nb = array(); @@ -3224,7 +3225,7 @@ class User extends CommonObject * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) @@ -3251,7 +3252,7 @@ class User extends CommonObject return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return property of user from its id * @@ -3261,7 +3262,7 @@ class User extends CommonObject */ public function user_get_property($rowid, $mode) { - // phpcs:enable + // phpcs:enable $user_property = ''; if (empty($rowid)) return ''; @@ -3303,8 +3304,8 @@ class User extends CommonObject * @return int <0 if KO, >0 if OK */ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = array(), $filtermode = 'AND', $entityfilter = false) - { - global $conf, $user; + { + global $conf, $user; $sql = "SELECT t.rowid"; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t '; @@ -3379,8 +3380,8 @@ class User extends CommonObject } else { - $this->errors[] = $this->db->lasterror(); - return -1; - } - } + $this->errors[] = $this->db->lasterror(); + return -1; + } + } }