Esempio n. 1
0
 /**
  *  Send new password by email
  *
  *  @param	User	$user           Object user that send email
  *  @param	string	$password       New password
  *	@param	int		$changelater	1=Change password only after clicking on confirm email
  *  @return int 		            < 0 si erreur, > 0 si ok
  */
 function send_password($user, $password = '', $changelater = 0)
 {
     global $conf, $langs;
     global $dolibarr_main_url_root;
     require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
     $msgishtml = 0;
     // Define $msg
     $mesg = '';
     $outputlangs = new Translate("", $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;
     }
     $outputlangs->load("main");
     $outputlangs->load("errors");
     $outputlangs->load("users");
     $outputlangs->load("other");
     $subject = $outputlangs->transnoentitiesnoconv("SubjectNewPassword");
     // Define $urlwithroot
     //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
     //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
     $urlwithroot = DOL_MAIN_URL_ROOT;
     // This is to use same domain name than current
     if (!$changelater) {
         $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived") . ".\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyIs") . " :\n\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("Login") . " = " . $this->login . "\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("Password") . " = " . $password . "\n\n";
         $mesg .= "\n";
         $url = $urlwithroot . '/';
         $mesg .= $outputlangs->transnoentitiesnoconv("ClickHereToGoTo", $conf->global->MAIN_APPLICATION_TITLE) . ': ' . $url . "\n\n";
         $mesg .= "--\n";
         $mesg .= $user->getFullName($outputlangs);
         // Username that make then sending
     } else {
         $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived") . "\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyWillBe") . " :\n\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("Login") . " = " . $this->login . "\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("Password") . " = " . $password . "\n\n";
         $mesg .= "\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("YouMustClickToChange") . " :\n";
         $url = $urlwithroot . '/user/passwordforgotten.php?action=validatenewpassword&username='******'', '', 0, $msgishtml);
     if ($mailfile->sendfile()) {
         return 1;
     } else {
         $langs->trans("errors");
         $this->error = $langs->trans("ErrorFailedToSendPassword") . ' ' . $mailfile->error;
         return -1;
     }
 }
Esempio n. 2
0
 /**
  *   \brief     	Envoie mot de passe par mail
  *   \param     	user            Object user de l'utilisateur qui fait l'envoi
  *   \param			password        Nouveau mot de passe
  *	 \param			changelater		1=Change password only after clicking on confirm email
  *   \return    	int             < 0 si erreur, > 0 si ok
  */
 function send_password($user, $password = '', $changelater = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . "/lib/CMailFile.class.php";
     $subject = $langs->trans("SubjectNewPassword");
     $msgishtml = 0;
     // Define $msg
     $mesg = '';
     $outputlangs = new Translate("", $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;
     }
     // Define urlwithouturlroot
     if (!empty($_SERVER["HTTP_HOST"])) {
         $urlwithouturlroot = 'http://' . preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $_SERVER["HTTP_HOST"]);
     } else {
         $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $dolibarr_main_url_root);
     }
     if (!empty($dolibarr_main_force_https)) {
         $urlwithouturlroot = preg_replace('/http:/i', 'https:', $urlwithouturlroot);
     }
     // TODO Use outputlangs to translate messages
     if (!$changelater) {
         $mesg .= "A request to change your Dolibarr password has been received.\n";
         $mesg .= "This is your new keys to login:\n\n";
         $mesg .= $langs->trans("Login") . " : {$this->login}\n";
         $mesg .= $langs->trans("Password") . " : {$password}\n\n";
         $mesg .= "\n";
         $url = $urlwithouturlroot . DOL_URL_ROOT;
         $mesg .= 'Click here to go to Dolibarr: ' . $url . "\n\n";
         $mesg .= "--\n";
         $mesg .= $user->getFullName($langs);
         // Username that make then sending
     } else {
         $mesg .= "A request to change your Dolibarr password has been received.\n";
         $mesg .= "Your new key to login will be:\n\n";
         $mesg .= $langs->trans("Login") . " : {$this->login}\n";
         $mesg .= $langs->trans("Password") . " : {$password}\n\n";
         $mesg .= "\n";
         $mesg .= "You must click on the folowing link to validate its change.\n";
         $url = $urlwithouturlroot . DOL_URL_ROOT . '/user/passwordforgotten.php?action=validatenewpassword&username='******'t ask anything, just forget this email\n\n";
         dol_syslog("User::send_password url=" . $url);
     }
     $mailfile = new CMailFile($subject, $this->email, $conf->notification->email_from, $mesg, array(), array(), array(), '', '', 0, $msgishtml);
     if ($mailfile->sendfile()) {
         return 1;
     } else {
         $this->error = $langs->trans("ErrorFailedToSendPassword") . ' ' . $mailfile->error;
         //print nl2br($mesg);
         return -1;
     }
 }