New: Prepare code to send password reminder in user language
This commit is contained in:
parent
762b2c92b4
commit
16a8a8bd5f
@ -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."&";
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user