Ejemplo n.º 1
0
 public function __construct($user = null)
 {
     $this->_db = DB::connect();
     $this->_sessionName = Config::get('session/session_name');
     $this->_cookieName = Config::get('remember/cookie_name');
     if (!$user) {
         if (Session::exists($this->_sessionName)) {
             $user = Session::get($this->_sessionName);
             if ($this->find($user)) {
                 $this->_isLoggedIn = true;
             } else {
                 // logout
             }
         }
     } else {
         $this->find($user);
     }
 }
Ejemplo n.º 2
0
<?php

//namespace app\core;
use app\models\Cookie;
use app\models\Config;
use app\models\Session;
use app\models\User;
use app\classes\DB;
session_start();
$GLOBALS['config'] = ['mysql' => ['host' => '127.0.0.1', 'username' => 'root', 'password' => 'root', 'db' => 'test'], 'remember' => ['cookie_name' => 'hash', 'cookie_expiry' => 604800], 'session' => ['session_name' => 'root', 'token_name' => 'token']];
spl_autoload_register(function ($class) {
    require_once 'classes/' . $class . '.php';
});
require_once "functions/sanitize.php";
if (Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) {
    $hash = Cookie::get(Config::get('remember/cookie_name'));
    $hashCheck = DB::connect()->get('users_session', ['hash', '=', $hash]);
    if ($hashCheck->count()) {
        $user = new User($hashCheck->first()->user_id);
        $user->login();
    }
}
Ejemplo n.º 3
0
require_once 'autoload.php';
$ctrl = isset($_GET['ctrl']) ? $_GET['ctrl'] : 'News';
$act = isset($_GET['act']) ? $_GET['act'] : 'All';
$classController = 'app\\controllers\\' . $ctrl . 'Controller';
//require __DIR__ . '/classes/DB.php';
$controller = new $classController();
$method = "action" . $act;
$controller->{$method}();
if (require_once 'core/init.php') {
    echo 1;
}
use app\models\Session;
use app\models\User;
use app\classes\DB;
$user = DB::connect();
if (Session::exists('home')) {
    echo "<p><b>" . Session::flash('home') . "</b></p>";
}
$user = new User();
if ($user->isLoggedIn()) {
    ?>
    <p>Hello, <a href="profile.php?user=<?php 
    echo escape($user->data()->username);
    ?>
"><?php 
    echo $user->data()->username;
    ?>
</a></p>
    <ul>
        <li>You can <a href="logout.php">log out</a> here!</li>
        <li>You can <a href="update.php">update</a> your profile here!</li>