Use a dedicated sendcontext when sending email for password reset
This commit is contained in:
parent
1ff1c8d48c
commit
4a1153dc49
3 changed files with 16 additions and 13 deletions
|
|
@ -164,7 +164,7 @@ class CMailFile
|
|||
* @param string $css Css option
|
||||
* @param string $trackid Tracking string (contains type and id of related element)
|
||||
* @param string $moreinheader More in header. $moreinheader must contains the "\r\n" (TODO not supported for other MAIL_SEND_MODE different than 'mail' and 'smtps' for the moment)
|
||||
* @param string $sendcontext 'standard', 'emailing', ... (used to define which sending mode and parameters to use)
|
||||
* @param string $sendcontext 'standard', 'emailing', 'ticket', 'password', ... (used to define which sending mode and parameters to use)
|
||||
* @param string $replyto Reply-to email (will be set to same value than From by default if not provided)
|
||||
* @param string $upload_dir_tmp Temporary directory (used to convert images embedded as img src=data:image)
|
||||
*/
|
||||
|
|
@ -187,7 +187,7 @@ class CMailFile
|
|||
|
||||
$this->sendcontext = $sendcontext;
|
||||
|
||||
// Define this->sendmode ('mail', 'smtps', 'siwftmailer', ...) according to $sendcontext ('standard', 'emailing', 'ticket')
|
||||
// Define this->sendmode ('mail', 'smtps', 'swiftmailer', ...) according to $sendcontext ('standard', 'emailing', 'ticket', 'password')
|
||||
$this->sendmode = '';
|
||||
if (!empty($this->sendcontext)) {
|
||||
$smtpContextKey = strtoupper($this->sendcontext);
|
||||
|
|
|
|||
|
|
@ -2388,7 +2388,7 @@ class User extends CommonObject
|
|||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Send new password by email
|
||||
* Send a new password (or instructions to reset it) by email
|
||||
*
|
||||
* @param User $user Object user that send the email (not the user we send to) @todo object $user is not used !
|
||||
* @param string $password New password
|
||||
|
|
@ -2437,8 +2437,12 @@ class User extends CommonObject
|
|||
|
||||
if (!$changelater) {
|
||||
$url = $urlwithroot.'/';
|
||||
if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD))
|
||||
if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD)) {
|
||||
$url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::send_password changelater is off, url=".$url);
|
||||
|
||||
$mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived").".\n";
|
||||
$mesg .= $outputlangs->transnoentitiesnoconv("NewKeyIs")." :\n\n";
|
||||
$mesg .= $outputlangs->transnoentitiesnoconv("Login")." = ".$this->login."\n";
|
||||
|
|
@ -2448,11 +2452,7 @@ class User extends CommonObject
|
|||
$mesg .= $outputlangs->transnoentitiesnoconv("ClickHereToGoTo", $appli).': '.$url."\n\n";
|
||||
$mesg .= "--\n";
|
||||
$mesg .= $user->getFullName($outputlangs); // Username that send the email (not the user for who we want to reset password)
|
||||
|
||||
dol_syslog(get_class($this)."::send_password changelater is off, url=".$url);
|
||||
} else {
|
||||
global $conf;
|
||||
|
||||
//print $password.'-'.$this->id.'-'.$conf->file->instance_unique_id;
|
||||
$url = $urlwithroot.'/user/passwordforgotten.php?action=validatenewpassword';
|
||||
$url .= '&username='.urlencode($this->login)."&passworduidhash=".urlencode(dol_hash($password.'-'.$this->id.'-'.$conf->file->instance_unique_id));
|
||||
|
|
@ -2460,6 +2460,8 @@ class User extends CommonObject
|
|||
$url .= '&entity='.(!empty($this->entity) ? $this->entity : 1);
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::send_password changelater is on, url=".$url);
|
||||
|
||||
$msgishtml = 1;
|
||||
|
||||
$mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived")."<br>\n";
|
||||
|
|
@ -2470,11 +2472,10 @@ class User extends CommonObject
|
|||
$mesg .= $outputlangs->transnoentitiesnoconv("YouMustClickToChange")." :<br>\n";
|
||||
$mesg .= '<a href="'.$url.'" rel="noopener">'.$outputlangs->transnoentitiesnoconv("ConfirmPasswordChange").'</a>'."<br>\n<br>\n";
|
||||
$mesg .= $outputlangs->transnoentitiesnoconv("ForgetIfNothing")."<br>\n<br>\n";
|
||||
|
||||
dol_syslog(get_class($this)."::send_password changelater is on, url=".$url);
|
||||
}
|
||||
|
||||
$trackid = 'use'.$this->id;
|
||||
$sendcontext = 'password';
|
||||
|
||||
$mailfile = new CMailFile(
|
||||
$subject,
|
||||
|
|
@ -2490,7 +2491,9 @@ class User extends CommonObject
|
|||
$msgishtml,
|
||||
'',
|
||||
'',
|
||||
$trackid
|
||||
$trackid,
|
||||
'',
|
||||
$sendcontext
|
||||
);
|
||||
|
||||
if ($mailfile->sendfile()) {
|
||||
|
|
|
|||
|
|
@ -142,12 +142,12 @@ if (empty($reshook)) {
|
|||
$messagewarning .= '</div>';
|
||||
|
||||
if ($result <= 0 && $edituser->error == 'USERNOTFOUND') {
|
||||
usleep(20000); // add delay to simulate setPassword and send_password actions delay (0.02s)
|
||||
usleep(20000); // add delay to simulate setPassword() and send_password() actions delay (0.02s)
|
||||
$message .= $messagewarning;
|
||||
$username = '';
|
||||
} else {
|
||||
if (empty($edituser->email)) {
|
||||
usleep(20000); // add delay to simulate setPassword and send_password actions delay (0.02s)
|
||||
usleep(20000); // add delay to simulate setPassword() and send_password() actions delay (0.02s)
|
||||
$message .= $messagewarning;
|
||||
} else {
|
||||
$newpassword = $edituser->setPassword($user, '', 1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue