Should fix bug in the condition class. Swapping the return values of the function, returns true means that the user can pass, false otherwise see #4619

skala
Julio Montoya 13 years ago
parent 732aed1cb8
commit 0a255edf58
  1. 54
      main/auth/conditional_login/conditional_login.php
  2. 17
      main/inc/lib/conditional_login.class.php

@ -3,64 +3,62 @@
/*
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.
* Please populate the $login_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();
/**
* Please implements the functions of the $login_conditions array.
* Each of these function will take a user array (user_id, username, password (crypted), auth_source, active, expiration_date)
*/
$login_conditions = array();
array_push($dc_conditions, array(
// 'conditional_function' => 'check_platform_legal_conditions',
// 'url' => api_get_path(WEB_CODE_PATH).'auth/inscription.php'
//"Term and conditions" condition
array_push($login_conditions, array(
'conditional_function' => 'check_platform_legal_conditions',
'url' => api_get_path(WEB_CODE_PATH).'auth/inscription.php'
));
//array_push($dc_conditions, array(
//array_push($login_conditions, array(
// 'conditional_function' => 'dc_check_phone_number',
// 'url' => api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php'
//));
//array_push($dc_conditions, array(
// 'conditional_function' => 'dc_check_first_login',
// 'url' => api_get_path(WEB_PATH).'main/auth/conditional_login/first_login.php'
//));
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
/*
Please implements the functions of the $dc_conditions array. Each of these fucntion will take a user array (user_id, username, password (crypted), auth_sourcen, active, expiration_date)
*/
function dc_check_phone_number($user){
$uInfo = UserManager::get_user_info_by_id($user['user_id']);
if (empty($uInfo['phone'])) {
return true;
return false;
}
return false;
}
function dc_check_first_login($user){
$uInfo = UserManager::get_user_info_by_id($user['user_id']);
return $uInfo['extra']['already_logged_in'] === 'false';
return true;
}
/**
* Checks if the user accepted or not the legal conditions
*
* @param array $user
* @return boolean true if user pass, false otherwise
*/
function check_platform_legal_conditions($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) {
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;*/
return false;
} else {
unset($_SESSION['term_and_condition']);
return false;
}
return true;
}
} else {
//No validation
//No validation user can pass
return true;
}
}

@ -7,16 +7,21 @@
*/
class ConditionalLogin {
/**
* Check conditions based in the $login_conditions see conditional_login.php file
* @param type $user
*/
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)) {
foreach ($dc_conditions as $dc_condition) {
if (isset($dc_condition['conditional_function']) && $dc_condition['conditional_function']($user)) {
$_SESSION['conditional_login']['uid'] = $user['user_id'];
if (isset($login_conditions)) {
foreach ($login_conditions as $condition) {
//If condition fails we redirect to the URL defined by the condition
if (isset($condition['conditional_function']) && $condition['conditional_function']($user) == false) {
$_SESSION['conditional_login']['uid'] = $user['user_id'];
$_SESSION['conditional_login']['can_login'] = false;
header("Location:". $dc_condition['url']);
header("Location:". $condition['url']);
exit();
}
}

Loading…
Cancel
Save