Advertisement
Guest User

Untitled

a guest
Jan 6th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Login extends CI_Controller {
  5.  
  6. public function __construct() {
  7. parent::__construct();
  8. }
  9.  
  10. /**
  11. * Index Page for this controller.
  12. *
  13. * Maps to the following URL
  14. * http://example.com/index.php/welcome
  15. * - or -
  16. * http://example.com/index.php/welcome/index
  17. * - or -
  18. * Since this controller is set as the default controller in
  19. * config/routes.php, it's displayed at http://example.com/
  20. *
  21. * So any other public methods not prefixed with an underscore will
  22. * map to /index.php/welcome/<method_name>
  23. * @see https://codeigniter.com/user_guide/general/urls.html
  24. */
  25. public function index()
  26. {
  27. if ($this->session->userdata('is_logged_in')==TRUE)
  28. {
  29. redirect('dashboard');
  30. } else {
  31.  
  32. $this->load->view('login');
  33. }
  34.  
  35. }
  36.  
  37. public function auth()
  38. {
  39.  
  40. $this->form_validation->set_rules('username', 'Username', 'required');
  41. $this->form_validation->set_rules('password', 'Password', 'required');
  42.  
  43.  
  44. if ($this->form_validation->run() == FALSE)
  45. {
  46. // $this->load->view('login');
  47. $this->index();
  48. } else {
  49.  
  50. $username=$this->input->post('username');
  51. $password=$this->input->post('password');
  52.  
  53. $result=$this->user_model->cek_login($username,$password);
  54.  
  55. if($result)
  56. {
  57. // ada, maka ambil informasi dari database
  58. // $userdata = $result->row();
  59. // foreach($result as $row){
  60. // $session_data = array(
  61. // 'id_user' => $row->id_user,
  62. // 'nama' => $row->nama,
  63. // 'jenis_kelamin' => $row->jenis_kelamin,
  64. // 'alamat' => $row->alamat,
  65. // 'username' => $row->username,
  66. // 'level' => $row->level,
  67. // 'password' => $row->password,
  68. // 'is_logged_in' => TRUE
  69. // );
  70. // }
  71.  
  72. // buat session
  73. // $this->session->set_userdata($session_data);
  74. // return true;
  75. redirect('dashboard');
  76. // $this->load->view('welcome_message');
  77. }
  78. else
  79. {
  80.  
  81. echo "<script>
  82. alert('Username atau Password Salah!');
  83. window.location.href = '";
  84. echo site_url('login/');
  85. echo "';// your redirect path here
  86. </script>";
  87.  
  88. }
  89.  
  90.  
  91. }
  92.  
  93. }
  94.  
  95.  
  96. }
  97. function keluar ()
  98. {
  99. $this->session->session_destroy()
  100. redirect('login');
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement