custom pages clean up: remove unnecessary requires

skala
Laurent Opprecht 14 years ago
parent 9c962b3354
commit 21683bf5ed
  1. 1
      custompages/first_login.php
  2. 7
      index.php
  3. 14
      main/auth/inscription.php
  4. 13
      main/auth/lostPassword.php
  5. 2
      main/inc/lib/autoload.class.php
  6. 2
      main/inc/lib/conditional_login.class.php
  7. 5
      main/inc/lib/conditionallogin.lib.php
  8. 82
      main/inc/lib/custom_pages.class.php
  9. 37
      main/inc/lib/custompages.lib.php
  10. 329
      main/inc/lib/login.lib.php
  11. 5
      main/inc/lib/login_redirection.class.php
  12. 7
      main/inc/lib/loginredirection.lib.php
  13. 6
      main/inc/lib/main_api.lib.php
  14. 1
      main/inc/local.inc.php

@ -1,7 +1,6 @@
<?php <?php
require_once('language.php'); require_once('language.php');
require_once(dirname(__FILE__).'/../main/inc/global.inc.php'); require_once(dirname(__FILE__).'/../main/inc/global.inc.php');
//require_once (api_get_path(LIBRARY_PATH).'conditionallogin.lib.php'); moved to autologin
require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php'); require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
if (! isset($_SESSION['conditional_login']['uid'])) if (! isset($_SESSION['conditional_login']['uid']))

@ -79,16 +79,15 @@ if (api_get_setting('allow_terms_conditions') == 'true') {
unset($_SESSION['info_current_user']); unset($_SESSION['info_current_user']);
} }
//If we are not logged in and customapages activated //If we are not logged in and customapages activated
if (!api_get_user_id() && api_get_setting('use_custom_pages') == 'true' ) if (!api_get_user_id() && CustomPages::enabled())
{ {
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
if(Request::get('loggedout')) if(Request::get('loggedout'))
{ {
CustomPages::displayPage('loggedout'); CustomPages::display(CustomPages::LOGGED_OUT);
} }
else else
{ {
CustomPages::displayPage('index-unlogged'); CustomPages::display(CustomPages::INDEX_UNLOGGED);
} }
} }

