Advertisement
ksubagja

auth.controller

Jan 7th, 2021 (edited)
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Auth extends CI_Controller {
  4.   public function __construct(){
  5.     parent::__construct();
  6.    
  7.     $this->load->model('Login_model', 'login');
  8.     $this->session->sess_destroy();
  9.      
  10.   }
  11.  
  12.   public function index()
  13.   {
  14.     $this->load->library('form_validation');
  15.  
  16.     $this->form_validation->set_rules('username', 'Username', 'required', [
  17.         'required' => 'Username harus diisi'
  18.     ]);
  19.     $this->form_validation->set_rules('password', 'Password', 'required', [
  20.         'required' => 'Password harus diisi'
  21.     ]);
  22.     if ($this->form_validation->run() == FALSE) {
  23.       $data['judul'] = 'Login Page';
  24.       $this->load->view('template/headlogin', $data);
  25.       $this->load->view('admin/login');
  26.       $this->load->view('template/footerlogin');
  27.     } else {
  28.       $data = $this->login->login();
  29.       // var_dump($data); die;
  30.       $userdata = [
  31.           'username' => $data['username'],
  32.           'status' => $data['status']
  33.       ];
  34.       $this->session->set_userdata($userdata);
  35.  
  36.       if ($data['status'] == 'Admin') {
  37.         //controller admin dipanggil
  38.         redirect('Admin');      
  39.       } else {
  40.         redirect('User');
  41.       }    
  42.     }
  43.   }
  44.  
  45.   public function logout(){
  46.     $this->session->sess_destroy();
  47.    
  48.     redirect('Auth');
  49.    
  50.  
  51.   }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement