/** * Retrieve user id of current user * @return int user id * @access public */ function auth_get_current_user_id() { global $g_cache_current_user_id; if (null !== $g_cache_current_user_id) { return $g_cache_current_user_id; } $t_cookie_string = auth_get_current_user_cookie(); if ($t_result = user_search_cache('cookie_string', $t_cookie_string)) { $t_user_id = (int) $t_result['id']; $g_cache_current_user_id = $t_user_id; return $t_user_id; } $t_user_table = db_get_table('user'); /** @todo error with an error saying they aren't logged in? Or redirect to the login page maybe? */ $query = "SELECT id\n\t\t\t\t FROM {$t_user_table}\n\t\t\t\t WHERE cookie_string=" . db_param(); $result = db_query_bound($query, array($t_cookie_string)); # The cookie was invalid. Clear the cookie (to allow people to log in again) # and give them an Access Denied message. if (db_num_rows($result) < 1) { auth_clear_cookies(); access_denied(); exit; } $t_user_id = (int) db_result($result); $g_cache_current_user_id = $t_user_id; return $t_user_id; }
/** * Retrieve user id of current user * @return integer user id * @access public */ function auth_get_current_user_id() { global $g_cache_current_user_id; if (null !== $g_cache_current_user_id) { return $g_cache_current_user_id; } $t_cookie_string = auth_get_current_user_cookie(); if ($t_result = user_search_cache('cookie_string', $t_cookie_string)) { $t_user_id = (int) $t_result['id']; current_user_set($t_user_id); return $t_user_id; } # @todo error with an error saying they aren't logged in? Or redirect to the login page maybe? db_param_push(); $t_query = 'SELECT id FROM {user} WHERE cookie_string=' . db_param(); $t_result = db_query($t_query, array($t_cookie_string)); $t_user_id = (int) db_result($t_result); # The cookie was invalid. Clear the cookie (to allow people to log in again) # and give them an Access Denied message. if (!$t_user_id) { auth_clear_cookies(); access_denied(); exit; } current_user_set($t_user_id); return $t_user_id; }
function auth_get_current_user_id() { global $g_cache_current_user_id; if (null !== $g_cache_current_user_id) { return $g_cache_current_user_id; } $t_user_table = config_get('mantis_user_table'); $t_cookie_string = auth_get_current_user_cookie(); # @@@ error with an error saying they aren't logged in? # Or redirect to the login page maybe? $c_cookie_string = db_prepare_string($t_cookie_string); $query = "SELECT id\r\n\t\t\t\t FROM {$t_user_table}\r\n\t\t\t\t WHERE cookie_string='{$c_cookie_string}'"; $result = db_query($query); # The cookie was invalid. Clear the cookie (to allow people to log in again) # and give them an Access Denied message. if (db_num_rows($result) < 1) { auth_clear_cookies(); access_denied(); # never returns return false; } $t_user_id = (int) db_result($result); $g_cache_current_user_id = $t_user_id; return $t_user_id; }
<?php # Copyright (C) 2008 John Reese # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. form_security_validate('plugin_Timecard_log_time'); $f_bug_id = gpc_get_int('bug_id'); $f_spent = gpc_get_int('spent', 0); access_ensure_bug_level(plugin_config_get('update_threshold'), $f_bug_id); if ($f_spent > 0) { $t_update = new TimecardUpdate($f_bug_id, 0, auth_get_current_user_cookie(), $f_spent); $t_update->save(); } else { trigger_error(ERROR_GENERIC, ERROR); } form_security_purge('plugin_Timecard_log_time'); print_successful_redirect_to_bug($f_bug_id);
public function initMiteObjects() { # do nothing if the user is not logged in if (!auth_get_current_user_cookie()) { return; } $this->i_userId = auth_get_current_user_id(); $this->o_miteRemote = mite::getInstance(); $this->o_mitePartialsController = mitePartialsController::getInstance(); # only fill session with user data, if there's a user currently logged in if (current_user_get_field(Mantis2mitePlugin::DB_FIELD_CONNECT_VERIFIED)) { $this->o_miteUserData = new miteUserData($this, $this->i_userId); $this->o_miteRemote->init($this->getDecodedUserValue(self::DB_FIELD_API_KEY), $this->getDecodedUserValue(self::DB_FIELD_ACCOUNT_NAME)); } return true; }