Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Login extends CI_Controller {
- public function __construct() {
- parent::__construct();
- }
- /**
- * Index Page for this controller.
- *
- * Maps to the following URL
- * http://example.com/index.php/welcome
- * - or -
- * http://example.com/index.php/welcome/index
- * - or -
- * Since this controller is set as the default controller in
- * config/routes.php, it's displayed at http://example.com/
- *
- * So any other public methods not prefixed with an underscore will
- * map to /index.php/welcome/<method_name>
- * @see https://codeigniter.com/user_guide/general/urls.html
- */
- public function index()
- {
- if ($this->session->userdata('is_logged_in')==TRUE)
- {
- redirect('dashboard');
- } else {
- $this->load->view('login');
- }
- }
- public function auth()
- {
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('password', 'Password', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- // $this->load->view('login');
- $this->index();
- } else {
- $username=$this->input->post('username');
- $password=$this->input->post('password');
- $result=$this->user_model->cek_login($username,$password);
- if($result)
- {
- // ada, maka ambil informasi dari database
- // $userdata = $result->row();
- // foreach($result as $row){
- // $session_data = array(
- // 'id_user' => $row->id_user,
- // 'nama' => $row->nama,
- // 'jenis_kelamin' => $row->jenis_kelamin,
- // 'alamat' => $row->alamat,
- // 'username' => $row->username,
- // 'level' => $row->level,
- // 'password' => $row->password,
- // 'is_logged_in' => TRUE
- // );
- // }
- // buat session
- // $this->session->set_userdata($session_data);
- // return true;
- redirect('dashboard');
- // $this->load->view('welcome_message');
- }
- else
- {
- echo "<script>
- alert('Username atau Password Salah!');
- window.location.href = '";
- echo site_url('login/');
- echo "';// your redirect path here
- </script>";
- }
- }
- }
- }
- function keluar ()
- {
- $this->session->session_destroy()
- redirect('login');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement