I have created registration and login successfully. Now i want 2 roles i.e Admin and users. please help how to proceed.
My SQL table contains: user, email, password, verification key, is_verified, role(admin and user).
Login Controller:
function validation()
{
$this->form_validation->set_rules('user_email', 'Email Address', 'required|trim|valid_email');
$this->form_validation->set_rules('user_password', 'Password', 'required');
if ($this->form_validation->run()) {
$result = $this->loginModel->can_login($this->input->post('user_email'), $this->input->post('user_password'));
if ($result == $query) {
redirect('Admin');
} else {
$this->session->set_flashdata('message',$result);
redirect('login');
}
} else {
$this->index();
}
}
Login Model:
function can_login($email, $password)
{
$this->db->where('email', $email);
$query = $this->db->get('codeigniter_register');
if($query->num_rows() > 0) {
foreach($query->result() as $row) {
if($row->is_email_verified == 'yes') {
$store_password = $this->encryption->decrypt($row->password);
if($password == $store_password) {
$this->session->set_userdata('id', $row->id);
} else {
return 'Wrong Password';
}
} else {
return 'First verified your email address';
}
}
} else {
return 'Wrong Email Address';
}
}
Admin Controller:
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
if(!$this->session->userdata('id')) {
redirect('login');
}
}
function index()
{
echo '<p align="center"><a href="'.base_url().'admin/logout">Logout</a></p>';*/
if($this->session->userdata('role')==='Admin') {
$this->load->view('dashboard_view');
} else {
echo "Access Denied";
}
}
}
I have created registration and login successfully. Now i want 2 roles i.e Admin and users. please help how to proceed.
My SQL table contains: user, email, password, verification key, is_verified, role(admin and user).
Create one more session which will hold the role(user or admin) and use this to process further.
$this->session->set_userdata('role', $row->role);