function userName() { if (isLoggedIn()) { return $_SESSION['username']; } else { return ''; } }
/** * Function renders main page and implements user login behaviour. * If user is already logged in, he will be redirected to his twitter wall. * If user doesn't exist or entered data is wrong, warning message will show. */ public function action() { if (isLoggedIn()) { redirect(\route\Route::get("twitterWall")->generate(array("id" => UserRepository::getIdByUsername($_SESSION['username'])))); } $main = new Main(); $main->setPageTitle("Twitter App"); $body = new \templates\Index(); $main->setBody($body); echo $main; if (UserRepository::isLoggedIn()) { redirect(\route\Route::get("twitterWall")->generate()); } if (post('login')) { $username = htmlentities(trim(post('username'))); $password = htmlentities(trim(post('password'))); $hashedPassword = hash_password($password); if (UserRepository::login($username, $hashedPassword)) { redirect(\route\Route::get("twitterWall")->generate(array("id" => UserRepository::getIdByUsername($_SESSION['username'])))); exit; } else { ?> <script src="assets/js/loginError.js"></script> <?php } } }
function redirect($page) { $currentPage = basename($_SERVER['PHP_SELF']); // prevent redirecting away from graphs.php when $.post is accessing if ($currentPage == 'graphs.php' || $currentPage == 'verify.php') { if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') { header('Location: /fp2.0/'); exit; } } else { if ($currentPage != $page) { if ($page == 'index.php') { $page = ''; } // make sure index.php is not included so that the url is shorter if (!isLoggedIn()) { header("Location: login.php"); exit; } else { if ($currentPage != 'monthlyReport.php' && $currentPage != 'settings.php') { header("Location: /fp2.0/" . $page); exit; } } } } }
function handleCookies() { // if no session lets check for cookies if (!isLoggedIn()) { if (isset($_COOKIE["urika_userlogin"]) == true && isset($_COOKIE["urika_login_tried"]) == false) { $CI =& get_instance(); $CI->load->model("user_model"); $query = $CI->user_model->getUser($_COOKIE["urika_userlogin"], "u_username"); if ($query) { // now verify secret before creating session $row = $query->row(); if (isset($_COOKIE["urika_usersecret"]) && md5($row->u_username . $row->u_password) == $_COOKIE["urika_usersecret"]) { // win lets make a session $data = array('username' => $row->u_username, 'user_id' => $row->user_id, 'is_logged_in' => true, 'image_url' => getUserProfileURL($row->u_profile_id, $row->u_email)); $CI->session->set_userdata($data); } else { // no luck setcookie("urika_login_tried", $_COOKIE["urika_userlogin"]); } } else { // no match, so et a cookie so we don't try over and over again setcookie("urika_login_tried", $_COOKIE["urika_userlogin"]); } } } }
function logout() { if (isLoggedIn()) { unset($_SESSION['user']); } return true; }
public function find() { if (!$this->uri->segment(3)) { show_404(current_url(), FALSE); } else { if ($this->data['Treasure'] = $this->treasure_model->get_by('md5', $this->uri->segment(3))) { if (isFound($this->data['Treasure']->id, $this->session->userdata('id'))) { $found = TRUE; } else { $found = FALSE; if (isLoggedIn()) { if (!isBanned($this->session->userdata('id'))) { if (!isAdmin()) { $this->mytreasure_model->insert(array('pirate' => $this->session->userdata('id'), 'treasure' => $this->data['Treasure']->id, 'time' => time())); } } } } $this->data['found'] = $found; $this->template->write_view('content', 'views/treasure/find', $this->data); $this->template->render(); } else { show_404(current_url(), FALSE); } } }
/** * Returns the current logged in user * * @return array|null */ function loggedin_user() { //User is not lgged in if (!isLoggedIn()) { //we return null return null; } //Check if we have user id if (!isset($_SESSION['user_id']) || $_SESSION['user_id'] == '' || $_SESSION['user_id'] == null) { //Return null return null; } //Create new user object $user = new App\Models\User(); //Get user id $user_id = $_SESSION['user_id']; //Get the user $results = $user->query("SELECT * FROM users WHERE id = '" . $user_id . "'"); //We got the results if ($results != false) { //Return the current user row return $results[0]; } else { //No user found //return null return null; } }
/** * Vraca korisnicko ime ako je korisnik ulogiran. */ function getUsername() { if (isLoggedIn()) { return $_SESSION["username"]; } return null; }
function index($info = "") { $menuList[] = array('id' => 1, 'name' => $this->spTextPanel['Website Manager'], 'url_section' => 'websites'); if (isAdmin()) { $menuList[] = array('id' => 2, 'name' => $this->spTextPanel['User Manager'], 'url_section' => 'users'); } if (isLoggedIn()) { $menuList[] = array('id' => 3, 'name' => $this->spTextPanel['Reports Manager'], 'url_section' => 'report-manager'); } if (isAdmin()) { $menuList[] = array('id' => 4, 'name' => $this->spTextPanel['Seo Tools Manager'], 'url_section' => 'seo-tools-manager'); $menuList[] = array('id' => 5, 'name' => $this->spTextPanel['Seo Plugins Manager'], 'url_section' => 'seo-plugin-manager'); $menuList[] = array('id' => 6, 'name' => $this->spTextPanel['Directory Manager'], 'url_section' => 'directory-manager'); $menuList[] = array('id' => 11, 'name' => $this->spTextPanel['Search Engine Manager'], 'url_section' => 'se-manager'); $menuList[] = array('id' => 9, 'name' => $this->spTextPanel['Proxy Manager'], 'url_section' => 'proxy-manager'); $menuList[] = array('id' => 7, 'name' => $this->spTextPanel['System Settings'], 'url_section' => 'settings'); } $menuList[] = array('id' => 8, 'name' => $this->spTextPanel['My Profile'], 'url_section' => 'my-profile'); $menuList[] = array('id' => 10, 'name' => $this->spTextPanel['About Us'], 'url_section' => 'about-us'); $menuSelected = empty($info['menu_selected']) ? 'websites' : urldecode($info['menu_selected']); $this->set('menuList', $menuList); $this->set('menuSelected', $menuSelected); $startScript = empty($info['start_script']) ? "websites.php" : urldecode($info['start_script']); if (!stristr($startScript, '.php')) { $startScript .= ".php"; } $arguments = ""; foreach ($info as $key => $value) { if (!in_array($key, array('menu_selected', 'start_script'))) { $arguments .= "&{$key}=" . urldecode($value); } } $this->set('startFunction', "scriptDoLoad('{$startScript}', 'content', '{$arguments}')"); $this->render('adminpanel/adminpanel'); }
function listSeoTools() { $userId = isLoggedIn(); $seoToolList = $this->__getAllSeoTools(); $this->set('list', $seoToolList); $this->render('seotools/listseotools'); }
?> <?php function addVideo() { if (isLoggedIn()) { if (hasCurrentUserRight("video")) {
/** * Determinate if user is admin * * @return boolean */ public function isAdmin() { if (!isLoggedIn()) { return false; } return (bool) $this->user()->site_access; }
public static function Factory($default_page = null, $requireLogin = true) { $prefs = UserPreferences::Instance(EGS_USERNAME); $default_page = $prefs->getPreferenceValue('default_page', 'shared'); if ($default_page == null) { $ao = AccessObject::Instance(); $default_page = 'module,' . $ao->getDefaultModule(); } if (get_config('SETUP')) { if (defined('MODULE')) { $default_page = MODULE; } } $router = RouteParser::Instance(); $modules = array(); if (!$requireLogin || isLoggedIn()) { foreach ($router->getDispatch() as $key => $dispatch) { if (($key == 'group' || $key == 'module' || strstr($key, 'submodule')) && !empty($dispatch)) { $modules[$key] = $dispatch; } } if (empty($modules)) { // Default page contains permission type and permission name // i.e. type is group or module $array = explode(',', $default_page); $modules[$array[0]] = $array[1]; } } else { $modules['module'] = 'login'; } $al =& AutoLoader::Instance(); return $modules; }
public function __construct() { parent::__construct(); ini_set('memory_limit', '-1'); $this->domain = 'http://localhost/cookindo'; $this->webroot = $_SERVER['DOCUMENT_ROOT'] . '/cookindo/'; // $this->domain = 'http://'.$_SERVER['SERVER_NAME']; // $this->webroot = $_SERVER['DOCUMENT_ROOT']; if (isLoggedIn()) { if ($this->session->userdata('userpassword') == 'def' && strtolower($this->router->method) != 'completion' && strtolower($this->router->method) != 'logout') { $this->load->helper('url'); redirect($this->domain . '/users/completion'); } $resNotification = $this->db->query('CALL GetNotifications(?)', array($this->session->userdata('userid'))); $notifications = $resNotification->result_array(); $resNotification->next_result(); $this->load->vars(array('notifications' => $notifications)); } if ($this->session->userdata('redirect_now') == true) { $this->session->set_userdata('redirect_now', false); if (!empty($this->session->userdata('redirect_after'))) { $redirect_after = $this->session->userdata('redirect_after'); $this->session->set_userdata('redirect_after', false); $this->load->helper('url'); redirect($this->domain . '/' . $redirect_after); } } $this->site_lang = get_cookie('site_lang') ? get_cookie('site_lang') : 'indonesian'; $this->lang->load($this->site_lang, $this->site_lang); $this->load->vars(array('domain' => $this->domain, 'webroot' => $this->webroot, 'site_lang' => $this->site_lang)); }
function requireUser($b = true) { if ($b && !isLoggedIn()) { warning('You need to login to view this page.'); redirect($GLOBALS['sLoginPage'] . '?ref=' . str_replace('?logout=true', '', $_SERVER['REQUEST_URI'])); } }
/** * Logs in and downloads the book * * @param $book */ function downloadBook($book) { $params = array("email" => ACCOUNT_EMAIL, "password" => ACCOUNT_PASSWORD, "op" => "Login", "form_build_id" => $book['form_build_id'], "form_id" => "packt_user_login_form"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.packtpub.com/packt/offers/free-learning'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie-name'); //could be empty, but cause problems on some hosts curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp'); //could be empty, but cause problems on some hosts curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $response = curl_exec($ch); if (curl_error($ch)) { echo curl_error($ch); } $loggedIn = isLoggedIn($response); $response = false; if ($loggedIn) { curl_setopt($ch, CURLOPT_URL, 'https://www.packtpub.com' . $book['book_claim_url']); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_POSTFIELDS, ""); $response = curl_exec($ch); } curl_close($ch); if ($response === false) { die(1); } }
function isValidAdmin() { if (isset($_SESSION['valid_admin']) && isLoggedIn()) { return true; } else { return false; } }
function me() { if (isLoggedIn()) { return new User(intval($_SESSION['UID'])); } else { return false; } }
public static function validateSession() { $status = array("session" => "invalid"); if (isLoggedIn()) { $status["session"] = "valid"; } return $status; }
function checkAuthz($action) { $noAuth = array('login', 'login.do', 'logout', 'main', '', 'register', 'register.do'); if (in_array($action, $noAuth)) { return true; } return isLoggedIn(); }
public function __construct() { parent::__construct(); if (isLoggedIn()) { redirect('treasure'); } $this->load->model(array('mytreasure_model', 'treasure_model')); }
function userstatus() { global $helper; $loggedin = isLoggedIn(); $user = getUserDetails(); $helper->set('user', $user); return $helper->render(); }
public function index() { if (isLoggedIn()) { redirect('admin/home'); } $this->template->write_view('content', 'views/admin/auth/index'); $this->template->render(); }
function __construct() { parent::__construct(); if (!isLoggedIn()) { redirect(my_site_url() . 'welcome/view_login'); } $this->load->model('SecureModel', 'secure'); $this->load->helper('date'); }
function canModerateNews() { if (isLoggedIn() == true) { if ($_SESSION['level'] == 1 || $_SESSION['level'] == 1) { return true; } } return false; }
/** * Enforces that the user is logged in. If the user isn't logged in, * redirect them to the given address and exit. MUST be called before any * output has been sent to the client, otherwise the function doesn't send headers. * * @param string $redirect The address to redirect to (default login.php), or null for no redirect. */ function requireLoggedIn($redirect = 'login.php') { if (!isLoggedIn()) { if (isset($redirect) && !headers_sent()) { header("Location: {$redirect}"); } exit; } }
public function __construct() { parent::__construct(); if (!isLoggedIn()) { redirect('admin/login'); } $this->load->model(array('mytreasure_model', 'pirate_model')); $this->load->helper(array('analytics')); }
function requireLogin() { $userId = isLoggedIn(); if (!$userId) { header('HTTP/1.1 403 Forbidden: Not logged in'); exit; } return $userId; }
function getSessionUser() { fetch_session(); if (isLoggedIn()) { return $_SESSION['username']; } else { return false; } }
/** VIEW RATES **/ function rate($result, $i) { include 'db_connect.php'; $avgRate = avgRating(mysql_result($result, $i, 'productId')); $roundRate = round($avgRate, 0, PHP_ROUND_HALF_DOWN); $maxRate = 5; $numRate = numRate(mysql_result($result, $i, 'productId')); ?> <table align="center"> <tr> <?php /** View rates via monkeys **/ for ($j = 0; $j < $roundRate; $j++) { if (isLoggedIn()) { ?> <form action="?p=rate" method="post"> <td><input type="hidden" id="rate" name="rate" value="<?php echo $j + 1; ?> "></td> <td><input type="hidden" id="prodId" name="prodId" value="<?php echo mysql_result($result, $i, 'productId'); ?> "></td> <td><input class="rateFill" type="image" src="commentsRatings/monkey.png" alt="Submit"> </td> </form> <?php } else { ?> <td><img class="rateFill" src="commentsRatings/monkey.png" alt="monkey"></td> <?php } } /** View rest of monkeys with lower opacity **/ for ($k = 0; $k < $maxRate - $roundRate; $k++) { if (isLoggedIn()) { ?> <form action="?p=rate" method="post"> <td><input type="hidden" id="rate" name="rate" value="<?php echo $roundRate + $k + 1; ?> "></td> <td><input type="hidden" id="prodId" name="prodId" value="<?php echo mysql_result($result, $i, 'productId'); ?> "></td> <td><input class="rateTotal" type="image" src="commentsRatings/monkey.png" alt="Submit"></td> </form> <?php } else { ?> <td><img class="rateTotal" src="commentsRatings/monkey.png" alt="monkey"></td> <?php } } echo "</tr></table>"; echo "<small> [" . $avgRate . "/" . $maxRate . "] " . $numRate . " votes</small>"; }