@ -14,7 +14,7 @@ require_once '../inc/global.inc.php';
require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php'; require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH).'legal.lib.php'; require_once api_get_path(LIBRARY_PATH).'legal.lib.php';
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; //require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';moved to autoload
if (!empty($_SESSION['user_language_choice'])) { if (!empty($_SESSION['user_language_choice'])) {
$user_selected_language = $_SESSION['user_language_choice']; $user_selected_language = $_SESSION['user_language_choice'];
@ -277,7 +277,7 @@ if (is_array($extra_data)) {
$form->setDefaults($defaults); $form->setDefaults($defaults);
if (api_get_setting('use_custom_pages') != 'true') { if (!CustomPages::enabled()) {
// Load terms & conditions from the current lang // Load terms & conditions from the current lang
if (api_get_setting('allow_terms_conditions') == 'true') { if (api_get_setting('allow_terms_conditions') == 'true') {
$get = array_keys($_GET); $get = array_keys($_GET);
@ -528,7 +528,7 @@ if ($form->validate()) {
// 3. exit the page // 3. exit the page
unset($user_id); unset($user_id);
if (api_get_setting('use_custom_pages') != 'true') { if (!CustomPages::enabled()) {
Display :: display_footer(); Display :: display_footer();
} }
exit; exit;
@ -610,14 +610,14 @@ if ($form->validate()) {
// ?uidReset=true&uidReq=$_user['user_id'] // ?uidReset=true&uidReq=$_user['user_id']
$display_text .= '<form action="'. $action_url. '" method="post">'. "\n". '<button type="submit" class="next" name="next" value="'. get_lang('Next',null,$_user['language']). '" validationmsg=" '. get_lang('Next',null,$_user['language']). ' ">'. $button_text. '</button>'. "\n". '</form><br />'. "\n"; $display_text .= '<form action="'. $action_url. '" method="post">'. "\n". '<button type="submit" class="next" name="next" value="'. get_lang('Next',null,$_user['language']). '" validationmsg=" '. get_lang('Next',null,$_user['language']). ' ">'. $button_text. '</button>'. "\n". '</form><br />'. "\n";
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
CustomPages::displayPage('registration-feedback', array('info' => $display_text)); CustomPages::display(CustomPages::REGISTRATION_FEEDBACK, array('info' => $display_text));
} }
echo $display_text; echo $display_text;
} else { } else {
// Custom pages // Custom pages
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
CustomPages::displayPage('registration', array('form' => $form)); CustomPages::display(CustomPages::REGISTRATION, array('form' => $form));
} else { } else {
$form->display(); $form->display();
} }

@ -23,19 +23,18 @@ $language_file = array('registration', 'index');
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'login.lib.php'; require_once api_get_path(LIBRARY_PATH).'login.lib.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; //require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';moved to autoload
// Custom pages // Custom pages
// Had to move the form handling in here, because otherwise there would // Had to move the form handling in here, because otherwise there would
// already be some display output. // already be some display output.
global $_configuration; global $_configuration;
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
//Reset Password when user goes to the link //Reset Password when user goes to the link
if ($_GET['reset'] && $_GET['id']){ if ($_GET['reset'] && $_GET['id']){
$mesg = Login::reset_password($_GET["reset"], $_GET["id"], true); $mesg = Login::reset_password($_GET["reset"], $_GET["id"], true);
CustomPages::displayPage('index-unlogged', array('info' => $mesg)); CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => $mesg));
} }
//Check email/username and do the right thing //Check email/username and do the right thing
@ -75,12 +74,12 @@ if (api_get_setting('use_custom_pages') == 'true') {
Login::send_password_to_user($user, $by_username); Login::send_password_to_user($user, $by_username);
} }
} else { } else {
CustomPages::displayPage('lostpassword',array('error' => get_lang('NoUserAccountWithThisEmailAddress'))); CustomPages::display(CustomPages::LOST_PASSWORD, array('error' => get_lang('NoUserAccountWithThisEmailAddress')));
} }
} else { } else {
CustomPages::displayPage('lostpassword'); CustomPages::display(CustomPages::LOGGED_OUT);
} }
CustomPages::displayPage('index-unlogged', array('info' => get_lang('YourPasswordHasBeenEmailed'))); CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => get_lang('YourPasswordHasBeenEmailed')));
} }
$tool_name = get_lang('LostPassword'); $tool_name = get_lang('LostPassword');

@ -119,7 +119,7 @@ class Autoload
$result['CourseSession'] = '/main/coursecopy/classes/CourseSession.class.php'; $result['CourseSession'] = '/main/coursecopy/classes/CourseSession.class.php';
$result['CsvReader'] = '/main/inc/lib/system/io/csv_reader.class.php'; $result['CsvReader'] = '/main/inc/lib/system/io/csv_reader.class.php';
$result['CsvWriter'] = '/main/inc/lib/system/io/csv_writer.class.php'; $result['CsvWriter'] = '/main/inc/lib/system/io/csv_writer.class.php';
$result['CustomPages'] = '/main/inc/lib/custompages.lib.php'; $result['CustomPages'] = '/main/inc/lib/custom_pages.class.php';
$result['DashboardManager'] = '/main/inc/lib/dashboard.lib.php'; $result['DashboardManager'] = '/main/inc/lib/dashboard.lib.php';
$result['DataForm'] = '/main/gradebook/lib/fe/dataform.class.php'; $result['DataForm'] = '/main/gradebook/lib/fe/dataform.class.php';
$result['Debug'] = '/main/inc/lib/debug.lib.php'; $result['Debug'] = '/main/inc/lib/debug.lib.php';

@ -22,9 +22,7 @@ class ConditionalLogin {
} }
public static function login() { public static function login() {
//require_once api_get_path(LIBRARY_PATH).'loginredirection.lib.php'; moved to autologin
$_SESSION['conditional_login']['can_login'] = true; $_SESSION['conditional_login']['can_login'] = true;
LoginRedirection::redirect(); LoginRedirection::redirect();
exit();
} }
} }

@ -1,5 +0,0 @@
<?php
/**
* Added to autologin
* moved to conditional_login.class.php
*/

@ -0,0 +1,82 @@
<?php
/**
* Used to implement the loading of custom pages
*
* @license see /license.txt
* @author 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
class CustomPages
{
const INDEX_LOGGED = 'index-logged';
const INDEX_UNLOGGED = 'index-unlogged';
const LOGGED_OUT = 'loggedout';
const REGISTRATION_FEEDBACK = 'registration-feedback';
const REGISTRATION = 'registration';
const LOST_PASSWORD = 'lostpassword';
/**
* Returns true if custom pages are enabled. False otherwise.
* @return bool
*/
public static function enabled()
{
return api_get_setting('use_custom_pages') == 'true';
}
/**
* Returns the path to a custom page.
*
* @param string $name
* @return string
*/
public static function path($name = '')
{
return api_get_path(SYS_PATH) . 'custompages/' . $name;
}
/**
* If enabled display a custom page and exist. Otherwise log error and returns.
*
* @param string $page_name
* @param array $content used to path data to the custom page
*/
public static function display($page_name, $content = array())
{
if (!self::enabled()) {
return false;
}
$file = self::path($page_name . '.php');
if (file_exists($file)) {
include($file);
exit;
} else {
error_log('CustomPages::displayPage : could not read file ' . $file_name);
}
}
/**
* Does not look like this function is being used is being used
*
* @param type $url_id
* @return string
*/
public static function getURLImages($url_id = null)
{
if (is_null($url_id)) {
$url = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$url_id = UrlManager::get_url_id($url);
}
$url_images_dir = api_get_path(SYS_PATH) . 'custompages/url-images/';
$images = array();
for ($img_id = 1; $img_id <= 3; $img_id++) {
if (file_exists($url_images_dir . $url_id . '_url_image_' . $img_id . '.png')) {
$images[] = api_get_path(WEB_PATH) . 'custompages/url-images/' . $url_id . '_url_image_' . $img_id . '.png';
}
}
return $images;
}
}

@ -1,37 +0,0 @@
<?php
// Custom Pages lib
// Used to implement the loading of custom pages
// 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
class CustomPages {
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)) {
include($file_name);
exit;
}
else {
error_log('CustomPages::displayPage : could not read file '.$file_name);
}
}
public static function getURLImages($url_id = null) {
if (is_null($url_id)) {
$url = 'http://'.$_SERVER['HTTP_HOST'].'/';
$url_id = UrlManager::get_url_id($url);
}
$url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
$images = array();
for ($img_id = 1; $img_id <= 3; $img_id++) {
if (file_exists($url_images_dir.$url_id.'_url_image_'.$img_id.'.png')) {
$images[] = api_get_path(WEB_PATH).'custompages/url-images/'.$url_id.'_url_image_'.$img_id.'.png';
}
}
return $images;
}
}
?>

