init() public static method

starts the session
public static init ( )
 /**
  * Returns the object of the active session.
  * Tries to find an existing session. 
  * Otherwise creates a new session.
  * 
  * @return 	 Session 		$session
  */
 public function get()
 {
     // get session id
     $this->sessionID = $this->readSessionID();
     $this->session = null;
     // get existing session
     if (!empty($this->sessionID)) {
         $this->session = $this->getExistingSession($this->sessionID);
     }
     // create new session
     if ($this->session == null) {
         $this->session = $this->create();
     }
     self::$activeSession = $this->session;
     // call shouldInit event
     if (!defined('NO_IMPORTS')) {
         EventHandler::fireAction($this, 'shouldInit');
     }
     // init session
     $this->session->init();
     // call didInit event
     if (!defined('NO_IMPORTS')) {
         EventHandler::fireAction($this, 'didInit');
     }
     return $this->session;
 }
Exemplo n.º 2
0
 /**
  * get instance of Session
  * @return Session
  */
 public static function getInstance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new self();
     }
     self::$_instance->init();
     return self::$_instance;
 }
Exemplo n.º 3
0
 function selectlanguage()
 {
     if ($_POST && $_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest") {
         $sonuc = array();
         $form = $this->load->otherClasses('Form');
         Session::init();
         $form->post("lang", true);
         $dil = $form->values['lang'];
         if ($dil == "tr" || $dil == "en" || $dil == "fr" || $dil == "ar" || $dil == "de" || $dil == "zh") {
             if (isset($_SESSION['dil'])) {
                 unset($_SESSION['dil']);
                 Session::set("dil", $dil);
             } else {
                 Session::set("dil", $dil);
             }
         } else {
             //eğer dil yoksa
             $dil = 'en';
             Session::set("dil", $dil);
         }
         $sonuc["lang"] = $dil;
         echo json_encode($sonuc);
     } else {
         die("Hacklemeye mi Çalışıyorsun pezevenk?");
     }
 }
 /**
  * Login Process (for Administrator)
  *
  * @return bool success state
  * */
 public function login()
 {
     //the first step checks
     if (!isset($_POST['adminid']) or empty($_POST['adminid'])) {
         $_SESSION["feedback_negative"][] = FEEDBACK_USERNAME_FIELD_EMPTY;
         return false;
     }
     if (!isset($_POST['password']) or empty($_POST['password'])) {
         $_SESSION["feedback_negative"][] = FEEDBACK_PASSWORD_FIELD_EMPTY;
         return false;
     }
     //ready to verify
     $sth = $this->db->prepare("SELECT adminid,\n\t\t\t\t\t\t\t\t\t\tadminName,\n\t\t\t\t\t\t\t\t\t\tpassword\n\t\t\t\t\t\t\t\t FROM   admin\n\t\t\t\t\t\t\t\t WHERE  adminid= :adminid");
     $sth->execute(array(':adminid' => $_POST['adminid']));
     $count = $sth->rowCount();
     //if ther is NOT such result
     if ($count != 1) {
         $_SESSION["feedback_negative"][] = FEEDBACK_LOGIN_FIELD;
         return false;
     }
     $result = $sth->fetch();
     if ($_POST['password'] === $result->password) {
         // set the user info into session
         Session::init();
         Session::set('admin_logged_in', true);
         Session::set('adminid', $result->adminid);
         Session::set('adminName', $result->adminName);
         //rerurn true to make clear thar the login was successful
         return true;
     } else {
         $_SESSION["feedback_negative"][] = FEEDBACK_PASSWORD_WRONG;
         return false;
     }
 }
Exemplo n.º 5
0
 public function __construct()
 {
     Session::init();
     if (Session::get('loggin') == false) {
         $this->login();
     }
 }
Exemplo n.º 6
0
 public function run()
 {
     $login = $_POST['login'];
     $password = $_POST['password'];
     /* PDO */
     $res = $this->db->prepare("SELECT userid, role FROM users WHERE\n                login = :login AND password = :password");
     $res->execute(array(':login' => $login, ':password' => Hash::create(HASH_METHOD, $password, HASH_PASSWORD_KEY)));
     //        $data = $res->fetchAll();
     $count = $res->rowCount();
     /* mysqli */
     /*$res = $this->db->prepare("select id from users
           where login = ?
           and password = MD5(?)");
       $res->bind_param("ss",$login,$password);
       $res->execute();
       $res->bind_result($ret);
       $res->fetch();*/
     $data = $res->fetch();
     if ($count > 0) {
         //login
         Session::init();
         Session::set('role', $data['role']);
         Session::set('loggedIn', true);
         Session::set('userid', $data['userid']);
         header('Location:../dashboard');
         exit;
     } else {
         //show an Error
         header('Location:../login');
         exit;
     }
     //        return $ret;
 }
Exemplo n.º 7
0
 function __construct()
 {
     Session::init();
     $this->registry = Registry::get_instance();
     // létrehozzuk a view objektumot és hozzárendeljük a $view tulajdonsághoz
     $this->view = new View();
 }
Exemplo n.º 8
0
 public function render($name)
 {
     Session::init();
     require 'views/navbar.php';
     require 'views/' . $name . '.php';
     require 'views/footer.php';
 }
Exemplo n.º 9
0
 /**
  * @throws \Exception
  */
 protected function init()
 {
     $this->setEnvironment();
     // Load class aliases
     $aliases = Config::get('aliases');
     foreach ($aliases as $orig => $new) {
         class_alias($orig, $new, true);
     }
     static::$container = new Container();
     Session::init();
     Request::init();
     $this->initRouter();
     $databaseConfig = Config::get('database');
     if ($databaseConfig !== null && is_array($databaseConfig)) {
         $this->capsule = new Capsule();
         foreach ($databaseConfig as $name => $conf) {
             if (array_key_exists('name', $conf) && strlen($conf['name']) > 0) {
                 $name = $conf['name'];
                 unset($conf['name']);
             }
             $this->capsule->addConnection($conf, $name);
         }
         $this->capsule->bootEloquent();
     }
     $hookConfig = Config::get('hooks');
     if (is_array($hookConfig)) {
         foreach ($hookConfig as $event => $callable) {
             EventHandler::addListener($event, $callable);
         }
     }
     EventHandler::triggerEvent('whirlpool-initialized', $this);
 }
Exemplo n.º 10
0
 function __construct()
 {
     Session::init();
     Session::set('active', "about");
     Session::set('title', "О нас");
     parent::__construct();
 }
 public function create()
 {
     Session::init();
     if (Session::get('username')) {
         if (!Session::get('admin')) {
             Url::redirect('welcome');
         }
     } else {
         Url::redirect('');
     }
     $data['title'] = 'Application Analytics';
     $data['gender'] = $this->mab->get_gender();
     $data['yearsInSchool'] = $this->mab->get_years_in_school();
     $data['apps'] = $this->mab->get_apps_by_issue();
     $data['apps1'] = $this->mab->get_apps_by_issue_rank(1);
     $data['apps2'] = $this->mab->get_apps_by_issue_rank(2);
     $data['apps3'] = $this->mab->get_apps_by_issue_rank(3);
     $data['apps_by_college'] = $this->mab->get_apps_by_college();
     $data['marketing_data'] = $this->mab->get_marketing_data();
     $data['issues'] = $this->apply_model->getAllIssues();
     if (isset($_POST['submit'])) {
         $issueId = $_POST['issues'];
         $data['issues_by_gender'] = $this->mab->get_issues_by_gender($issueId);
     }
     View::rendertemplate('exec_header', $data);
     View::render('analytics/application_analytics', $data, $error);
     View::rendertemplate('footer', $data);
 }
Exemplo n.º 12
0
 public function run($static = false)
 {
     $form = new Form();
     $form->post('login')->val('blank')->post('password')->val('blank');
     if (!$form->submit()) {
         // Error
         $this->_error($static);
         return false;
     }
     $data = $form->fetch();
     $login = $data['login'];
     $password = Hash::create('sha256', $data['password'], PASS_HASH_KEY);
     $query = "SELECT userid, login, role FROM user WHERE login = :login AND password = :password";
     if (!($result = $this->db->select($query, array(':login' => $login, ':password' => $password)))) {
         $this->_error($static);
         return false;
     }
     Session::init();
     Session::set('userid', $result[0]['userid']);
     Session::set('login', $result[0]['login']);
     Session::set('role', $result[0]['role']);
     Session::set('loggedIn', true);
     if ($static) {
         header('location:' . URL . 'dashboard');
     }
     echo json_encode('success');
 }
Exemplo n.º 13
0
 /**
  * Default method
  * @return [type] [description]
  */
 public function index()
 {
     if (Session::get('logined') !== null) {
         if (Session::get('logined')) {
             $this->getUserLogin();
             exit;
         }
     }
     $auth = new Authenticate();
     if (isset($_POST['user_id']) && isset($_POST['id_token'])) {
         $user_id = $_POST['user_id'];
         $id_token = $_POST['id_token'];
         if ($auth->checkLogin($user_id, $id_token)) {
             Session::init();
             Session::set('id_token', $id_token);
             Session::set('user_id', $user_id);
             Session::set('logined', true);
             echo json_encode('success');
             exit;
         } else {
             echo json_encode('need login with google ID');
             exit;
         }
     } else {
         echo json_encode('need login with google ID');
         exit;
     }
 }
 public function run()
 {
     /*
      * md5 is a 32 bit hash
      */
     $statement = $this->db->prepare("SELECT id, role FROM users WHERE login = :user AND password = :pass");
     $statement->execute(array(':user' => $_POST['user'], ':pass' => Hash::create('sha256', $_POST['pass'], HASH_KEY)));
     /*
      * The Obj returned by $statement was 'Array of Arrays'
      */
     $result = $statement->fetchAll();
     //$statement returns an Array of objects
     //print_r($result);
     //echo '</br>';
     $data = $result['0'];
     //print_r($data);
     //echo '</br>role='.$data['role'];
     $count = $statement->rowCount();
     if ($count > 0) {
         //log in the user
         Session::init();
         Session::set('userid', $data['id']);
         Session::set('role', $data['role']);
         Session::set('loggedIn', true);
         header('location: ../dashboard');
     } else {
         //show an error
         header('location: ../login');
     }
 }
Exemplo n.º 15
0
 public static function initialize()
 {
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     try {
         // Initialize local session
         Session::init();
         if (!empty($_GET['logout'])) {
             self::destroy();
             Session::init();
         }
         if (!Session::userIsLoggedIn() && Request::cookie('remember_me')) {
             if (!LoginModel::loginWithCookie(Request::cookie('remember_me'))) {
                 LoginModel::deleteCookie();
             }
         }
         $currentUrl = $_SERVER['REQUEST_URI'];
         $end = strpos($currentUrl, '?');
         if ($end === false) {
             $end = strpos($currentUrl, '#');
         }
         if ($end !== false) {
             $currentUrl = substr($currentUrl, 0, $end);
         }
         // Initialize Facebook session
         /*self::$facebookSession = new FacebookSessionWrapper(
             Tools::getBaseUrl() . $currentUrl,
             Tools::getBaseUrl() . '/logout/'
           );*/
     } catch (\Exception $ex) {
     }
 }
Exemplo n.º 16
0
 /**
  * Change current Session Handler
  *
  * @param string|Next\Session\Handlers\Handler $handler
  *   Handler Object or Handler Name
  *
  * @throws Next\Session\Handlers\HandlerException
  *   Changing Session Handler to a invalid Handler, characterized as
  *   instance of Next\Session\Hndlers\Handler
  */
 public function changeHandler($handler)
 {
     // If we don't have a true Handler...
     if (!$handler instanceof Handler) {
         // ... let's find an assigned Handler that matches given string
         $test = $this->handlers->find($handler);
         // Nothing Found?
         if (!$test instanceof Handler) {
             throw HandlersException::unknownHandler((string) $handler);
         }
         // Yeah! We're ninjas!
         $handler = $test;
     }
     // Committing Session
     $this->session->commit();
     // Setting Session Options with Handler Options
     if (isset($handler->getOptions->savePath)) {
         $this->session->setSessionSavePath($handler->getOptions->savePath);
     }
     $lifetime = isset($handler->getOptions->lifetime) ? $handler->getOptions->lifetime : 0;
     if ($lifetime > 0) {
         $this->session->setSessionLifetime($lifetime);
     }
     // Changing current Session Handler
     $this->handler =& $handler;
     // Restarting Session
     $this->session->init($this->session->getSessionName(), $this->session->getSessionID());
 }
Exemplo n.º 17
0
 function __construct()
 {
     Session::init();
     Session::set('active', "timet");
     Session::set('title', "Афиша");
     parent::__construct();
 }
