diff --git a/custompages/first_login.php b/custompages/first_login.php index 643e7933f1..186ba17ff2 100644 --- a/custompages/first_login.php +++ b/custompages/first_login.php @@ -1,7 +1,6 @@ setDefaults($defaults); -if (api_get_setting('use_custom_pages') != 'true') { +if (!CustomPages::enabled()) { // Load terms & conditions from the current lang if (api_get_setting('allow_terms_conditions') == 'true') { $get = array_keys($_GET); @@ -528,7 +528,7 @@ if ($form->validate()) { // 3. exit the page unset($user_id); - if (api_get_setting('use_custom_pages') != 'true') { + if (!CustomPages::enabled()) { Display :: display_footer(); } exit; @@ -610,14 +610,14 @@ if ($form->validate()) { // ?uidReset=true&uidReq=$_user['user_id'] $display_text .= '
'. "\n". ''. "\n". '

'. "\n"; - if (api_get_setting('use_custom_pages') == 'true') { - CustomPages::displayPage('registration-feedback', array('info' => $display_text)); + if (CustomPages::enabled()) { + CustomPages::display(CustomPages::REGISTRATION_FEEDBACK, array('info' => $display_text)); } echo $display_text; } else { // Custom pages - if (api_get_setting('use_custom_pages') == 'true') { - CustomPages::displayPage('registration', array('form' => $form)); + if (CustomPages::enabled()) { + CustomPages::display(CustomPages::REGISTRATION, array('form' => $form)); } else { $form->display(); } diff --git a/main/auth/lostPassword.php b/main/auth/lostPassword.php index 9a4a305670..5842d083d2 100644 --- a/main/auth/lostPassword.php +++ b/main/auth/lostPassword.php @@ -23,19 +23,18 @@ $language_file = array('registration', 'index'); require_once '../inc/global.inc.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).'custompages.lib.php'; +//require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';moved to autoload // Custom pages // Had to move the form handling in here, because otherwise there would // already be some display output. global $_configuration; -if (api_get_setting('use_custom_pages') == 'true') { - +if (CustomPages::enabled()) { //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)); + CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => $mesg)); } //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); } } else { - CustomPages::displayPage('lostpassword',array('error' => get_lang('NoUserAccountWithThisEmailAddress'))); + CustomPages::display(CustomPages::LOST_PASSWORD, array('error' => get_lang('NoUserAccountWithThisEmailAddress'))); } } 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'); diff --git a/main/inc/lib/autoload.class.php b/main/inc/lib/autoload.class.php index 5ed846305e..3a744438ea 100644 --- a/main/inc/lib/autoload.class.php +++ b/main/inc/lib/autoload.class.php @@ -119,7 +119,7 @@ class Autoload $result['CourseSession'] = '/main/coursecopy/classes/CourseSession.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['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['DataForm'] = '/main/gradebook/lib/fe/dataform.class.php'; $result['Debug'] = '/main/inc/lib/debug.lib.php'; diff --git a/main/inc/lib/conditional_login.class.php b/main/inc/lib/conditional_login.class.php index 46abd82876..1ede1715f9 100644 --- a/main/inc/lib/conditional_login.class.php +++ b/main/inc/lib/conditional_login.class.php @@ -22,9 +22,7 @@ class ConditionalLogin { } public static function login() { - //require_once api_get_path(LIBRARY_PATH).'loginredirection.lib.php'; moved to autologin $_SESSION['conditional_login']['can_login'] = true; LoginRedirection::redirect(); - exit(); } } \ No newline at end of file diff --git a/main/inc/lib/conditionallogin.lib.php b/main/inc/lib/conditionallogin.lib.php deleted file mode 100644 index 13078f1cc1..0000000000 --- a/main/inc/lib/conditionallogin.lib.php +++ /dev/null @@ -1,5 +0,0 @@ - + * @author Laurent Opprecht 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; + } + +} \ No newline at end of file diff --git a/main/inc/lib/custompages.lib.php b/main/inc/lib/custompages.lib.php deleted file mode 100644 index d1498402fd..0000000000 --- a/main/inc/lib/custompages.lib.php +++ /dev/null @@ -1,37 +0,0 @@ - - -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; - } -} -?> diff --git a/main/inc/lib/login.lib.php b/main/inc/lib/login.lib.php index 90007561a1..e27eb7d7b0 100644 --- a/main/inc/lib/login.lib.php +++ b/main/inc/lib/login.lib.php @@ -1,126 +1,132 @@ , Ghent University -* @author Julio Montoya -* @package chamilo.login -*/ + * Code library for login process + * + * @author Olivier Cauberghe , Ghent University + * @author Julio Montoya + * @package chamilo.login + */ + /** * Class * @package chamilo.login */ -class Login +class Login { - /** - * Get user account list - * - * @param unknown_type $user - * @param boolean $reset - * @param boolean $by_username - * @return unknown - */ - public static function get_user_account_list($user, $reset = false, $by_username = false) { - global $_configuration; + + /** + * Get user account list + * + * @param unknown_type $user + * @param boolean $reset + * @param boolean $by_username + * @return unknown + */ + public static function get_user_account_list($user, $reset = false, $by_username = false) + { + global $_configuration; //$portal_url = $_configuration['root_web']; - $portal_url = api_get_path(WEB_PATH); - - if ($_configuration['multiple_access_urls']) { - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1 ) { - $url = api_get_access_url($access_url_id); - $portal_url = $url['url']; - } - } - - if ($reset) { - if ($by_username) { - $secret_word = self::get_secret_word($user['email']); - if ($reset) { - $reset_link = $portal_url."main/auth/lostPassword.php?reset=".$secret_word."&id=".$user['uid']; - } else { - $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.''; - - if ($user_account_list) { - $user_account_list = "\n-----------------------------------------------\n" . $user_account_list; - } - } else { - foreach ($user as $this_user) { - $secret_word = self::get_secret_word($this_user['email']); - if ($reset) { - $reset_link = $portal_url."main/auth/lostPassword.php?reset=".$secret_word."&id=".$this_user['uid']; - } else { - $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.''; - } - if ($user_account_list) { - $user_account_list = implode("\n-----------------------------------------------\n", $user_account_list); - } - } - } else { - if (!$by_username) { - $user = $user[0]; - } - $reset_link = get_lang('Pass')." : $user[password]"; - $user_account_list = get_lang('YourRegistrationData')." : \n".get_lang('UserName').' : '.$user['loginName']."\n".$reset_link.''; - } - return $user_account_list; - } - - /** - * This function sends the actual password to the user - * - * @param unknown_type $user - * @author Olivier Cauberghe , Ghent University - */ - public static function send_password_to_user($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, false, $by_username); // BODY - $email_to = $user['email']; - } else { - $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']) { - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1 ) { - $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 - $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'); - } else { - return get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".

"; - } - } - - /** - * Handle encrypted password, send an email to a user with his password - * - * @param int user id - * @param bool $by_username - * - * @author Olivier Cauberghe , Ghent University - */ - public static function handle_encrypted_password($user, $by_username = false) { + $portal_url = api_get_path(WEB_PATH); + + if ($_configuration['multiple_access_urls']) { + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1) { + $url = api_get_access_url($access_url_id); + $portal_url = $url['url']; + } + } + + if ($reset) { + if ($by_username) { + $secret_word = self::get_secret_word($user['email']); + if ($reset) { + $reset_link = $portal_url . "main/auth/lostPassword.php?reset=" . $secret_word . "&id=" . $user['uid']; + } else { + $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 . ''; + + if ($user_account_list) { + $user_account_list = "\n-----------------------------------------------\n" . $user_account_list; + } + } else { + foreach ($user as $this_user) { + $secret_word = self::get_secret_word($this_user['email']); + if ($reset) { + $reset_link = $portal_url . "main/auth/lostPassword.php?reset=" . $secret_word . "&id=" . $this_user['uid']; + } else { + $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 . ''; + } + if ($user_account_list) { + $user_account_list = implode("\n-----------------------------------------------\n", $user_account_list); + } + } + } else { + if (!$by_username) { + $user = $user[0]; + } + $reset_link = get_lang('Pass') . " : $user[password]"; + $user_account_list = get_lang('YourRegistrationData') . " : \n" . get_lang('UserName') . ' : ' . $user['loginName'] . "\n" . $reset_link . ''; + } + return $user_account_list; + } + + /** + * This function sends the actual password to the user + * + * @param unknown_type $user + * @author Olivier Cauberghe , Ghent University + */ + public static function send_password_to_user($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, false, $by_username); // BODY + $email_to = $user['email']; + } else { + $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']) { + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1) { + $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 + $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'); + } else { + return get_lang('SystemUnableToSendEmailContact') . ' ' . Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')) . ".

"; + } + } + + /** + * Handle encrypted password, send an email to a user with his password + * + * @param int user id + * @param bool $by_username + * + * @author Olivier Cauberghe , Ghent University + */ + public static function handle_encrypted_password($user, $by_username = false) + { 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 $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); - $email_body = get_lang('DearUser')." :\n".get_lang('password_request')."\n"; - $email_body .= $user_account_list."\n-----------------------------------------------\n\n"; + $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".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); $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') { + + if (CustomPages::enabled()) { 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')).".

"; - if (api_get_setting('use_custom_pages') == 'true') { + $message = get_lang('SystemUnableToSendEmailContact') . ' ' . Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')) . ".

"; + if (CustomPages::enabled()) { return $message; } else { Display::display_error_message($message, false); } } } - - /** - * Gets the secret word - * @author Olivier Cauberghe , Ghent University - */ - public static function get_secret_word($add) { - global $_configuration; - return $secret_word = md5($_configuration['security_key'].$add); - } - - /** - * Resets a password - * @author Olivier Cauberghe , Ghent University - */ - public static function reset_password($secret, $id, $by_username = false) { - $tbl_user = Database::get_main_table(TABLE_MAIN_USER); - $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"; - $result = Database::query($sql); - $num_rows = Database::num_rows($result); - - if ($result && $num_rows > 0) { - $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']; - $crypted = api_get_encrypted_password($crypted); - $sql = "UPDATE ".$tbl_user." SET password='$crypted' WHERE user_id = $id"; - $result = Database::query($sql); - return self::send_password_to_user($user, $by_username); - } else { - return get_lang('NotAllowed'); - } - } + + /** + * Gets the secret word + * @author Olivier Cauberghe , Ghent University + */ + public static function get_secret_word($add) + { + global $_configuration; + return $secret_word = md5($_configuration['security_key'] . $add); + } + + /** + * Resets a password + * @author Olivier Cauberghe , Ghent University + */ + public static function reset_password($secret, $id, $by_username = false) + { + $tbl_user = Database::get_main_table(TABLE_MAIN_USER); + $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"; + $result = Database::query($sql); + $num_rows = Database::num_rows($result); + + if ($result && $num_rows > 0) { + $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']; + $crypted = api_get_encrypted_password($crypted); + $sql = "UPDATE " . $tbl_user . " SET password='$crypted' WHERE user_id = $id"; + $result = Database::query($sql); + return self::send_password_to_user($user, $by_username); + } else { + return get_lang('NotAllowed'); + } + } + + + } diff --git a/main/inc/lib/login_redirection.class.php b/main/inc/lib/login_redirection.class.php index 2e3af2913b..7bd4e10f56 100644 --- a/main/inc/lib/login_redirection.class.php +++ b/main/inc/lib/login_redirection.class.php @@ -52,9 +52,8 @@ Class LoginRedirection { } // Custom pages - if (api_get_setting('use_custom_pages') == 'true') { - require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; - CustomPages::displayPage('index-logged'); + if (CustomPages::enabled()) { + CustomPages::display(CustomPages::INDEX_LOGGED); } header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param); exit(); diff --git a/main/inc/lib/loginredirection.lib.php b/main/inc/lib/loginredirection.lib.php deleted file mode 100644 index e65cc74f3e..0000000000 --- a/main/inc/lib/loginredirection.lib.php +++ /dev/null @@ -1,7 +0,0 @@ -