New: Prepare code to send password reminder in user language

This commit is contained in:
Laurent Destailleur 2008-08-29 23:49:53 +00:00
parent 762b2c92b4
commit 16a8a8bd5f
2 changed files with 45 additions and 60 deletions

View File

@ -119,11 +119,12 @@ class User extends CommonObject
/** /**
* \brief Charge un objet user avec toutes ces caracteristiques depuis un id ou login * \brief Charge un objet user avec toutes ces caracteristiques depuis un id ou login
* \param login Si defini, login a utiliser pour recherche * \param login Si defini, login a utiliser pour recherche
* \param sid Si defini, sid a utiliser pour recherche * \param sid Si defini, sid a utiliser pour recherche
* \return int <0 if KO, 0 not found, >0 if OK * \param $loadpersonalconf Also load personal conf of user (in $user->conf->xxx)
* \return int <0 if KO, 0 not found, >0 if OK
*/ */
function fetch($login='',$sid='') function fetch($login='',$sid='',$loadpersonalconf=1)
{ {
global $conf; global $conf;
@ -217,60 +218,32 @@ class User extends CommonObject
} }
// Recupere parametrage global propre a l'utilisateur // Recupere parametrage global propre a l'utilisateur
// \todo a stocker/recuperer en session pour eviter ce select a chaque page // \TODO a stocker/recuperer en session pour eviter ce select a chaque page
$sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param"; // \TODO Remove where on page and remove page field in databse (not used)
$sql.= " WHERE fk_user = ".$this->id; if ($loadpersonalconf)
$sql.= " AND page = ''";
$result=$this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$p=$obj->param;
if ($p) $this->conf->$p = $obj->value;
$i++;
}
$this->db->free($result);
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("User::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql, LOG_ERR);
return -2;
}
// Recupere parametrage propre a la page et a l'utilisateur
// \todo SCRIPT_URL non defini sur tous serveurs
// Parametrage par page desactive pour l'instant
if (1==2 && isset($_SERVER['SCRIPT_URL']))
{ {
$sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param"; $sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param";
$sql.= " WHERE fk_user = ".$this->id; $sql.= " WHERE fk_user = ".$this->id;
$sql.= " AND page='".$_SERVER['SCRIPT_URL']."'"; $sql.= " AND page = ''";
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
{ {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$i = 0; $i = 0;
$page_param_url = '';
$this->page_param = array();
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->page_param[$obj->param] = $obj->value; $p=$obj->param;
$page_param_url .= $obj->param."=".$obj->value."&amp;"; if ($p) $this->conf->$p = $obj->value;
$i++; $i++;
} }
$this->page_param_url = $page_param_url;
$this->db->free($result); $this->db->free($result);
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
return -1; dolibarr_syslog("User::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql, LOG_ERR);
return -2;
} }
} }
@ -656,7 +629,7 @@ class User extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE rowid = ".$this->contact_id; $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE rowid = ".$this->contact_id;
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
} }
} }
@ -708,7 +681,7 @@ class User extends CommonObject
{ {
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$this->db->free($resql); $this->db->free($resql);
if ($num) if ($num)
{ {
$this->error = 'ErrorLoginAlreadyExists'; $this->error = 'ErrorLoginAlreadyExists';
@ -726,7 +699,7 @@ class User extends CommonObject
{ {
$table = "".MAIN_DB_PREFIX."user"; $table = "".MAIN_DB_PREFIX."user";
$this->id = $this->db->last_insert_id($table); $this->id = $this->db->last_insert_id($table);
// Set default rights // Set default rights
if ($this->set_default_rights() < 0) if ($this->set_default_rights() < 0)
{ {
@ -734,7 +707,7 @@ class User extends CommonObject
$this->db->rollback(); $this->db->rollback();
return -5; return -5;
} }
// Update minor fields // Update minor fields
$result = $this->update($user,1,1); $result = $this->update($user,1,1);
if ($result < 0) if ($result < 0)
@ -762,7 +735,7 @@ class User extends CommonObject
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
} }
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
@ -1001,7 +974,7 @@ class User extends CommonObject
if ($resql) if ($resql)
{ {
$nbrowsaffected+=$this->db->affected_rows($resql); $nbrowsaffected+=$this->db->affected_rows($resql);
// Mise a jour mot de passe // Mise a jour mot de passe
if ($this->pass) if ($this->pass)
{ {
@ -1009,22 +982,22 @@ class User extends CommonObject
{ {
// Si mot de passe saisi et different de celui en base // Si mot de passe saisi et different de celui en base
$result=$this->setPassword($user,$this->pass,0,$notrigger); $result=$this->setPassword($user,$this->pass,0,$notrigger);
if (! $nbrowsaffected) $nbrowsaffected++; if (! $nbrowsaffected) $nbrowsaffected++;
} }
} }
if ($nbrowsaffected) if ($nbrowsaffected)
{ {
if ($this->fk_member && ! $nosyncmember) if ($this->fk_member && ! $nosyncmember)
{ {
require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
// This user is linked with a member, so we also update members informations // This user is linked with a member, so we also update members informations
// if this is an update. // if this is an update.
$adh=new Adherent($this->db); $adh=new Adherent($this->db);
$result=$adh->fetch($this->fk_member); $result=$adh->fetch($this->fk_member);
if ($result >= 0) if ($result >= 0)
{ {
$adh->prenom=$this->prenom; $adh->prenom=$this->prenom;
@ -1211,7 +1184,7 @@ class User extends CommonObject
if ($result < 0) $this->errors=$interface->errors; if ($result < 0) $this->errors=$interface->errors;
// Fin appel triggers // Fin appel triggers
} }
return $this->pass; return $this->pass;
} }
else else
@ -1251,8 +1224,8 @@ class User extends CommonObject
/** /**
* \brief Envoie mot de passe par mail * \brief Envoie mot de passe par mail
* \param user Object user de l'utilisateur qui fait l'envoi * \param user Object user de l'utilisateur qui fait l'envoi
* \param password Nouveau mot de passe * \param password Nouveau mot de passe
* \param changelater 1=Change password only after clicking on confirm email * \param changelater 1=Change password only after clicking on confirm email
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function send_password($user, $password='', $changelater=0) function send_password($user, $password='', $changelater=0)
@ -1266,6 +1239,19 @@ class User extends CommonObject
// Define $msg // Define $msg
$mesg = ''; $mesg = '';
$outputlangs=new Translate($db,$conf);
if (isset($this->conf->MAIN_LANG_DEFAULT)
&& $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);
}
else
{ // If user has not defined its own language, we used current language
$outputlangs=$langs;
}
// \TODO Use outputlangs to translate messages
if (! $changelater) if (! $changelater)
{ {
$mesg.= "A request to change your Dolibarr password has been received.\n"; $mesg.= "A request to change your Dolibarr password has been received.\n";
@ -1292,8 +1278,7 @@ class User extends CommonObject
dolibarr_syslog("User::send_password url=".$url); dolibarr_syslog("User::send_password url=".$url);
} }
$mailfile = new CMailFile($subject,$this->email,$conf->notification->email_from,$mesg, $mailfile = new CMailFile($subject,$this->email,$conf->notification->email_from,$mesg,
array(),array(),array(), array(),array(),array(),'', '', 0, $msgishtml);
'', '', 0, $msgishtml);
if ($mailfile->sendfile()) if ($mailfile->sendfile())
{ {

View File

@ -88,10 +88,10 @@ if ($_POST["action"] == 'buildnewpassword' && $_POST["username"])
require_once DOL_DOCUMENT_ROOT.'/../external-libs/Artichow/Artichow.cfg.php'; require_once DOL_DOCUMENT_ROOT.'/../external-libs/Artichow/Artichow.cfg.php';
require_once ARTICHOW."/AntiSpam.class.php"; require_once ARTICHOW."/AntiSpam.class.php";
// On créé l'objet anti-spam // We create anti-spam object
$object = new AntiSpam(); $object = new AntiSpam();
// Verifie code // Verify code
if (! $object->check('dol_antispam_value',$_POST['code'],true)) if (! $object->check('dol_antispam_value',$_POST['code'],true))
{ {
$message = '<div class="error">'.$langs->trans("ErrorBadValueForCode").'</div>'; $message = '<div class="error">'.$langs->trans("ErrorBadValueForCode").'</div>';
@ -99,7 +99,7 @@ if ($_POST["action"] == 'buildnewpassword' && $_POST["username"])
else else
{ {
$edituser = new User($db); $edituser = new User($db);
$result=$edituser->fetch($_POST["username"]); $result=$edituser->fetch($_POST["username"],'',1);
if ($result <= 0 && $edituser->error == 'USERNOTFOUND') if ($result <= 0 && $edituser->error == 'USERNOTFOUND')
{ {
$message = '<div class="error">'.$langs->trans("ErrorLoginDoesNotExists",$_POST["username"]).'</div>'; $message = '<div class="error">'.$langs->trans("ErrorLoginDoesNotExists",$_POST["username"]).'</div>';
@ -116,12 +116,12 @@ if ($_POST["action"] == 'buildnewpassword' && $_POST["username"])
$newpassword=$edituser->setPassword($user,'',1); $newpassword=$edituser->setPassword($user,'',1);
if ($newpassword < 0) if ($newpassword < 0)
{ {
// Echec // Failed
$message = '<div class="error">'.$langs->trans("ErrorFailedToChangePassword").'</div>'; $message = '<div class="error">'.$langs->trans("ErrorFailedToChangePassword").'</div>';
} }
else else
{ {
// Succes // Success
if ($edituser->send_password($user,$newpassword,1) > 0) if ($edituser->send_password($user,$newpassword,1) > 0)
{ {
$message = '<div class="ok">'.$langs->trans("PasswordChangeRequestSent",$edituser->login,$edituser->email).'</div>'; $message = '<div class="ok">'.$langs->trans("PasswordChangeRequestSent",$edituser->login,$edituser->email).'</div>';