@ -1,126 +1,132 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Code library for login process * Code library for login process
* *
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
* @author Julio Montoya <gugli100@gmail.com> * @author Julio Montoya <gugli100@gmail.com>
* @package chamilo.login * @package chamilo.login
*/ */
/** /**
* Class * Class
* @package chamilo.login * @package chamilo.login
*/ */
class Login class Login
{ {
/**
* Get user account list /**
* * Get user account list
* @param unknown_type $user *
* @param boolean $reset * @param unknown_type $user
* @param boolean $by_username * @param boolean $reset
* @return unknown * @param boolean $by_username
*/ * @return unknown
public static function get_user_account_list($user, $reset = false, $by_username = false) { */
global $_configuration; public static function get_user_account_list($user, $reset = false, $by_username = false)
{
global $_configuration;
//$portal_url = $_configuration['root_web']; //$portal_url = $_configuration['root_web'];
$portal_url = api_get_path(WEB_PATH); $portal_url = api_get_path(WEB_PATH);
if ($_configuration['multiple_access_urls']) { if ($_configuration['multiple_access_urls']) {
$access_url_id = api_get_current_access_url_id(); $access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1 ) { if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id); $url = api_get_access_url($access_url_id);
$portal_url = $url['url']; $portal_url = $url['url'];
} }
} }
if ($reset) { if ($reset) {
if ($by_username) { if ($by_username) {
$secret_word = self::get_secret_word($user['email']); $secret_word = self::get_secret_word($user['email']);
if ($reset) { if ($reset) {
$reset_link = $portal_url."main/auth/lostPassword.php?reset=".$secret_word."&id=".$user['uid']; $reset_link = $portal_url . "main/auth/lostPassword.php?reset=" . $secret_word . "&id=" . $user['uid'];
} else { } else {
$reset_link = get_lang('Pass')." : $user[password]"; $reset_link = get_lang('Pass') . " : $user[password]";
} }
$user_account_list = get_lang('YourRegistrationData')." : \n".get_lang('UserName').' : '.$user['loginName']."\n".get_lang('ResetLink').' : '.$reset_link.''; $user_account_list = get_lang('YourRegistrationData') . " : \n" . get_lang('UserName') . ' : ' . $user['loginName'] . "\n" . get_lang('ResetLink') . ' : ' . $reset_link . '';
if ($user_account_list) { if ($user_account_list) {
$user_account_list = "\n-----------------------------------------------\n" . $user_account_list; $user_account_list = "\n-----------------------------------------------\n" . $user_account_list;
} }
} else { } else {
foreach ($user as $this_user) { foreach ($user as $this_user) {
$secret_word = self::get_secret_word($this_user['email']); $secret_word = self::get_secret_word($this_user['email']);
if ($reset) { if ($reset) {
$reset_link = $portal_url."main/auth/lostPassword.php?reset=".$secret_word."&id=".$this_user['uid']; $reset_link = $portal_url . "main/auth/lostPassword.php?reset=" . $secret_word . "&id=" . $this_user['uid'];
} else { } else {
$reset_link = get_lang('Pass')." : $this_user[password]"; $reset_link = get_lang('Pass') . " : $this_user[password]";
} }
$user_account_list[] = get_lang('YourRegistrationData')." : \n".get_lang('UserName').' : '.$this_user['loginName']."\n".get_lang('ResetLink').' : '.$reset_link.''; $user_account_list[] = get_lang('YourRegistrationData') . " : \n" . get_lang('UserName') . ' : ' . $this_user['loginName'] . "\n" . get_lang('ResetLink') . ' : ' . $reset_link . '';
} }
if ($user_account_list) { if ($user_account_list) {
$user_account_list = implode("\n-----------------------------------------------\n", $user_account_list); $user_account_list = implode("\n-----------------------------------------------\n", $user_account_list);
} }
} }
} else { } else {
if (!$by_username) { if (!$by_username) {
$user = $user[0]; $user = $user[0];
} }
$reset_link = get_lang('Pass')." : $user[password]"; $reset_link = get_lang('Pass') . " : $user[password]";
$user_account_list = get_lang('YourRegistrationData')." : \n".get_lang('UserName').' : '.$user['loginName']."\n".$reset_link.''; $user_account_list = get_lang('YourRegistrationData') . " : \n" . get_lang('UserName') . ' : ' . $user['loginName'] . "\n" . $reset_link . '';
} }
return $user_account_list; return $user_account_list;
} }
/** /**
* This function sends the actual password to the user * This function sends the actual password to the user
* *
* @param unknown_type $user * @param unknown_type $user
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
*/ */
public static function send_password_to_user($user, $by_username = false) { public static function send_password_to_user($user, $by_username = false)
global $_configuration; {
$email_subject = "[".api_get_setting('siteName')."] ".get_lang('LoginRequest'); // SUBJECT 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, false, $by_username); // BODY if ($by_username) { // Show only for lost password
$email_to = $user['email']; $user_account_list = self::get_user_account_list($user, false, $by_username); // BODY
} else { $email_to = $user['email'];
$user_account_list = self::get_user_account_list($user); // BODY } else {
$email_to = $user[0]['email']; $user_account_list = self::get_user_account_list($user); // BODY
} $email_to = $user[0]['email'];
}
$portal_url = $_configuration['root_web'];
if ($_configuration['multiple_access_urls']) { $portal_url = $_configuration['root_web'];
$access_url_id = api_get_current_access_url_id(); if ($_configuration['multiple_access_urls']) {
if ($access_url_id != -1 ) { $access_url_id = api_get_current_access_url_id();
$url = api_get_access_url($access_url_id); if ($access_url_id != -1) {
$portal_url = $url['url']; $url = api_get_access_url($access_url_id);
} $portal_url = $url['url'];
} }
}
$email_body = get_lang('YourAccountParam')." ".$portal_url."\n\n$user_account_list";
// SEND MESSAGE $email_body = get_lang('YourAccountParam') . " " . $portal_url . "\n\n$user_account_list";
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); // SEND MESSAGE
$email_admin = api_get_setting('emailAdministrator'); $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) {
return get_lang('your_password_has_been_reset'); if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
} else { return get_lang('your_password_has_been_reset');
return get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".</p>"; } else {
} return get_lang('SystemUnableToSendEmailContact') . ' ' . Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')) . ".</p>";
} }
}
/**
* Handle encrypted password, send an email to a user with his password /**
* * Handle encrypted password, send an email to a user with his password
* @param int user id *
* @param bool $by_username * @param int user id
* * @param bool $by_username
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University *
*/ * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
public static function handle_encrypted_password($user, $by_username = false) { */
public static function handle_encrypted_password($user, $by_username = false)
{
global $_configuration; global $_configuration;
$email_subject = "[".api_get_setting('siteName')."] ".get_lang('LoginRequest'); // SUBJECT $email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest'); // SUBJECT
if ($by_username) { // Show only for lost password if ($by_username) { // Show only for lost password
$user_account_list = self::get_user_account_list($user, true, $by_username); // BODY $user_account_list = self::get_user_account_list($user, true, $by_username); // BODY
@ -131,67 +137,72 @@ class Login
} }
$secret_word = self::get_secret_word($email_to); $secret_word = self::get_secret_word($email_to);
$email_body = get_lang('DearUser')." :\n".get_lang('password_request')."\n"; $email_body = get_lang('DearUser') . " :\n" . get_lang('password_request') . "\n";
$email_body .= $user_account_list."\n-----------------------------------------------\n\n"; $email_body .= $user_account_list . "\n-----------------------------------------------\n\n";
$email_body .= get_lang('PasswordEncryptedForSecurity'); $email_body .= get_lang('PasswordEncryptedForSecurity');
$email_body .= "\n\n".get_lang('Formula').",\n".api_get_setting('administratorName')." ".api_get_setting('administratorSurname')."\n".get_lang('PlataformAdmin')." - ".api_get_setting('siteName'); $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); $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'); $email_admin = api_get_setting('emailAdministrator');
if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) { if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
return get_lang('YourPasswordHasBeenEmailed'); return get_lang('YourPasswordHasBeenEmailed');
} else { } else {
Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed')); Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));
} }
} else { } else {
$message = get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".</p>"; $message = get_lang('SystemUnableToSendEmailContact') . ' ' . Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')) . ".</p>";
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
return $message; return $message;
} else { } else {
Display::display_error_message($message, false); Display::display_error_message($message, false);
} }
} }
} }
/** /**
* Gets the secret word * Gets the secret word
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
*/ */
public static function get_secret_word($add) { public static function get_secret_word($add)
global $_configuration; {
return $secret_word = md5($_configuration['security_key'].$add); global $_configuration;
} return $secret_word = md5($_configuration['security_key'] . $add);
}
/**
* Resets a password /**
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University * Resets a password
*/ * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
public static function reset_password($secret, $id, $by_username = false) { */
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); public static function reset_password($secret, $id, $by_username = false)
$id = intval($id); {
$sql = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email FROM ".$tbl_user." WHERE user_id=$id"; $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$result = Database::query($sql); $id = intval($id);
$num_rows = Database::num_rows($result); $sql = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email FROM " . $tbl_user . " WHERE user_id=$id";
$result = Database::query($sql);
if ($result && $num_rows > 0) { $num_rows = Database::num_rows($result);
$user = Database::fetch_array($result);
} else { if ($result && $num_rows > 0) {
return get_lang('CouldNotResetPassword'); $user = Database::fetch_array($result);
} } else {
return get_lang('CouldNotResetPassword');
if (self::get_secret_word($user['email']) == $secret) { // OK, secret word is good. Now change password and mail it. }
$user['password'] = api_generate_password();
$crypted = $user['password']; if (self::get_secret_word($user['email']) == $secret) { // OK, secret word is good. Now change password and mail it.
$crypted = api_get_encrypted_password($crypted); $user['password'] = api_generate_password();
$sql = "UPDATE ".$tbl_user." SET password='$crypted' WHERE user_id = $id"; $crypted = $user['password'];
$result = Database::query($sql); $crypted = api_get_encrypted_password($crypted);
return self::send_password_to_user($user, $by_username); $sql = "UPDATE " . $tbl_user . " SET password='$crypted' WHERE user_id = $id";
} else { $result = Database::query($sql);
return get_lang('NotAllowed'); return self::send_password_to_user($user, $by_username);
} } else {
} return get_lang('NotAllowed');
}
}
} }

