Hello,
I'm a complete beginner with the php language and the Codeigniter framework but for a school project our teacher gave us the order to use only the Codeigniter framework to code our site.
I am currently following a video to help me make the authentication system but when I launch the connection with the login form, I have a problem that results from that. I looked to see if I had an error in the console but there is nothing at all indicated.
I tried doing a var_dump to show me the error and it only shows me "NULL".
I tried to fix the problem as the instructor put it in his video by using the if(!is_null(item)) command... but after that nothing happens.
Here is my code, Controller, Routes and Views and also the screens.
Login Controller :
Code:
$record = $model->where("email", $this->request->getVar("email"))
->where("password", $this->request->getVar("password"))
->first();
var_dump($record);
$session = session();
if(!is_null($record)){
//donnée trouvée dans la bdd
$sess_data = [
"email" => $record["email"],
"pseudo" => $record["pseudo"],
"id_role" => $record["id_role"]
];
$session->set($sess_data);
if($record['id_role']=="eleve"){
// direction tableau de bord "élève"
return view('eleve_dashboard/dashboard');
}
else if($record['id_role']=="modo"){
// direction tableau de bord "modo"
return view('modo_dashboard/dashboard');
}
else{
// direction tableau de bord "admin"
return view('admin_dashboard/dashboard');
}
return redirect()->to(base_url($url));
}
else{
$session->set("failed_message","Vos informations ne correspondent pas, réessayer.");
$session->markAsFlashdata('failed_message');
return redirect()->back()->withInput();
}
login.php Views :
Code:
<h3>Connexion</h3>
<?php $session = session(); ?>
<?php if(!is_null($session->getFlashdata('failed_message'))): ?>
<div class="alert alert-danger">
<?php echo $session->getFlashdata('failed_message'); ?>
</div>
<?php endif ?>
<?php $validation = \Config\Services::validation(); ?>
<form action="<?php echo base_url('login')?>" method="POST">
<div class="input__item">
<input type="text" placeholder="Email address" name="email" value="<?php echo old('email')?>">
<span class="icon_mail"></span>
<div class="text-danger">
<?php echo $validation->getError("email")?>
</div>
</div>
<div class="input__item">
<input type="text" placeholder="Password" name="password" value="<?php echo old('password')?>">
<span class="icon_lock"></span>
<div class="text-danger">
<?php echo $validation->getError("password")?>
</div>
</div>
<button type="submit" name ="identification" class="site-btn">Se connecter</button>
</form>
Routes :
Code:
$routes->get('/login','Login::login');
$routes->post('/login','Login::login');
$routes->group('groupe', ['namespace' => 'App\Controllers'], function ($routes) {
$routes->get('eleve', 'DashboardController::eleve');
$routes->get('admin', 'AdminDashboardController::index');
});
I got this as an error, I log in with the right email and password but it leaves me on this page with the error that my information is not correct.
With var_dump
Normally it should direct me to this page.
Thanks for any help you can give me.