Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( !defined('BASEPATH')) exit('No direct script access allowed');
- class Admin extends CI_Controller
- {
- public function __constuct()
- {
- $this->load->library('session');
- parent::__constuct();
- $section = $this->uri->segment_array();
- array_shift($section);
- $section=end($this->uri->segment_array());
- if($section != 'login' && $section !='submit'
- && $this->session->userdata('user_id') == false
- && $this->session->userdata('is_admin') == false) {
- redirect(site_url('admin/admin'));
- }
- }
- public function index()
- {
- $this->load->model('user_model');
- $users = $this->user_model->get();
- $this->load->view('templates/header');
- $this->load->view('admin/admin', ['users' => $users] );
- $this->load->view('templates/footer');
- }
- public function dashboard()
- {
- $this->load->model('user_model');
- $users = $this->user_model->get();
- $this->load->view('templates/header');
- $this->load->view('admin/dashboard', ['users' => $users] );
- $this->load->view('templates/footer');
- }
- public function create_user()
- {
- $email = $this->input->post('email');
- $password = $this->input->post('password');
- //$this->db->get_where('user', ['email'=>$email]);
- $this->load->model('user_model');
- $this->user_model->create($email, $password);
- }
- public function delete_user($user_id)
- {
- $this->load->model('user_model');
- echo $this->user_model->delete($user_id);
- }
- public function login ($submit = null)
- {
- if($submit = null){
- $this->load->view('templates/header');
- $this->load->view('admin/admin');
- $this->load->view('templates/footer');
- }
- $email = $this->input->post('email');
- $password = $this->input->post('password');
- $this->load->model('user_model');
- $result = $this->user_model->login('admin', $email, $password);
- if($result == true) {
- session_start();
- $this->session->set_userdata('user_id', 1);
- redirect(site_url('admin/dashboard'));
- } else {
- redirect(site_url('admin/admin'));
- }
- }
- public function logout()
- {
- $this->session->sess_destroy();
- redirect(site_url('admin/admin'));
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement