Moving code from local to the conditional login see #5217

skala
Julio Montoya 14 years ago
parent 145b1d05bf
commit f8a460f8ec
  1. 4
      main/admin/configure_inscription.php
  2. 6
      main/auth/conditional_login/complete_phone_number.php
  3. 42
      main/auth/conditional_login/conditional_login.php
  4. 11
      main/inc/lib/conditional_login.class.php
  5. 33
      main/inc/local.inc.php

@ -301,10 +301,6 @@ if (get_setting('allow_terms_conditions') == 'true') {
$form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
$form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']);
/*if (isset($_SESSION['term_and_condition']['user_id']) && isset($_SESSION['term_and_condition']['password'])) {
$form->addElement('hidden', 'login', $_SESSION['term_and_condition']['user_id']);
$form->addElement('hidden', 'password', $_SESSION['term_and_condition']['password']);
}*/
if ($term_preview['type'] == 1) {
$form->addElement('checkbox', 'legal_accept', null, get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang('TermsAndConditions').'</a>');
$form->addRule('extra_legal_accept', get_lang('ThisFieldIsRequired'), 'required');

@ -1,7 +1,7 @@
<?php
require_once(dirname(__FILE__).'/../../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');
/* For licensing terms, see /license.txt */
require_once dirname(__FILE__).'/../../inc/global.inc.php';
$url = api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php';
if (! isset($_SESSION['conditional_login']['uid']))

@ -1,10 +1,22 @@
<?php
/*
This scrip is included by local.inc.php to redirect users to some url if some conditions are satisfied. Please populate the $dc_conditions array with a conditional function and an url. If the conditional function returns true the user will be redirected to URL at login
/* For licensing terms, see /license.txt */
This array must be filled for this module to work. This is an example asking the user to enter his phone number if it is empty. Note you can enter more than one condition in the array. They will be checked in the array order.
/*
This script is included by local.inc.php to redirect users to some url if some conditions are satisfied.
* Please populate the $dc_conditions array with a conditional function and an url.
* If the conditional function returns true the user will be redirected to URL at login.
* This array must be filled for this module to work.
* This is an example asking the user to enter his phone number if it is empty.
* Note you can enter more than one condition in the array. They will be checked in the array order.
*/
$dc_conditions = array();
array_push($dc_conditions, array(
'conditional_function' => 'check_platform_legal',
'url' => api_get_path(WEB_CODE_PATH).'auth/inscription.php'
));
//array_push($dc_conditions, array(
// 'conditional_function' => 'dc_check_phone_number',
// 'url' => api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php'
@ -19,7 +31,7 @@ require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
*/
function dc_check_phone_number($user){
$uInfo = UserManager::get_user_info_by_id($user['user_id']);
if ( empty($uInfo['phone'])) {
if (empty($uInfo['phone'])) {
return true;
}
return false;
@ -27,5 +39,25 @@ function dc_check_phone_number($user){
function dc_check_first_login($user){
$uInfo = UserManager::get_user_info_by_id($user['user_id']);
return(($uInfo['extra']['already_logged_in'] === 'false'));
return $uInfo['extra']['already_logged_in'] === 'false';
}
function check_platform_legal($user) {
if (api_get_setting('allow_terms_conditions') == 'true') {
$term_and_condition_status = api_check_term_condition($user['user_id']);
// @todo not sure why we need the login password and update_term_status
if ($term_and_condition_status === false) {
$_SESSION['term_and_condition'] = array('user_id' => $user['user_id'],
//'login' => $user['username'],
//'password' => $user['password'],
//'update_term_status' => true,
);
return true;
/*header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php');
exit;*/
} else {
unset($_SESSION['term_and_condition']);
}
}
return false;
}

@ -1,14 +1,17 @@
<?php
// Conditional login
// Used to implement the loading of custom pages
// 2011, Noel Dieschburg <noel@cblue.be>
/* For licensing terms, see /license.txt */
/*
* Conditional login
* Used to implement the loading of custom pages
* 2011, Noel Dieschburg <noel@cblue.be>
*/
class ConditionalLogin {
public static function check_conditions($user) {
if (file_exists(api_get_path(SYS_PATH).'main/auth/conditional_login/conditional_login.php')) {
include_once api_get_path(SYS_PATH).'main/auth/conditional_login/conditional_login.php';
if (isset($dc_conditions)){
if (isset($dc_conditions)) {
foreach ($dc_conditions as $dc_condition) {
if (isset($dc_condition['conditional_function']) && $dc_condition['conditional_function']($user)) {
$_SESSION['conditional_login']['uid'] = $user['user_id'];

@ -227,8 +227,8 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) {
$login = $_POST['login'];
$password = $_POST['password'];
}
//lookup the user in the main database
//Lookup the user in the main database
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT user_id, username, password, auth_source, active, expiration_date, status FROM $user_table
WHERE username = '".Database::escape_string($login)."'";
@ -238,38 +238,19 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) {
$uData = Database::fetch_array($result);
if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE || $uData['auth_source'] == CAS_AUTH_SOURCE) {
//the authentification of this user is managed by Chamilo itself
//The authentification of this user is managed by Chamilo itself
$password = api_get_encrypted_password(trim(stripslashes($password)));
if (api_get_setting('allow_terms_conditions')=='true') {
if ($password == $uData['password'] AND (trim($login) == $uData['username']) OR $cas_login ) {
$temp_user_id = $uData['user_id'];
$term_and_condition_status = api_check_term_condition($temp_user_id);//false or true
if ($term_and_condition_status === false) {
$_SESSION['term_and_condition'] = array('user_id' => $temp_user_id,
'login' => $login,
'password' => $password,
'update_term_status' => true,
);
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php');
exit;
} else {
unset($_SESSION['term_and_condition']);
}
}
}
// Check the user's password
if ( ($password == $uData['password'] OR $cas_login) AND (trim($login) == $uData['username'])) {
if ( ($password == $uData['password'] OR $cas_login) AND (trim($login) == $uData['username'])) {
$update_type = UserManager::get_extra_user_data_by_field($uData['user_id'], 'update_type');
$update_type= $update_type['update_type'];
if (!empty($extAuthSource[$update_type]['updateUser']) && file_exists($extAuthSource[$update_type]['updateUser'])) {
include_once $extAuthSource[$update_type]['updateUser'];
}
// Check if the account is active (not locked)
if ($uData['active']=='1') {
if ($uData['active'] == '1') {
// Check if the expiration date has not been reached
if ($uData['expiration_date'] > date('Y-m-d H:i:s') OR $uData['expiration_date'] == '0000-00-00 00:00:00') {

Loading…
Cancel
Save