Skip to content

Instantly share code, notes, and snippets.

@bazooka07
Last active January 13, 2020 16:08
Show Gist options
  • Save bazooka07/2b4dfafb48706a673aba52879c83b11a to your computer and use it in GitHub Desktop.
Save bazooka07/2b4dfafb48706a673aba52879c83b11a to your computer and use it in GitHub Desktop.
Ré-écriture de plxAdmin::sendLostPasswordEmail pour pluxml.org
// A modifier dans le fichier core/lib/class.plx.admin.php
public function sendLostPasswordEmail($loginOrMail) {
if (!empty($loginOrMail) and plxUtils::testMail(false)) {
foreach($this->aUsers as $user_id => $user) {
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') {
$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 {
# 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);
}
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;
}
}
break;
}
}
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment