Skip to content

Commit

Permalink
Event::event_login now requires a user id
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Apr 23, 2015
1 parent 5e17efd commit 665a9a6
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 42 deletions.
4 changes: 2 additions & 2 deletions main/auth/external_login/login.ldap.php
Expand Up @@ -38,7 +38,7 @@
*
* */

use \ChamiloSession as Session;
use ChamiloSession as Session;

require_once dirname(__FILE__) . '/ldap.inc.php';
require_once dirname(__FILE__) . '/functions.inc.php';
Expand All @@ -65,7 +65,7 @@
Session::write('_user', $_user);
$uidReset = true;
$logging_in = true;
Event::event_login();
Event::event_login($_user['user_id']);
} else {
error_log('extldap_authenticate error');
$loginFailed = true;
Expand Down
4 changes: 2 additions & 2 deletions main/auth/external_login/login.ws.php
Expand Up @@ -6,7 +6,7 @@
* have 'ws' in his auth_source field instead of 'platform'.
*/

use \ChamiloSession as Session;
use ChamiloSession as Session;

// Configure the web service URL here. e.g. http://174.1.1.19:8020/login.asmx?WSDL
$wsUrl = '';
Expand All @@ -27,7 +27,7 @@
Session::write('_user', $_user);
$uidReset = true;
$logging_in = true;
Event::event_login();
Event::event_login($_user['user_id']);
} else {
//error_log('WS authentication error - user not approved by external WS');
$loginFailed = true;
Expand Down
5 changes: 3 additions & 2 deletions main/auth/external_login/newUser.ldap.php
Expand Up @@ -37,7 +37,7 @@
* - index.php?loginFailed=1&error=unrecognize_sso_origin');
* */

use \ChamiloSession as Session;
use ChamiloSession as Session;

require_once dirname(__FILE__) . '/ldap.inc.php';
require_once dirname(__FILE__) . '/functions.inc.php';
Expand All @@ -60,8 +60,9 @@
$is_platformAdmin = true;
Database::query("INSERT INTO admin values ('$chamilo_uid')");
}
Event::event_login($chamilo_uid);
}
Event::event_login();

} else {
$loginFailed = true;
$uidReset = false;
Expand Down
4 changes: 2 additions & 2 deletions main/auth/external_login/newUser.php
Expand Up @@ -8,7 +8,7 @@
You also have to implements the external_get_user_info function in functions.inc.php
*/

use \ChamiloSession as Session;
use ChamiloSession as Session;

require_once(dirname(__FILE__) . '/functions.inc.php');

Expand Down Expand Up @@ -46,7 +46,7 @@
// Can user create course
$is_allowedCreateCourse = (bool) (($user['status'] == COURSEMANAGER) or (api_get_setting('drhCourseManagerRights') and $user['status'] == SESSIONADMIN));

Event::event_login();
Event::event_login($chamilo_uid);
} else {
$loginFailed = true;
unset($_user['user_id']);
Expand Down
12 changes: 4 additions & 8 deletions main/auth/ldap/login.php
Expand Up @@ -21,25 +21,21 @@
*/
//require_once('../../inc/global.inc.php'); - this script should be loaded by the /index.php script anyway, so global is already loaded

use \ChamiloSession as Session;
use ChamiloSession as Session;

require_once('authldap.php');

$loginLdapSucces = ldap_login($login, $password);

if ($loginLdapSucces)
{
if ($loginLdapSucces) {
$loginFailed = false;
$uidReset = true;
$_user['user_id'] = $uData['user_id'];
Session::write('_uid',$_uid);
// Jand: copied from event_login in events.lib.php to enable login statistics:
Event::event_login();
}
else
{
Event::event_login($uData['user_id']);
} else {
$loginFailed = true;
unset($_user['user_id']);
$uidReset = false;
}
?>
2 changes: 1 addition & 1 deletion main/auth/shibboleth/lib/shibboleth_session.class.php
Expand Up @@ -79,7 +79,7 @@ function login($uid)
$_SESSION['noredirection'] = true;

//must be called before 'init_local.inc.php'
Event::event_login();
Event::event_login($_uid);

//used in 'init_local.inc.php' this is BAD but and should be changed
$loginFailed = false;
Expand Down
8 changes: 4 additions & 4 deletions main/auth/sso/sso.Drupal.class.php
@@ -1,6 +1,6 @@
<?php

use \ChamiloSession as Session;
use ChamiloSession as Session;

/* For licensing terms, see /license.txt */
/**
Expand Down Expand Up @@ -142,7 +142,7 @@ public function check_user()
$_user['user_id'] = $uData['user_id'];
$_user = api_get_user_info($_user['user_id']);
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
// Redirect to homepage
$sso_target = isset($sso['target']) ? $sso['target'] : api_get_path(WEB_PATH) . 'index.php';
header('Location: '. $sso_target);
Expand Down Expand Up @@ -173,15 +173,15 @@ public function check_user()
$is_platformAdmin = $uData['status'] == COURSEMANAGER;
Session::write('is_platformAdmin', $is_platformAdmin);
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
} else {
//Secondary URL admin wants to login
// so we check as a normal user
if (in_array($current_access_url_id, $my_url_list)) {
$_user['user_id'] = $uData['user_id'];
$_user = api_get_user_info($_user['user_id']);
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
} else {
$loginFailed = true;
Session::erase('_uid');
Expand Down
8 changes: 4 additions & 4 deletions main/auth/sso/sso.class.php
@@ -1,6 +1,6 @@
<?php

use \ChamiloSession as Session;
use ChamiloSession as Session;

/* For licensing terms, see /license.txt */
/**
Expand Down Expand Up @@ -150,7 +150,7 @@ public function check_user()
$_user['user_id'] = $uData['user_id'];
$_user = api_get_user_info($_user['user_id']);
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
// Redirect to homepage
$sso_target = isset($sso['target']) ? $sso['target'] : api_get_path(WEB_PATH) .'.index.php';
header('Location: '. $sso_target);
Expand Down Expand Up @@ -181,15 +181,15 @@ public function check_user()
$is_platformAdmin = $uData['status'] == COURSEMANAGER;
Session::write('is_platformAdmin', $is_platformAdmin);
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
} else {
//Secondary URL admin wants to login
// so we check as a normal user
if (in_array($current_access_url_id, $my_url_list)) {
$_user['user_id'] = $uData['user_id'];
$_user = api_get_user_info($_user['user_id']);
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
} else {
$loginFailed = true;
Session::erase('_uid');
Expand Down
9 changes: 5 additions & 4 deletions main/inc/lib/events.lib.php
Expand Up @@ -55,15 +55,16 @@ public static function event_open()
* @author Julio Montoya 2013
* @desc Record information for login event when an user identifies himself with username & password
*/
public static function event_login()
public static function event_login($userId)
{
$userInfo = api_get_user_info();
$userInfo = api_get_user_info($userId);

$userId = intval($userId);

if (empty($userInfo)) {
return false;
}

$userId = api_get_user_id();

$TABLETRACK_LOGIN = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);

$reallyNow = api_get_utc_datetime();
Expand Down
22 changes: 9 additions & 13 deletions main/inc/local.inc.php
Expand Up @@ -109,12 +109,6 @@
* @package chamilo.include
*/

/*
INIT SECTION
variables should be initialised here
*/

//require_once api_get_path(LIBRARY_PATH).'conditionallogin.lib.php'; moved to autologin
// verified if exists the username and password in session current

use ChamiloSession as Session;
Expand All @@ -131,7 +125,7 @@
Session::write('_user', $_user);
Session::erase('conditional_login');
$uidReset=true;
Event::event_login();
Event::event_login($_user['user_id']);
}

// parameters passed via GET
Expand Down Expand Up @@ -321,7 +315,7 @@
if (($password == $uData['password'] || $cas_login) && (trim($login) == $uData['username'])) {
$update_type = UserManager::get_extra_user_data_by_field($uData['user_id'], 'update_type');

$update_type= $update_type['update_type'];
$update_type = $update_type['update_type'];
if (!empty($extAuthSource[$update_type]['updateUser'])
&& file_exists($extAuthSource[$update_type]['updateUser'])
) {
Expand Down Expand Up @@ -361,7 +355,7 @@
$_user['user_id'] = $uData['user_id'];
$_user['status'] = $uData['status'];
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
$logging_in = true;
} else {
$loginFailed = true;
Expand All @@ -387,15 +381,15 @@
$_user['user_id'] = $uData['user_id'];
$_user['status'] = $uData['status'];
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
$logging_in = true;
} else {
//This means a secondary admin wants to login so we check as he's a normal user
if (in_array($current_access_url_id, $my_url_list)) {
$_user['user_id'] = $uData['user_id'];
$_user['status'] = $uData['status'];
Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
$logging_in = true;
} else {
$loginFailed = true;
Expand All @@ -410,13 +404,15 @@
}
}
} else {

ConditionalLogin::check_conditions($uData);
$_user['user_id'] = $uData['user_id'];
$_user['status'] = $uData['status'];

Session::write('_user', $_user);
Event::event_login();
Event::event_login($uData['user_id']);
$logging_in = true;

}
} else {
$loginFailed = true;
Expand Down Expand Up @@ -661,7 +657,7 @@
$_user['status'] = $uData['status'];

Session::write('_user', $_user);
Event::event_login();
Event::event_login($_user['user_id']);
} else {
$loginFailed = true;
Session::erase('_uid');
Expand Down

0 comments on commit 665a9a6

Please sign in to comment.