Advertisement
Guest User

Controller Login

a guest
Jul 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <?php
  2.  
  3. class Login extends CI_Controller {
  4.  
  5. function __construct() {
  6. parent::__construct();
  7. //session_start();
  8. $this->load->model(array('user_model'));
  9. $this->load->helper(array('form', 'url', 'html', 'date', 'form_helper', 'file'));
  10. $this->load->library(array('form_validation', 'table', 'template', 'session', 'simple_login'));
  11. $this->load->database();
  12. $this->load->helper('url');
  13. }
  14.  
  15. function index() {
  16. $session = $this->session->userdata('isLogin');
  17. if ($session == FALSE) {
  18. $this->template->displayUser('template_user/home');
  19. } else {
  20. if ($this->session->userdata('status') == 'Super Admin') {
  21. redirect('dashboard');
  22. } else if ($this->session->userdata('status') == 'Admin') {
  23. redirect('admin');
  24. } else if ($this->session->userdata('status') == 'User') {
  25. redirect('developer');
  26. }
  27. }
  28. }
  29.  
  30. function proses() {
  31. $this->form_validation->set_rules('username', 'username', 'required');
  32. $this->form_validation->set_rules('password', 'password', 'required');
  33.  
  34. if ($this->form_validation->run() == FALSE) {
  35. $this->template->displayUser('template_user/home');
  36. } else {
  37.  
  38. $usr = $this->input->post('username');
  39. $psw = $this->input->post('password');
  40. //$u = mysqli_real_escape_string($usr);
  41. //$p = (mysqli_real_escape_string($psw));
  42. $cek = $this->user_model->cek($usr, $psw);
  43. if ($cek->num_rows() > 0) {
  44. //login berhasil, buat session
  45. foreach ($cek->result() as $qad) {
  46. $sess_data['id_user'] = $qad->id_user;
  47. $sess_data['nama'] = $qad->nama;
  48. $sess_data['username'] = $qad->username;
  49. $sess_data['status'] = $qad->status;
  50. $this->session->set_userdata('isLogin', TRUE);
  51. $this->session->set_userdata($sess_data);
  52. }
  53. if ($this->session->userdata('status') == 'Super Admin') {
  54. redirect('dashboard');
  55. } else if ($this->session->userdata('status') == 'Admin') {
  56. redirect('admin');
  57. } else if ($this->session->userdata('status') == 'User') {
  58. redirect('developer');
  59. }
  60. } else {
  61. $this->session->set_flashdata('result_login', '<br>Anda belum Login!<br>Username atau Password yang anda masukkan salah.');
  62. redirect('login');
  63. }
  64. }
  65. }
  66.  
  67. function logout() {
  68. $this->session->sess_destroy();
  69. redirect('maps');
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement