if (isset($uidReset) && $uidReset) { // session data refresh requested unset($_SESSION['_user']['uidReset']); $is_platformAdmin = false; $is_allowedCreateCourse = false; if (isset($_user['user_id']) && $_user['user_id'] && !api_is_anonymous()) { // a uid is given (log in succeeded) $user_table = Database::get_main_table(TABLE_MAIN_USER); $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); $track_e_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); $sql = "SELECT user.*, a.user_id is_admin, login.login_date\n FROM {$user_table}\n LEFT JOIN {$admin_table} a\n ON user.user_id = a.user_id\n LEFT JOIN {$track_e_login} login\n ON user.user_id = login.login_user_id\n WHERE user.user_id = '" . $_user['user_id'] . "'\n ORDER BY login.login_date DESC LIMIT 1"; $result = Database::query($sql); if (Database::num_rows($result) > 0) { // Extracting the user data $uData = Database::fetch_array($result); $_user = api_format_user($uData, false); $_user['lastLogin'] = api_strtotime($uData['login_date'], 'UTC'); $is_platformAdmin = (bool) (!is_null($uData['is_admin'])); $is_allowedCreateCourse = (bool) ($uData['status'] == COURSEMANAGER or api_get_setting('drhCourseManagerRights') and $uData['status'] == DRH); ConditionalLogin::check_conditions($uData); Session::write('_user', $_user); UserManager::update_extra_field_value($_user['user_id'], 'already_logged_in', 'true'); Session::write('is_platformAdmin', $is_platformAdmin); Session::write('is_allowedCreateCourse', $is_allowedCreateCourse); } else { header('location:' . api_get_path(WEB_PATH)); exit; } } else { // no uid => logout or Anonymous Session::erase('_user');
/** * Finds all the information about a user from username instead of user id * @param $username (string): the username * @return $user_info (array): user_id, lastname, firstname, username, email, ... * @author Yannick Warnier <*****@*****.**> */ function api_get_user_info_from_official_code($official_code = '') { if (empty($official_code)) { return false; } $sql = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_USER) . " WHERE official_code ='" . Database::escape_string($official_code) . "'"; $result = Database::query($sql); if (Database::num_rows($result) > 0) { $result_array = Database::fetch_array($result); return api_format_user($result_array); } return false; }