Exemplo n.º 18
0
 public static function handleLogin()
 {
     Session::init();
     if ($_SESSION['user_logged_in'] == false) {
         Session::destroy();
     }
 }
 public function run()
 {
     $pass = $_POST['password'];
     $username = $_POST['username'];
     $sth = $this->db->prepare("SELECT * FROM users WHERE \n\t\t\t\tusername = :username ");
     $sth->execute(array(':username' => $_POST['username']));
     $data = $sth->fetchAll();
     $count = $sth->rowCount();
     if ($count > 0) {
         foreach ($data as $value) {
             $set_password = $value['password'];
             $set_username = $value['username'];
             $set_role = $value['role'];
         }
         $input_password = crypt($pass, $set_password);
         if ($input_password == $set_password && $username == $set_username) {
             // login
             Session::init();
             Session::set('loggedIn', true);
             Session::set('username', $set_username);
             Session::set('role', $set_role);
             header('location: ../dashboard');
         } else {
             header('location: ../login');
         }
     } else {
         header('location: ../login');
     }
 }
Exemplo n.º 20
0
 function __construct()
 {
     Session::init();
     Session::set('active', "services");
     Session::set('title', "Услуги");
     parent::__construct();
 }
Exemplo n.º 21
0
 /**
  * Construct the (base) controller. This happens when a real controller is constructed, like in
  * the constructor of IndexController when it says: parent::__construct();
  */
 function __construct()
 {
     // always initialize a session
     Session::init();
     // create a view object to be able to use it inside a controller, like $this->View->render();
     $this->View = new View();
 }
Exemplo n.º 22
0
 public function run()
 {
     $stch = $this->db->prepare("SELECT * FROM users WHERE login = :login AND password = MD5(:password)");
     $stch->execute(array(':login' => $_POST['login'], ':password' => $_POST['password']));
     $data = $stch->fetchAll();
     $count = $stch->rowCount();
     if ($count > 0) {
         //login
         Session::init();
         Session::set('role', $data['0']['role']);
         Session::set('loggedIn', true);
         Session::set('login', $data['0']['login']);
         Session::set('office', $data['0']['office']);
         Session::set('comment', $data['0']['comment']);
         //            echo '
         //                <script type="text/javascript">
         //                    location.replace("../dashboard");
         //                </script>
         //                ';
         if (Session::get('role') != MOSCOW) {
             header('location: ../dashboard');
         } else {
             header('location: ../sales');
         }
     } else {
         //show an error
         header('location: ../index');
     }
     //        echo '<pre>';
     //        print_r($data);
     //        echo '</pre>';
     //        echo $data['0']['role'];
 }
Exemplo n.º 23
0
 public function create()
 {
     Session::init();
     if (Session::get('username')) {
         if (Session::get('admin')) {
             Url::redirect('exec');
         }
     } else {
         Url::redirect('');
     }
     $data['title'] = 'Wishlist';
     $tripId = \helpers\Session::get("tripId");
     $data['applicants'] = $this->mab->get_wishlist($tripId);
     $data['roster'] = $this->mab->get_official_roster($tripId);
     foreach ($data['applicants'] as $applicants_info) {
         $applicants_info->age = $this->mab->get_age_at_time($applicants_info->dateOfBirth, date('Y-m-d', time()));
     }
     if (isset($_POST['draft'])) {
         $trip_id = $this->mab->verify_applicant($_POST['applicationId']);
         if ($trip_id == NULL) {
             $this->mab->add_to_trip($_POST['applicationId'], $tripId);
             $this->mab->applicant_becomes_person($_POST['applicationId']);
             $this->mab->person_becomes_trip_member($_POST['applicationId'], $tripId);
         } else {
             if ($trip_id == $tripId) {
                 echo 'This is your participant';
             } else {
                 echo 'Application has already been drafted.';
             }
         }
     }
     View::rendertemplate('header', $data);
     View::render('wishlist/wishlist', $data, $error);
     View::rendertemplate('footer', $data);
 }
 function logout()
 {
     Session::init();
     Session::destroy();
     header('location:' . URL . 'admincp');
     exit;
 }
Exemplo n.º 25
0
 function __construct()
 {
     parent::__construct();
     Session::init();
     Session::set('active', "index");
     Session::set('title', "Главная");
 }
