6521 : generic lost_password custompage

skala
Noel Dieschburg 13 years ago
parent 213d1576e4
commit ef4fbd56ab
  1. 19
      custompages/index-unlogged.php
  2. 12
      custompages/lostpassword.php
  3. 95
      main/auth/lostPassword.php
  4. 2
      main/inc/lib/custompages.lib.php
  5. 71
      main/inc/lib/login.lib.php

@ -52,20 +52,22 @@ if (isset($_GET['loginFailed'])){
</head>
<body>
<div id="backgroundimage">
<img src="/custompages/images/page-background.png" class="backgroundimage" />
<img src="<?php echo api_get_path(WEB_PATH)?>/custompages/images/page-background.png" class="backgroundimage" />
</div>
<div id="wrapper">
<div id="header">
<img src="/custompages/images/header.png" alt="Logo" />
<img src="<?php echo api_get_path(WEB_PATH)?>/custompages/images/header.png" alt="Logo" />
</div> <!-- #header -->
<div id="login-form-box" class="form-box">
<?php if ($values['reset_password']) {
echo '<div id="login-form-info" class="form-info">'.cblue_get_lang('your_password_has_been_reset').'</div>';
}?>
<div id="login-form-info" class="form-info">
<?php if (isset($content['info']) && !empty($content['info'] )) {
echo $content['info'];
}?>
</div>
<?php if (isset($error_message)) {
echo '<div id="login-form-info" class="form-error">'.$error_message.'</div>';
}?>
<form id="login-form" class="form" action="/index.php" method="post">
<form id="login-form" class="form" action="<?php echo api_get_path(WEB_PATH)?>index.php" method="post">
<div>
<label for="login">*<?php echo cblue_get_lang('User');?></label>
<input name="login" type="text" /><br />
@ -77,11 +79,12 @@ if (isset($_GET['loginFailed'])){
<span><?php echo cblue_get_lang('LoginEnter');?></span>
</div> <!-- #form-submit -->
<div id="links">
<a href="main/auth/lostPassword.php"><?php echo cblue_get_lang('langLostPassword')?></a>
<a href="<?php echo api_get_path(WEB_PATH)?>main/auth/inscription.php"><?php echo cblue_get_lang('langReg')?></a><br />
<a href="<?php echo api_get_path(WEB_PATH)?>main/auth/lostPassword.php"><?php echo cblue_get_lang('langLostPassword')?></a>
</div>
</div> <!-- #form -->
<div id="footer">
<img src="/custompages/images/footer.png" />
<img src="<?php echo api_get_path(WEB_PATH)?>/custompages/images/footer.png" />
</div> <!-- #footer -->
</div> <!-- #wrapper -->
</body>

@ -32,10 +32,16 @@ require_once('language.php');
<div id="header">
<img src="../../custompages/images/header.png" alt="Ambassador logo" />
</div> <!-- #header -->
<?php echo '<div id="registration-form-info" class="form-info">'.cblue_get_lang('lang_enter_email_and_well_send_you_password').'</div>'; ?>
<div id="registration-form-info" class="form-info">
<?php if(isset($content['error']) && !empty($content['error'])){
echo $content['info'];
} else {
echo cblue_get_lang('lang_enter_email_and_well_send_you_password');
}?>
</div>
<div id="lostpassword-form-box" class="form-box">
<?php if (isset($form_error) && !empty($form_error)) {
echo '<div id="registration-form-error" class="form-error"><ul>'.$form_error.'</ul></div>';
<?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>

@ -15,7 +15,7 @@
* @package chamilo.auth
*/
// name of the language file that needs to be included
$language_file = 'registration';
$language_file = array('registration', 'index');
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'login.lib.php';
@ -26,50 +26,59 @@ require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
// Custom pages
// Had to move the form handling in here, because otherwise there would already be some display output.
if (api_get_setting('use_custom_pages') == 'true') {
if (isset ($_POST['user']) && isset ($_POST['email'])) {
$user = $_POST['user'];
$email = $_POST['email'];
$condition = '';
if (!empty($email)) {
$condition = " AND LOWER(email) = '".Database::escape_string($email)."' ";
}
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$query = " SELECT user_id AS uid, lastname AS lastName, firstname AS firstName,
username AS loginName, password, email, status AS status,
official_code, phone, picture_uri, creator_id
FROM ".$tbl_user."
WHERE ( username = '".Database::escape_string($user)."' $condition ) ";
$result = Database::query($query);
$num_rows = Database::num_rows($result);
if ($result && $num_rows > 0) {
if ($num_rows > 1) {
$by_username = false; // more than one user
while ($data = Database::fetch_array($result)) {
$user[] = $data;
}
} else {
$by_username = true; // single user (valid user + email)
$user = Database::fetch_array($result);
}
if ($userPasswordCrypted != 'none') {
Login::handle_encrypted_password($user, $by_username);
} else {
Login::send_password_to_user($user, $by_username);
}
} else {
Display::display_error_message(get_lang('NoUserAccountWithThisEmailAddress'));
}
$msg = Login::reset_password($_GET["reset"], $_GET["id"], true);
CustomPages::displayPage('lostpassword-feedback');
}
else {
CustomPages::displayPage('lostpassword');
}
//Reset Password when user goes to the link
if($_GET['reset'] && $_GET['id']){
$mesg = Login::reset_password($_GET["reset"], $_GET["id"], true);
CustomPages::displayPage('index-unlogged', array('info' => $mesg));
}
//Check email/username and do the right thing
if (isset ($_POST['user']) && isset ($_POST['email'])) {
$user = $_POST['user'];
$email = $_POST['email'];
$condition = '';
if (!empty($email)) {
$condition = " AND LOWER(email) = '".Database::escape_string($email)."' ";
}
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$query = " SELECT user_id AS uid, lastname AS lastName, firstname AS firstName,
username AS loginName, password, email, status AS status,
official_code, phone, picture_uri, creator_id
FROM ".$tbl_user."
WHERE ( username = '".Database::escape_string($user)."' $condition ) ";
$result = Database::query($query);
$num_rows = Database::num_rows($result);
if ($result && $num_rows > 0) {
if ($num_rows > 1) {
$by_username = false; // more than one user
while ($data = Database::fetch_array($result)) {
$user[] = $data;
}
} else {
$by_username = true; // single user (valid user + email)
$user = Database::fetch_array($result);
}
if ($userPasswordCrypted != 'none') {
//Send email with secret link to user
Login::handle_encrypted_password($user, $by_username);
} else {
Login::send_password_to_user($user, $by_username);
}
} else {
CustomPages::displayPage('lostpassword',array('error' => get_lang('NoUserAccountWithThisEmailAddress')));
}
}
else {
CustomPages::displayPage('lostpassword');
}
CustomPages::displayPage('index-unlogged', array('info' => get_lang('YourPasswordHasBeenEmailed')));
}
$tool_name = get_lang('LostPassword');
Display :: display_header($tool_name);

@ -7,7 +7,7 @@ require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
class CustomPages {
public static function displayPage($page_name) {
public static function displayPage($page_name, $content=array()) {
$pages_dir = api_get_path(SYS_PATH).'custompages/';
$file_name = $pages_dir.$page_name.'.php';
if (file_exists($file_name)) {

@ -104,7 +104,10 @@ class Login
$email_admin = api_get_setting('emailAdministrator');
if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));
if (api_get_setting('use_custom_pages') == 'true')
return get_lang('your_password_has_been_reset');
else
Display::display_confirmation_message(get_lang('your_password_has_been_reset'));
} else {
$message = get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".</p>";
}
@ -118,35 +121,41 @@ class Login
*
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
*/
public static function handle_encrypted_password($user, $by_username = false) {
global $_configuration;
$email_subject = "[".api_get_setting('siteName')."] ".get_lang('LoginRequest'); // SUBJECT
if ($by_username) { // Show only for lost password
$user_account_list = self::get_user_account_list($user, true, $by_username); // BODY
$email_to = $user['email'];
} else {
$user_account_list = self::get_user_account_list($user, true); // BODY
$email_to = $user[0]['email'];
}
$secret_word = self::get_secret_word($email_to);
$email_body = get_lang('DearUser')." :\n".get_lang('password_request')."\n";
$email_body .= $user_account_list."\n-----------------------------------------------\n\n";
$email_body .= get_lang('PasswordEncryptedForSecurity');
//$email_body .= "\n\n".get_lang('Formula').",\n".get_lang('PlataformAdmin');
$email_body .= "\n\n".get_lang('Formula').",\n".api_get_setting('administratorName')." ".api_get_setting('administratorSurname')."\n".get_lang('PlataformAdmin')." - ".api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));
} else {
$message = get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".</p>";
Display::display_error_message($message, false);
}
}
public static function handle_encrypted_password($user, $by_username = false) {
global $_configuration;
$email_subject = "[".api_get_setting('siteName')."] ".get_lang('LoginRequest'); // SUBJECT
if ($by_username) { // Show only for lost password
$user_account_list = self::get_user_account_list($user, true, $by_username); // BODY
$email_to = $user['email'];
} else {
$user_account_list = self::get_user_account_list($user, true); // BODY
$email_to = $user[0]['email'];
}
$secret_word = self::get_secret_word($email_to);
$email_body = get_lang('DearUser')." :\n".get_lang('password_request')."\n";
$email_body .= $user_account_list."\n-----------------------------------------------\n\n";
$email_body .= get_lang('PasswordEncryptedForSecurity');
//$email_body .= "\n\n".get_lang('Formula').",\n".get_lang('PlataformAdmin');
$email_body .= "\n\n".get_lang('Formula').",\n".api_get_setting('administratorName')." ".api_get_setting('administratorSurname')."\n".get_lang('PlataformAdmin')." - ".api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
if (api_get_setting('use_custom_pages') == 'true')
return get_lang('YourPasswordHasBeenEmailed');
else
Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));
} else {
$message = get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".</p>";
if (api_get_setting('use_custom_pages') == 'true')
return $message;
else
Display::display_error_message($message, false);
}
}
/**
* Gets the secret word
@ -185,4 +194,4 @@ class Login
return get_lang('NotAllowed');
}
}
}
}

Loading…
Cancel
Save