Skip to content

Commit

Permalink
FIX #401 alternative to PHPMailer with sendmail
Browse files Browse the repository at this point in the history
Co-authored-by: bazooka07 <[email protected]>
  • Loading branch information
kazimentou and bazooka07 authored Apr 14, 2020
1 parent cc11ac5 commit 6757c86
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions core/lib/class.plx.admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,55 +308,66 @@ public function editPassword($content) {
*
* @param loginOrMail user login or e-mail address
* @return string token to password reset
* @author Pedro "P3ter" CADETE
* @author Pedro "P3ter" CADETE, J.P. Pourrez aka bazooka07
**/
public function sendLostPasswordEmail($loginOrMail) {
/*
$mail = array();
$tokenExpiry = 24;
$lostPasswordToken = plxToken::getTokenPostMethod('', false);
$lostPasswordTokenExpiry = plxToken::generateTokenExperyDate($tokenExpiry);
$templateName = 'email-lostpassword-'.PLX_SITE_LANG.'.xml';
$error = false;

* */
if (!empty($loginOrMail) and plxUtils::testMail(false)) {
foreach($this->aUsers as $user_id => $user) {
if (($user['login'] == $loginOrMail OR $user['email'] == $loginOrMail) AND $user['active'] AND !$user['delete'] AND !empty($user['email'])) {
if(!$user['active'] or $user['delete'] or empty($user['email'])) { continue; }

if($user['login'] == $loginOrMail OR $user['email'] == $loginOrMail) {
// Attention à l'unicité des logins !!!
// token and e-mail creation
$mail = array();
$tokenExpiry = 24;
$lostPasswordToken = plxToken::generateToken();
$lostPasswordTokenExpiry = plxToken::generateTokenExperyDate($tokenExpiry);
$templateName = 'email-lostpassword-'.PLX_SITE_LANG.'.xml';

$placeholdersValues = array(
"##LOGIN##" => $user['login'],
"##URL_PASSWORD##" => $this->aConf['racine'].'core/admin/auth.php?action=changepassword&token='.$lostPasswordToken,
"##URL_EXPIRY##" => $tokenExpiry
);
if (($mail ['body'] = $this->aTemplates[$templateName]->getTemplateGeneratedContent($placeholdersValues)) != '1') {
if (!empty($this->aConf['title'])) {
$mail ['name'] = $this->aConf['title'];
$mail['subject'] = $this->aTemplates[$templateName]->getTemplateEmailSubject();

if(empty($this->aConf['email_method']) or $this->aConf['email_method'] == 'sendmail' or !method_exists(plxUtils, 'sendMailPhpMailer')) {
# fonction mail() intrinséque à PHP
$success = plxUtils::sendMail('', '', $user['email'], $mail['subject'], $mail['body']);
} else {
$mail ['name'] = $this->aTemplates[$templateName]->getTemplateEmailName();
# On utilise PHPMailer
if (!empty($this->aConf['title'])) {
$mail ['name'] = $this->aConf['title'];
} else {
$mail ['name'] = $this->aTemplates[$templateName]->getTemplateEmailName();
}
$mail ['from'] = $this->aTemplates[$templateName]->getTemplateEmailFrom();
// send the e-mail and if it is OK store the token
$success = plxUtils::sendMailPhpMailer($mail['name'], $mail['from'], $user['email'], $mail['subject'], $mail['body'], false, $this->aConf, false);
}
$mail ['from'] = $this->aTemplates[$templateName]->getTemplateEmailFrom();
$mail['subject'] = $this->aTemplates[$templateName]->getTemplateEmailSubject();
// send the e-mail and if it is OK store the token
if (plxUtils::sendMailPhpMailer($mail['name'], $mail['from'], $user['email'], $mail['subject'], $mail['body'], false, $this->aConf, false)) {

if (!empty($success)) {
$this->aUsers[$user_id]['password_token'] = $lostPasswordToken;
$this->aUsers[$user_id]['password_token_expiry'] = $lostPasswordTokenExpiry;
$this->editUsers($user_id, true);
return $lostPasswordToken;
}
else {
$error = true;
}
}
else {
$error = true;
}
break;
}
}
}

if ($error) {
$lostPasswordToken = '';
}

return $lostPasswordToken;
return '';
}

/**
Expand Down

0 comments on commit 6757c86

Please sign in to comment.