Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <?php if ( !defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Admin extends CI_Controller
  4. {
  5.  
  6. public function __constuct()
  7. {
  8.  
  9. $this->load->library('session');
  10. parent::__constuct();
  11. $section = $this->uri->segment_array();
  12. array_shift($section);
  13.  
  14. $section=end($this->uri->segment_array());
  15. if($section != 'login' && $section !='submit'
  16. && $this->session->userdata('user_id') == false
  17. && $this->session->userdata('is_admin') == false) {
  18. redirect(site_url('admin/admin'));
  19. }
  20. }
  21.  
  22. public function index()
  23. {
  24. $this->load->model('user_model');
  25. $users = $this->user_model->get();
  26. $this->load->view('templates/header');
  27. $this->load->view('admin/admin', ['users' => $users] );
  28. $this->load->view('templates/footer');
  29. }
  30.  
  31. public function dashboard()
  32. {
  33. $this->load->model('user_model');
  34. $users = $this->user_model->get();
  35.  
  36. $this->load->view('templates/header');
  37. $this->load->view('admin/dashboard', ['users' => $users] );
  38. $this->load->view('templates/footer');
  39. }
  40.  
  41. public function create_user()
  42. {
  43. $email = $this->input->post('email');
  44. $password = $this->input->post('password');
  45.  
  46. //$this->db->get_where('user', ['email'=>$email]);
  47.  
  48. $this->load->model('user_model');
  49. $this->user_model->create($email, $password);
  50. }
  51.  
  52. public function delete_user($user_id)
  53. {
  54. $this->load->model('user_model');
  55. echo $this->user_model->delete($user_id);
  56. }
  57.  
  58. public function login ($submit = null)
  59. {
  60. if($submit = null){
  61. $this->load->view('templates/header');
  62. $this->load->view('admin/admin');
  63. $this->load->view('templates/footer');
  64. }
  65.  
  66. $email = $this->input->post('email');
  67. $password = $this->input->post('password');
  68.  
  69. $this->load->model('user_model');
  70. $result = $this->user_model->login('admin', $email, $password);
  71.  
  72. if($result == true) {
  73. session_start();
  74. $this->session->set_userdata('user_id', 1);
  75. redirect(site_url('admin/dashboard'));
  76. } else {
  77. redirect(site_url('admin/admin'));
  78. }
  79. }
  80.  
  81. public function logout()
  82. {
  83. $this->session->sess_destroy();
  84. redirect(site_url('admin/admin'));
  85. }
  86.  
  87. }
  88.  
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement