Beispiel #1
0
 /**
  * Determines whether a variable in this session section is set.
  * @param  string    name
  * @return bool
  */
 public function __isset($name)
 {
     if ($this->session->exists()) {
         $this->start();
     }
     return isset($this->data[$name]);
 }
Beispiel #2
0
 public function __construct($user = null)
 {
     $this->_db = DB::getInstance();
     $this->session_name = Config::get('session/session_name');
     $this->_cookieName = Config::get('remember/cookie_name');
     if (!$user) {
         if (Session::exists($this->session_name)) {
             if ($this->find_by_id(Session::get($this->session_name))) {
                 $this->_isLoggedIn = true;
             } else {
                 // logout process
                 $this->logout();
             }
         } elseif (Cookie::exists($this->_cookieName)) {
             $this->_db->get('user_id', 'users_session', array('hash', '=', Cookie::get($this->_cookieName)));
             if ($this->find_by_id($this->_db->first()->user_id)) {
                 Session::put($this->session_name, $this->data()->id);
                 Cookie::put($this->_cookieName, Cookie::get($this->_cookieName), Config::get('remember/cookie_expiry'));
                 Session::flash('success', 'Wellcome Back ' . $this->data()->username);
                 $this->_isLoggedIn = true;
             } else {
                 $this->logout();
             }
         }
     } elseif (is_numeric($user)) {
         if ($this->find_by_id($user)) {
             Session::put($this->session_name, $this->data()->id);
             $this->_isLoggedIn = true;
         } else {
             $this->logout();
         }
     } elseif (is_string($user)) {
         return $this->find($user);
     }
 }
Beispiel #3
0
 public function __construct($user = null)
 {
     $this->_db = DB::getInstance();
     $this->_sessionName = Config::get('session/session_name');
     $this->_cookieName = Config::get('remember/cookie_name');
     $this->_admSessionName = Config::get('session/admin_name');
     if (!$user) {
         if (Session::exists($this->_sessionName)) {
             $user = Session::get($this->_sessionName);
             if ($this->find($user)) {
                 $this->_isLoggedIn = true;
             } else {
                 // process logout
             }
         }
         if (Session::exists($this->_admSessionName)) {
             $user = Session::get($this->_admSessionName);
             if ($this->find($user)) {
                 $this->_isAdmLoggedIn = true;
             } else {
                 // process logout
             }
         }
     } else {
         $this->find($user);
     }
 }
Beispiel #4
0
 public static function get($key)
 {
     $prefixkey = self::$prefix . $key;
     if (Session::exists($prefixkey)) {
         return Session::get($prefixkey);
     }
 }
 public static function Create($p_sessionId, &$p_objectId, $p_objectTypeId = null, $p_userId = null, $p_updateStats = false)
 {
     if (empty($p_sessionId)) {
         throw new SessionIdNotSet();
     }
     $session = new Session($p_sessionId);
     if (!$session->exists()) {
         $sessionParams = array('start_time' => strftime("%Y-%m-%d %T"));
         if (!empty($p_userId)) {
             $sessionParams['user_id'] = $p_userId;
         }
         $session->create($sessionParams);
     }
     $sessionUserId = $session->getUserId();
     if (!empty($p_userId) && !empty($sessionUserId) && $sessionUserId != $p_userId) {
         throw new InvalidUserId();
     }
     $requestObject = new RequestObject($p_objectId);
     if (!$requestObject->exists()) {
         if (empty($p_objectTypeId)) {
             throw new ObjectTypeIdNotSet();
         }
         $requestObject->create(array('object_type_id' => $p_objectTypeId));
         $p_objectId = $requestObject->getObjectId();
     } elseif (empty($p_objectId)) {
         throw new ObjectIdNotSet();
     }
     if ($p_updateStats) {
         self::UpdateStats($p_sessionId, $p_objectId);
     }
 }
 /**
  * Si no existe una sesion para el usuario dado, se le redirecciona a la vista de login para que puedan iniciar sesion.
  */
 public function authorize_user()
 {
     if (!Session::exists($_COOKIE['user_id'])) {
         header("Location: " . APP_PREFIX . "/sessions/login");
         exit(0);
     }
 }
 public function startNewSession()
 {
     if (!loggedIn() && (privilege() != 'dean' || privilege() != 'director' || privilege() != 'admin')) {
         return 0;
     }
     $this->_connect();
     if (!Session::exists('semester_session')) {
         $type = 'odd';
         $session = date('Y');
     } else {
         if (Session::get('semester_type') === 'even') {
             $type = 'odd';
             $session = Session::get('semester_session');
         } else {
             if (Session::get('semester_type') === 'odd') {
                 $type = 'even';
                 $session = Session::get('semester_session') + 1;
             }
         }
     }
     $timestamp = date('Y-m-d H:i:s');
     $query = "INSERT INTO semester_session (session,type,starting_timestamp) VALUES('" . $session . "','" . $type . "','" . $timestamp . "')";
     $result = $this->_db->query($query);
     if ($this->_db->affected_rows && $this->_db->error == '') {
         $this->getRunningSession();
         return 1;
     } else {
         return 0;
     }
 }
