I don't know what I am doing wrong here. I'm working on a login / logout module.
I auth against the DB to know is the user credentials are ok, if they are.....i want to set a session variable and use it in the controllers beforeRoute to check.
Problem is that, the variables comes empty from one controller to the other....
class LoginController extends BaseController{
public function index(){
$view=new View;
echo $view->render('app/views/login/LoginView.php');
}
public function check(){
$username = $this->f3->get('POST.username');
$password = $this->f3->get('POST.password');
$db = new \DB\Mongo('mongodb://XXXXXXXXXXX','XXXXXXXXX');
$user = new \DB\Mongo\Mapper($db, 'user');
$auth = new \Auth($user, array('id'=>'username', 'pw'=>'password'));
$result = $auth->login($username,$password); // returns true on successful login
if ($result == 1){
$feedback = "";
//new \DB\Mongo\Session($db);
$this->f3->set('SESSION.z',123);
echo "VAR:". $this->f3->get('SESSION.z'); //PRINTS 123
//$this->f3->reroute('/home'); //-------------GO TO HOME!
}else{
$feedback = "Username or password incorrect";
}
$this->f3->set('username',$username);
$this->f3->set('password',$password);
$this->f3->set('feedback',$feedback);
$view=new View;
echo $view->render('app/views/login/LoginView.php');
}
}
class HomeController extends BaseController{
public function index(){
echo "VAR:". $this->f3->get('SESSION.z'); //<----------------------EMPTY VALUE....
$view=new View;
echo $view->render('app/views/home/HomeView.php');
}
}