if(!class_exists('ForgotManagerPassword')) {
class ForgotManagerPassword{
function ForgotManagerPassword(){
$this->errors = array();
$this->checkLang();
}
function getLink() {
global $_lang;
$link = <<
{$_lang['forgot_password_email_instructions']}
{$_lang['forgot_password_email_fine_print']}
EOD; $mail = mail($to, $subject, $body, $headers); if(!$mail) { $this->errors[] = $_lang['error_sending_email']; } return $mail; } } function unblockUser($user_id) { global $modx, $_lang; $pre = $modx->db->config['table_prefix']; $modx->db->update(array('blocked'=>'', 'blockeduntil'=>''), "`{$pre}user_attributes`", "internalKey = '{$user_id}'"); if(!$modx->db->getAffectedRows()) { $this->errors[] = $_lang['user_doesnt_exist']; return; } return true; } function checkLang() { global $_lang; $eng = array(); $eng['forgot_your_password'] = 'Forgot your password?'; $eng['account_email'] = 'Account email'; $eng['send'] = 'Send'; $eng['password_change_request'] = 'Password change request'; $eng['forgot_password_email_intro'] = 'A request has been made to change the password on your account.'; $eng['forgot_password_email_link'] = 'Click here to complete the process.'; $eng['forgot_password_email_instructions'] = 'From there you will be able to change your password from the My Account menu.'; $eng['forgot_password_email_fine_print'] = '* The URL above will expire once you change your password or after today.'; $eng['error_sending_email'] = 'Error sending email'; $eng['could_not_find_user'] = 'Could not find user'; $eng['user_doesnt_exist'] = 'User does not exist'; $eng['email_sent'] = 'Email sent'; foreach($eng as $key=>$value) { if(empty($_lang[$key])) { $_lang[$key] = $value; } } } function getErrorOutput() { $outptut = ''; if($this->errors) { $output = ''.implode('', $this->errors).''; } return $output; } } } global $_lang; $output = ''; $event_name = $modx->Event->name; $action = (empty($_GET['action']) ? '' : $_GET['action']); $username = (empty($_GET['username']) ? '' : $_GET['username']); $to = (empty($_GET['email']) ? '' : $_GET['email']); $hash = (empty($_GET['hash']) ? '' : $_GET['hash']); $forgot = new ForgotManagerPassword(); if($event_name == 'OnManagerLoginFormRender') { switch($action) { case 'show_form': $output = $forgot->getForm(); break; case 'send_email': if($forgot->sendEmail($to)) { $output = $_lang['email_sent']; } break; default: $output = $forgot->getLink(); } if($forgot->errors) { $output = $forgot->getErrorOutput() . $forgot->getLink(); } } if($event_name == 'OnBeforeManagerLogin') { $user = $forgot->getUser(0, $username, '', $hash); if($user['id'] && !$forgot->errors) { $forgot->unblockUser($user['id']); } } if($event_name == 'OnManagerAuthentication' && $hash) { $user = $forgot->getUser(0, '', '', $hash); $output = ($user['id'] > 0 && !$forgot->errors); } $modx->Event->output($output);