Beispiel #8
0
 /**
  * Perform HTTP redirect with saving POST params in session.
  *
  * @param string $url URL redirect to.
  * @param array<mixed> $postData List of post params to save.
  */
 public static function httpRedirect($url = "", $postData = [])
 {
     if (preg_match("#^http[s]?://.+#", $url)) {
         // absolute url
         if (function_exists("http_redirect")) {
             http_redirect($url);
         } else {
             self::http_redirect($url);
         }
     } else {
         // same domain (relative url)
         if (!empty($postData)) {
             if (is_array($postData)) {
                 if (!Session::exists('_post') || !is_array($_SESSION['_post'])) {
                     Session::set('_post', []);
                 }
                 foreach ($postData as $fieldName => $fieldValue) {
                     Session::set("_post[{$fieldName}]", serialize($fieldValue));
                 }
             } else {
                 throw new HttpException("Wrong POST data.");
             }
         }
         if (function_exists("http_redirect")) {
             http_redirect("http://" . $_SERVER['SERVER_NAME'] . "/" . $url);
         } else {
             self::http_redirect("http://" . $_SERVER['SERVER_NAME'] . "/" . $url);
         }
     }
 }
Beispiel #9
0
 public function __construct($user = null)
 {
     $this->_db = DB::getInstance();
     //get instance of DB
     $this->_sessionName = Config::get('session/session_name');
     //get default session array name
     $this->_cookieName = Config::get('remember/cookie_name');
     //get default remember cookie name
     if (!$user) {
         //if user is not set
         if (Session::exists($this->_sessionName)) {
             //if the default session exists
             $user = Session::get($this->_sessionName);
             //set user (id) to the value of default session
             if ($this->find($user)) {
                 //find the user with this id
                 $this->_isLoggedIn = true;
                 //set private variable isLoggedIn to true
             } else {
                 $this->logout();
                 //if not, log out
             }
         }
     } else {
         $this->find($user);
         //if user is set, find user
     }
 }
Beispiel #10
0
 public function _index()
 {
     $post = Input::post();
     if (!empty($post)) {
         $validate = Validate::register($post);
         $token = Token::check($post['token']);
         if ($validate === TRUE && $token === TRUE) {
             User::addUser($post);
             echo 'Registered';
         } else {
             if (!$token) {
                 echo 'Security Token is missing';
             }
             echo '<pre>';
             print_r($validate);
             echo '</pre>';
         }
     } else {
         if (Session::exists('user_id')) {
             header('Location: /');
             exit;
         }
         self::init('RegisterModel', 'register', $arg);
     }
 }
 private static function getTracking($offer_id = null, $params = null, $options = null)
 {
     if (!$offer_id) {
         $offer_id = self::getSelectedOfferId();
     }
     if (!$params && !$options && Session::exists('tracking')) {
         $tracking = Session::read('tracking');
         if ($tracking['offer_id'] == $offer_id) {
             return $tracking;
         }
     }
     $user = Session::read('User');
     $response = ApiClient_HasOffers_Request::Execute('Offer', 'generateTrackingLink', array('offer_id' => $offer_id, 'affiliate_id' => $user['affiliate_id'], 'params' => $params, 'options' => $options));
     $tracking = $response->getValue();
     /* Array ( 
     			'affiliate_id' => 1,
     			'offer_id' => 2,
     			'click_url' => "http://demo.go2jump.org/aff_c?offer_id=2&aff_id=1",
     			'impression_pixel' => "<img src="http://demo.stage-go2jump.org/aff_i?offer_id=2&amp;aff_id=1" width="1" height="1">"
     		) */
     if (!$params && !$options) {
         Session::write('tracking', $tracking);
     }
     return $tracking;
 }