@ -52,9 +52,8 @@ Class LoginRedirection {
} }
// Custom pages // Custom pages
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; CustomPages::display(CustomPages::INDEX_LOGGED);
CustomPages::displayPage('index-logged');
} }
header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param); header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param);
exit(); exit();

@ -1,7 +0,0 @@
<?php
/**
* Added to autologin
* @see login_redirection.class.php
*
*/

@ -2636,11 +2636,9 @@ function api_not_allowed($print_headers = false, $message = null) {
$course = api_get_course_id(); $course = api_get_course_id();
global $this_section; global $this_section;
if (api_get_setting('use_custom_pages') == 'true' && !isset($_SESSION['_user']['user_id'])) { if (CustomPages::enabled() && !isset($_SESSION['_user']['user_id'])) {
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI']; $_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; CustomPages::display(CustomPages::INDEX_UNLOGGED);
CustomPages::displayPage('index-unlogged');
exit;
} }
$origin = isset($_GET['origin']) ? $_GET['origin'] : ''; $origin = isset($_GET['origin']) ? $_GET['origin'] : '';

@ -670,7 +670,6 @@ if (isset($uidReset) && $uidReset) { // session data refresh requested
//If we just want to reset info without redirecting user //If we just want to reset info without redirecting user
unset($_SESSION['noredirection']); unset($_SESSION['noredirection']);
} else { } else {
//require_once api_get_path(LIBRARY_PATH).'loginredirection.lib.php'; moved to autologin
LoginRedirection::redirect(); LoginRedirection::redirect();
} }
} }

Loading…
Cancel
Save