Exemplo n.º 26
0
 public function loginWithCookies()
 {
     $cookie = isset($_COOKIE['rememberme']) ? $_COOKIE['rememberme'] : '';
     // do we have a cookie var ?
     if (!$cookie) {
         $_SESSION["feedback_negative"][] = FEEDBACK_COOKIE_INVALID;
         return false;
     }
     // check cookie's contents, check if cookie contents belong together
     list($user_id, $token, $hash) = explode(':', $cookie);
     if ($hash !== hash('sha256', $user_id . ':' . $token)) {
         $_SESSION["feedback_negative"][] = FEEDBACK_COOKIE_INVALID;
         return false;
     }
     // do not log in when token is empty
     if (empty($token)) {
         $_SESSION["feedback_negative"][] = FEEDBACK_COOKIE_INVALID;
         return false;
     }
     // get real token from database (and all other data)
     $query = $this->db->prepare("SELECT user_id, user_name, user_email, user_password_hash, user_active,\n                                          user_account_type,  user_avatar,  user_last_failed_login, user_personal_iduser_personal\n                                     FROM users\n                                     WHERE user_id = :user_id\n                                       AND user_rememberme_token = :user_rememberme_token\n                                       AND user_rememberme_token IS NOT NULL\n                                       AND user_provider_type = :provider_type");
     $query->execute(array(':user_id' => $user_id, ':user_rememberme_token' => $token, ':provider_type' => 'DEFAULT'));
     $count = $query->rowCount();
     if ($count == 1) {
         // fetch one row (we only have one result)
         $result = $query->fetch();
         $st = $this->db->prepare("SELECT first_name,\n                                          last_name\n                                   FROM   user_personal\n                                   WHERE  iduser_personal = '" . $result->user_personal_iduser_personal . "'");
         $st->execute();
         $user_details = $st->fetch();
         // TODO: this block is same/similar to the one from login(), maybe we should put this in a method
         // write data into session
         Session::init();
         Session::set('user_logged_in', true);
         Session::set('uid', $result->user_id);
         Session::set('name', $user_details->first_name . ' ' . $user_details->last_name);
         Session::set('username', $result->user_name);
         Session::set('user_email', $result->user_email);
         Session::set('user_account_type', $result->user_account_type);
         Session::set('user_provider_type', 'DEFAULT');
         // Session::set('user_avatar_file', $this->getUserAvatarFilePath());
         // call the setGravatarImageUrl() method which writes gravatar urls into the session
         //$this->setGravatarImageUrl($result->user_email, AVATAR_SIZE);
         // generate integer-timestamp for saving of last-login date
         $user_last_login_timestamp = time();
         // write timestamp of this login into database (we only write "real" logins via login form into the
         // database, not the session-login on every page request
         $sql = "UPDATE users SET user_last_login_timestamp = :user_last_login_timestamp WHERE user_id = :user_id";
         $sth = $this->db->prepare($sql);
         $sth->execute(array(':user_id' => $user_id, ':user_last_login_timestamp' => $user_last_login_timestamp));
         // NOTE: we don't set another rememberme-cookie here as the current cookie should always
         // be invalid after a certain amount of time, so the user has to login with username/password
         // again from time to time. This is good and safe ! ;)
         $_SESSION["feedback_positive"][] = FEEDBACK_COOKIE_LOGIN_SUCCESSFUL;
         return true;
     } else {
         $_SESSION["feedback_negative"][] = FEEDBACK_COOKIE_INVALID;
         return false;
     }
 }
Exemplo n.º 27
0
 function __construct()
 {
     // everytime a controller is created, start a session
     // TODO: this is a singleton. should this be handled in another way ?
     Session::init();
     // everytime a controller is created, create a view object (that does nothing, but provides the render() method)
     $this->view = new View();
 }
Exemplo n.º 28
0
 public function init($args)
 {
     parent::init($args);
     // set the database session handlers
     session_set_save_handler(array($this, 'sess_open'), array($this, 'sess_close'), array($this, 'sess_read'), array($this, 'sess_write'), array($this, 'sess_destroy'), array($this, 'sess_gc'));
     // necessary http://www.php.net/manual/en/function.session-set-save-handler.php
     register_shutdown_function('session_write_close');
 }
Exemplo n.º 29
0
 public function __construct()
 {
     //Iniciamos la sesion PHP
     Session::init();
     $this->view = new View();
     $this->loadModel();
     $errors = array();
 }
Exemplo n.º 30
0
 public function __construct()
 {
     parent::__construct();
     Session::init();
     if (!Session::get('logged_in')) {
         redirect('auth/login');
     }
 }