Beispiel #12
0
 public function __construct($user = NULL)
 {
     //get db instance
     $this->_db = DB::getInstance();
     //get session name, which is just 'user'. See init.php
     $this->_sessionName = Config::get('session/session_name');
     $this->_cookieName = Config::get('remember/cookie_name');
     if (!$user) {
         //if a user has NOT been defined
         if (Session::exists($this->_sessionName)) {
             $user = Session::get($this->_sessionName);
             //check if user exists
             if ($this->find($user)) {
                 //if there is a session and the user exists,
                 //signify they're logged in
                 $this->_isLoggedIn = true;
             } else {
                 //process logout
             }
         }
     } else {
         //if a user HAS been defined
         $this->find($user);
     }
     //end if
 }
Beispiel #13
0
 public function hasAlert()
 {
     if (\Session::exists($this->getPageName() . 'Alert')) {
         return true;
     }
     return false;
 }
Beispiel #14
0
 /**
  * Get the value of the variable session
  * @param $name string The name of variable in session
  * @return object Value of variable or null
  */
 public static function get($name)
 {
     if (Session::exists($name)) {
         return $_SESSION[$name];
     }
     return null;
 }
Beispiel #15
0
 /**
  * Will return location data given a user's ip address.
  * @param string $ip The ip address to backtrace.
  * @return array
  */
 public static function lookupIp($ip = null)
 {
     // Log whether the ip was null
     $wasNull = false;
     // Let's see if we've done this recently for this session
     if ($ip == null && Session::exists('backtrace_ip')) {
         return Session::get('backtrace_ip');
     }
     // Choose the ip to use
     if ($ip == null) {
         $wasNull = true;
         $ip = Session::getIpAddress();
     }
     // Format the host string for the api
     $host = sprintf(self::IP_BACKTRACE_HOST, $ip);
     // Get the response from the api
     $response = Utils::curl_get_contents($host);
     $data = unserialize($response);
     // Return the info in an array
     $result = array('ip' => $ip, 'city' => $data['geoplugin_city'], 'state' => $data['geoplugin_region'], 'state_full' => $data['geoplugin_regionName'], 'area_code' => $data['geoplugin_areaCode'], 'dma' => $data['geoplugin_dmaCode'], 'country_code' => $data['geoplugin_countryCode'], 'country_name' => $data['geoplugin_countryName'], 'continent_code' => $data['geoplugin_continentCode'], 'latitude' => $data['geoplugin_latitude'], 'longitude' => $data['geoplugin_longitude'], 'currency_code' => $data['geoplugin_currencyCode'], 'currency_symbol' => $data['geoplugin_currencySymbol']);
     // Now let's get the zip code
     $latLongLookup = self::lookupLatLong($result['latitude'], $result['longitude']);
     $result['zip'] = $latLongLookup['zip'];
     // Save this for future reference, if this was the current user's ip
     if ($wasNull) {
         Session::set('backtrace_ip', $result);
     }
     // Now let's return the result
     return $result;
 }
Beispiel #16
0
 public function login($id = null)
 {
     $user = $this->user;
     $this->data['user']['name'] = $user->data()->user;
     Config::set('html.title', 'Авторизация');
     Config::set('html.description.val', 'На этой странице можно залогиниться');
     //$user = new User();
     $salt = uniqid();
     if (!Session::exists(Config::get('session.token_name'))) {
         Token::generate();
     }
     if (Input::exists()) {
         if (Token::check(Input::get('token'))) {
             $validate = new VALIDATE();
             $validation = $validate->check($_POST, array('user' => array('required' => true), 'password' => array('required' => true)));
             if ($validate->passed()) {
                 $remember = Input::get('remember') === 'on' ? true : false;
                 $login = $user->login(Input::get('user'), Input::get('password'), null);
                 if ($login) {
                     Redirect::to('/');
                 } else {
                     echo '<p>Sorry, logging in failed</p>';
                 }
             } else {
                 foreach ($validation->errors() as $error) {
                     //echo $error, '<br/>';
                     $this->data['validate_errors'][] = $error;
                 }
             }
         }
     }
     //$this->data['id']=$id;
     //$this->data['name']=Input::get('name');
     $this->view('user/login');
 }
Beispiel #17
0
 public function __construct()
 {
     /*Verifica se existe uma sessão de login ativo*/
     if (!Session::exists('user')) {
         //caso o usuário não esteja logado
         //executa o método loginScreen da Classe Usuario
         require_once 'app/controllers/Usuario.php';
         return (new Usuario())->loginScreen();
     }
     $url = $this->parseUrl();
     if (file_exists('app/controllers/' . $url[0] . '.php')) {
         $this->controller = $url[0];
         unset($url[0]);
     }
     require_once 'app/controllers/' . $this->controller . '.php';
     $this->controller = new $this->controller();
     if (isset($url[1])) {
         /**
          * @todo Melhorar teste de permissão de rota
          */
         //Testa se o usuário tem permissão para a rota 'confirmDelete'
         if (Session::get('nivel') > 1 && $url[1] == 'confirmDelete') {
             require_once 'app/controllers/Home.php';
             return (new Home())->start();
         }
         if (method_exists($this->controller, $url[1])) {
             $this->method = $url[1];
             unset($url[1]);
         }
     }
     //reseta o array para iniciar no zero
     //se params estiver vazio, recebe um array vazio
     $this->params = $url ? array_values($url) : array();
     call_user_func_array(array($this->controller, $this->method), $this->params);
 }
Beispiel #18
0
 /**
  * @depends testSessionSet
  * @depends testSessionUnset
  */
 public function testSessionFlash()
 {
     \Session::flash("TestNotice", "Hello");
     $this->assertEquals(\Session::get("TestNotice"), "Hello");
     $this->assertEquals(\Session::flash("TestNotice"), "Hello");
     $this->assertEquals(\Session::exists("Test"), false);
 }
Beispiel #19
0
 public static function check($token)
 {
     if (Session::exists(self::$tokenName) && $token === Session::get(self::$tokenName)) {
         Session::delete(self::$tokenName);
         return true;
     }
     return false;
 }
/**
 * Retrieves privilege of the current logged in user
 * @return string
 * @author Harsh Vardhan Ladha & Yogesh Chauhan
 * @package MIS
 * @link http://mis.nits.ac.in
 * @license NIT Silchar
 */
function privilege()
{
    if (Session::exists('privilege')) {
        return Session::get('privilege');
    } else {
        return NULL;
    }
}
Beispiel #21
0
 /**
  * Sets initial language configuration for global use.
  */
 public function setLang()
 {
     $session = new Session();
     $vars = new Vars();
     if (!$session->exists('lang') || $vars->get('lang')) {
         $session->set('lang', $vars->get('lang') ? $vars->get('lang') : self::DEFAULT_LANG);
     }
 }
/**
 * Tells whether user is logged in or not
 * @return boolean
 * @package MIS
 * @name LoggedIn
 * @author Harsh Vardhan Ladha & Yogesh Chauhan
 * @copyright Computer Science & Engineering Department, NIT Silchar
 * @link http://mis.nits.ac.in
 * @license NIT Silchar
 */
function loggedIn()
{
    if (Session::exists('loggedIn') && Session::get('loggedIn') == 1) {
        return TRUE;
    } else {
        return FALSE;
    }
}
Beispiel #23
0
 public static function check($token)
 {
     if (Session::exists('token') && $token === Session::get('token')) {
         Session::delete('token');
         return true;
     }
     return false;
 }
Beispiel #24
0
 public static function ajaxCheck($token)
 {
     $tokenName = 'csrf_form_token';
     if (Session::exists($tokenName) && $token === Session::get($tokenName)) {
         return TRUE;
     }
     return FALSE;
 }
/**
 * Check whether user is logged in or not.
 * 
 */
function loggedIn()
{
    if (Session::exists('loggedIn') && Session::get('loggedIn') == 1) {
        return true;
    } else {
        return false;
    }
}
 public static function check($token)
 {
     $tokenName = Config::get('session/token_name');
     if (Session::exists($tokenName) && $token === Session::get($tokenName)) {
         return true;
     }
     return false;
 }
Beispiel #27
0
 public static function check_for_login($token)
 {
     $tokenName = Config::get('session/token_login');
     if (Session::exists($tokenName) && $token === Session::get($tokenName)) {
         Session::delete($tokenName);
         return true;
     }
     return false;
 }
Beispiel #28
0
 /**
  * Mengecek apakah token yang dikirimkan sama dengan token yang disimpan di session.
  *
  * @return string $token
  * @return bool
  */
 public static function match($token)
 {
     $token_name = Config::get('session.token_name');
     if (Session::exists($token_name) && $token === Session::get($token_name)) {
         Session::delete($token_name);
         return true;
     }
     return false;
 }
Beispiel #29
0
 public static function check($token)
 {
     $tokenName = Config::get('csrf.session');
     if (Session::exists($tokenName) && $token === Session::get($tokenName)) {
         Session::delete($tokenName);
         return true;
     }
     return false;
 }
 public function verifyOTP($response)
 {
     if (Session::exists('OTPCode') && $response === Session::get('OTPCode')) {
         Session::delete('OTPCode');
         return 1;
     } else {
         return 0;
     }
 }