Fix sent duplicated messages on Lost Password page - refs BT#10376 #TMI

1.10.x
Angel Fernando Quiroz Campos 9 years ago
parent 9d37a654fa
commit aec05212b2
  1. 26
      custompages/lostpassword-dist.php
  2. 206
      main/auth/lostPassword.php
  3. 12
      main/inc/lib/custom_pages.class.php
  4. 16
      main/inc/lib/login.lib.php

@ -39,26 +39,14 @@ require_once('language.php');
<div id="header">
<img src="../../custompages/images/header.png" alt="Ambassador logo" />
</div> <!-- #header -->
<div id="registration-form-info" class="form-info">
<?php if(isset($content['error']) && !empty($content['error'])){
echo $content['info'];
} else {
echo custompages_get_lang('EnterEmailAndWeWillSendYouYourPassword');
}?>
</div>
<div id="lostpassword-form-box" class="form-box">
<?php if (isset($content['error']) && !empty($content['error'])) {
echo '<div id="registration-form-error" class="form-error"><ul>'.$content['error'].'</ul></div>';
}?>
<form id="lostpassword-form" class="form" action="lostPassword.php" method="post">
<div>
<label for="user">*<?php echo custompages_get_lang('LoginOrEmailAddress');?></label>
<input name="user" type="text" /><br />
</div>
</form>
<div id="lostpassword-form-submit" class="form-submit" onclick="document.forms['lostpassword-form'].submit();">
<span><?php echo custompages_get_lang('Send'); ?> </span>
</div> <!-- #form-submit -->
<?php
if (isset($content['info']) && !empty($content['info'])) {
echo '<div id="registration-form-error" class="form-error"><ul>' . $content['info'] . '</ul></div>';
}
echo isset($content['form']) ? $content['form'] : ''
?>
</div> <!-- #form -->
<div id="footer">
<img src="../../custompages/images/footer.png" />

@ -20,124 +20,132 @@ require_once '../inc/global.inc.php';
// Custom pages
// Had to move the form handling in here, because otherwise there would
// already be some display output.
global $_configuration;
if (CustomPages::enabled()) {
// Reset Password when user goes to the link
if (isset($_GET['reset']) && $_GET['reset'] &&
isset($_GET['id']) && $_GET['id']
) {
$mesg = Login::reset_password($_GET["reset"], $_GET["id"], true);
CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => $mesg));
// Forbidden to retrieve the lost password
if (api_get_setting('allow_lostpassword') == 'false') {
api_not_allowed(true);
}
$reset = Request::get('reset');
$userId = Request::get('id');
$this_section = SECTION_CAMPUS;
$tool_name = get_lang('LostPassword');
if ($reset && $userId) {
$messageText = Login::reset_password($reset, $userId, true);
if (CustomPages::enabled() && CustomPages::exists(CustomPages::INDEX_UNLOGGED)) {
CustomPages::display(
CustomPages::INDEX_UNLOGGED,
['info' => $messageText]
);
exit;
}
// Check email/username and do the right thing
if (isset($_POST['user'])) {
$usersRelatedToUsername = Login::get_user_accounts_by_username($_POST['user']);
if ($usersRelatedToUsername) {
$by_username = true;
foreach ($usersRelatedToUsername as $user) {
if ($_configuration['password_encryption'] != 'none') {
Login::handle_encrypted_password($user, $by_username);
} else {
Login::send_password_to_user($user, $by_username);
}
}
} else {
Display::addFlash(
Display::return_message($messageText)
);
header('Location: ' . api_get_path(WEB_PATH));
exit;
}
$form = new FormValidator('lost_password');
$form->addHeader($tool_name);
$form->addText('user', [get_lang('LoginOrEmailAddress'), get_lang('EnterEmailUserAndWellSendYouPassword')], true);
$form->addButtonSend(get_lang('Send'));
if ($form->validate()) {
$values = $form->exportValues();
$user = Login::get_user_accounts_by_username($values['user']);
if (!$user) {
$messageText = get_lang('NoUserAccountWithThisEmailAddress');
if (CustomPages::enabled() && CustomPages::exists(CustomPages::LOST_PASSWORD)) {
CustomPages::display(
CustomPages::LOST_PASSWORD,
array('error' => get_lang('NoUserAccountWithThisEmailAddress'))
['info' => $messageText]
);
exit;
}
} else {
CustomPages::display(CustomPages::LOST_PASSWORD);
Display::addFlash(
Display::return_message($messageText, 'error')
);
header('Location: ' . api_get_self());
exit;
}
CustomPages::display(
CustomPages::INDEX_UNLOGGED,
array('info' => get_lang('YourPasswordHasBeenEmailed'))
);
}
$passwordEncryption = api_get_configuration_value('password_encryption');
$tool_name = get_lang('LostPassword');
if ($passwordEncryption === 'none') {
$messageText = Login::send_password_to_user($user, true);
$this_section = SECTION_CAMPUS;
$tool_name = get_lang('LostPass');
if (CustomPages::enabled() && CustomPages::exists(CustomPages::INDEX_UNLOGGED)) {
CustomPages::display(
CustomPages::INDEX_UNLOGGED,
['info' => $messageText]
);
exit;
}
// Forbidden to retrieve the lost password
if (api_get_setting('allow_lostpassword') == 'false') {
api_not_allowed(true);
}
Display::addFlash(
Display::return_message($messageText)
);
header('Location: ' . api_get_path(WEB_PATH));
exit;
}
$formToString = '';
if (isset($_GET['reset']) && isset($_GET['id'])) {
$message = Display::return_message(
Login::reset_password($_GET["reset"], $_GET["id"], true),
'normal',
false
);
$message .= '<a href="'.api_get_path(WEB_CODE_PATH).'auth/lostPassword.php" class="btn btn-back" >'.get_lang('Back').'</a>';
Display::addFlash($message);
} else {
$form = new FormValidator('lost_password');
$form->addElement('header', $tool_name);
$form->addElement(
'text',
'user',
array(
get_lang('LoginOrEmailAddress'),
get_lang('EnterEmailUserAndWellSendYouPassword'),
),
array('size' => '40')
);
$form->addButtonSend(get_lang('Send'));
$userResetPasswordSetting = api_get_setting('user_reset_password');
// Setting the rules
$form->addRule('user', get_lang('ThisFieldIsRequired'), 'required');
if ($userResetPasswordSetting === 'true') {
$user = Database::getManager()
->getRepository('ChamiloUserBundle:User')
->find($user['uid']);
if ($form->validate()) {
$values = $form->exportValues();
Login::sendResetEmail($user, true);
$usersRelatedToUsername = Login::get_user_accounts_by_username(
$values['user']
if (CustomPages::enabled() && CustomPages::exists(CustomPages::INDEX_UNLOGGED)) {
CustomPages::display(
CustomPages::INDEX_UNLOGGED,
['info' => get_lang('CheckYourEmailAndFollowInstructions')]
);
exit;
}
header('Location: ' . api_get_path(WEB_PATH));
exit;
}
$messageText = Login::handle_encrypted_password($user, true);
if (CustomPages::enabled() && CustomPages::exists(CustomPages::INDEX_UNLOGGED)) {
CustomPages::display(
CustomPages::INDEX_UNLOGGED,
['info' => $messageText]
);
exit;
}
if ($usersRelatedToUsername) {
$by_username = true;
foreach ($usersRelatedToUsername as $user) {
if ($_configuration['password_encryption'] != 'none') {
$setting = api_get_setting('user_reset_password');
if ($setting === 'true') {
$userObj = Database::getManager()->getRepository('ChamiloUserBundle:User')->find($user['uid']);
Login::sendResetEmail($userObj);
} else {
$message = Login::handle_encrypted_password($user, $by_username);
Display::addFlash($message);
}
} else {
$message = Login::send_password_to_user($user, $by_username);
Display::addFlash($message);
}
}
} else {
Display::addFlash(
Display::return_message(
get_lang('NoUserAccountWithThisEmailAddress'),
'warning'
)
);
}
} else {
$formToString = $form->returnForm();
}
Display::addFlash(
Display::return_message($messageText)
);
header('Location: ' . api_get_path(WEB_PATH));
exit;
}
if (CustomPages::enabled() && CustomPages::exists(CustomPages::LOST_PASSWORD)) {
CustomPages::display(
CustomPages::LOST_PASSWORD,
['form' => $form->returnForm()]
);
exit;
}
$controller = new IndexManager($tool_name);
$controller->set_login_form();
$tpl = $controller->tpl;
$tpl->assign('form', $formToString);
$template = $tpl->get_template('auth/lost_password.tpl');
$tpl->display($template);
$controller->tpl->assign('form', $form->returnForm());
$template = $controller->tpl->get_template('auth/lost_password.tpl');
$controller->tpl->display($template);

@ -83,4 +83,16 @@ class CustomPages
return $images;
}
/**
* Check if exists the file for custom page
* @param string $pageName The name of custom page
* @return boolean
*/
public static function exists($pageName)
{
$fileName = self::path("$pageName.php");
return file_exists($fileName);
}
}

@ -165,11 +165,7 @@ class Login
);
if ($result == 1) {
if (CustomPages::enabled()) {
return get_lang('YourPasswordHasBeenEmailed');
} else {
return Display::return_message(get_lang('YourPasswordHasBeenEmailed'));
}
return get_lang('YourPasswordHasBeenEmailed');
} else {
$admin_email = Display:: encrypted_mailto_link(
api_get_setting('emailAdministrator'),
@ -180,18 +176,14 @@ class Login
);
$message = sprintf(get_lang('ThisPlatformWasUnableToSendTheEmailPleaseContactXForMoreInformation'), $admin_email);
if (CustomPages::enabled()) {
return $message;
} else {
return Display::return_message($message, 'error');
}
return $message;
}
}
/**
* @param User $user
*/
public function sendResetEmail(User $user)
public static function sendResetEmail(User $user)
{
//if (null === $user->getConfirmationToken()) {
$uniqueId = api_get_unique_id();
@ -861,7 +853,7 @@ class Login
$result = Database::query($query);
$num_rows = Database::num_rows($result);
if ($result && $num_rows > 0) {
return Database::store_result($result);
return Database::fetch_assoc($result);
}
return false;
}

Loading…
Cancel
Save