Advertisement
21ani

Controller Auth Skr

Jan 2nd, 2020
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.87 KB | None | 0 0
  1. <?php
  2. class Auth extends CI_Controller {
  3.  
  4.     public function __construct(){
  5.         parent::__construct();
  6.         $this->load->library('form_validation');
  7.     }
  8.  
  9.  
  10.     function index()
  11.     {
  12.         $this->load->helper('url');
  13.         $data['judul'] = 'Halaman Home';
  14.         $this->load->view('template/home/vheader', $data);
  15.         $this->load->view('home/index');
  16.         $this->load->view('template/home/vfooter');
  17.     }
  18.  
  19.     public function lihat(){
  20.         $this->load->helper('url');
  21.         ////$data['judul'] = 'Halaman Home';
  22.         // $this->load->view('template/home/vheader');
  23.         // $this->load->view('home/vimhs');
  24.         // $this->load->view('template/home/vfooter');
  25.         $data['judul'] = 'Halaman Home';
  26.         $this->load->view('template/home/vheader', $data);
  27.         $this->load->view('home/vimhs');
  28.         $this->load->view('template/home/vfooter');
  29.        
  30.     }
  31.     public function fti(){
  32.         $this->load->helper('url');
  33.         $data['judul'] = 'Halaman Home';
  34.         $this->load->view('template/home/vheader', $data);
  35.         $this->load->view('home/fti');
  36.         $this->load->view('template/home/vfooter');
  37.        
  38.     }
  39.  
  40.  
  41.  
  42.     public function login(){
  43.         $this->form_validation->set_rules('nim', 'Nim', 'trim|required');
  44.         // $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  45.         $this->form_validation->set_rules('password', 'Password', 'trim|required');
  46.  
  47.         if ($this->form_validation->run() == false){
  48.             $data['judul'] = 'Halaman Login';
  49.         $this->load->view('template/auth_vheader', $data);
  50.         $this->load->view('auth/login');
  51.         $this->load->view('template/auth_vfooter');
  52.         }
  53.         else{
  54.             //ketika validasi lolos atau sukses
  55.             $this->_login();
  56.         }
  57.     }
  58.  
  59.     private function _login(){
  60.         $nim = $this->input->post('nim'); //ngambil email yang ada di elemen email
  61.         // $email = $this->input->post('email'); //ngambil email yang ada di elemen email
  62.         $password = $this->input->post('password'); //ngambil password yang ada di elemen email
  63.  
  64.         //$user = $this->db->get_where('user',['email=> $email'])->row_array();
  65.         $mhs = $this->db->get_where('mhs',['nim'=> $nim])->row_array();
  66.         // var_dump($user);
  67.         // die;
  68.         if($mhs){
  69.             if ($mhs['is_active'] == 1){
  70.                 if (password_verify($password,$mhs['password'])){
  71.                     $data =[
  72.                         'nim'=> $mhs['nim'],
  73.                         // 'email'=> $user['email'],
  74.                         'role_id'=> $mhs['role_id']
  75.                     ];
  76.                     $this->session->set_userdata($data);
  77.                     redirect('user');
  78.  
  79.                 } else {
  80.                     $this->session->set_flashdata('massage','<div class="alert alert-danger" role="alert">
  81.                Wrong Password
  82.              </div>');
  83.                 //setelah database berhasil masuk, kita  redirect ke halaman index auth.
  84.                 redirect('auth');
  85.  
  86.                 }
  87.  
  88.             } else{
  89.                 $this->session->set_flashdata('massage','<div class="alert alert-danger" role="alert">
  90.                This Email has not been activated!
  91.              </div>');
  92.                 //setelah database berhasil masuk, kita  redirect ke halaman index auth.
  93.                 redirect('auth');
  94.  
  95.             }
  96.  
  97.         } else{
  98.             $this->session->set_flashdata('massage','<div class="alert alert-danger" role="alert">
  99.            Email is not registered!
  100.          </div>');
  101.             //setelah database berhasil masuk, kita  redirect ke halaman index auth.
  102.             redirect('auth');
  103.  
  104.         }
  105.     }
  106.    
  107.     public function registration(){
  108.  
  109.         //aturan untuk kolom inputan pada form
  110.  
  111.         $this->form_validation->set_rules('name', 'Name', 'required|trim|alphabets_text_field');
  112.         $this->form_validation->set_rules('nim', 'Nim', 'required|trim|is_unique[mhs.nim]',[
  113.             'is_unique' => 'This nim has already registered'
  114.             ]);
  115.            
  116.         $this->form_validation->set_rules('fakultas', 'Fakultas', 'required|trim');
  117.         $this->form_validation->set_rules('prodi', 'Prodi', 'required|trim');
  118.         // $this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email|is_unique[user.email]',[
  119.         //     'is_unique' => 'This Email has already registered'
  120.         // ]);
  121.         $this->form_validation->set_rules('password1', 'Password', 'required|trim|
  122. min_length[3]|matches[password2]',[
  123.     'min_lenght' => 'Password too short!',
  124.     'matches' => 'Password dont matches'
  125. ]);
  126.         $this->form_validation->set_rules('password2', 'Password', 'required|trim|matches[password1]');
  127.  
  128.  
  129.         //logika untuk mengembalikan tampilan apabila form_validasi nya gagal
  130.         if ($this->form_validation->run() == false ){
  131.             $this->load->helper('url');
  132.  
  133.             $data['judul'] = 'Halaman Regis';
  134.  
  135.         $this->load->view('template/auth_vheader', $data);
  136.         $this->load->view('auth/vregistration');
  137.         $this->load->view('template/auth_vfooter');
  138.         } else {
  139.             //membuat sebuah variabel utk isian perintah memasukkan apa yang diinputkan di form input
  140.             //lalu memasukkan di tabel database
  141.             $data = [
  142.                 'id_fakultas' => htmlspecialchars($this->input->post('name',true)),
  143.                 'name' => htmlspecialchars($this->input->post('name',true)),
  144.                 'name' => htmlspecialchars($this->input->post('name',true)),
  145.                 'name' => htmlspecialchars($this->input->post('name',true)),
  146.                 'nim' => htmlspecialchars($this->input->post('nim',true)),
  147.                 // 'email' => htmlspecialchars($this->input->post('email',true)),
  148.                 'image' => 'default.jpg',
  149.                 //'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT),
  150.                 'password' => password_hash($this->input->post('password1'), PASSWORD_DEFAULT),
  151.                 'role_id' => 2,
  152.                 'is_active' => 1,
  153.                 'date_created' => time()
  154.             ];
  155.  
  156.             //memasukkan variabel tadi ke tabel user
  157.             $this->db->insert('mhs',$data);
  158.             // $this->db->insert('user',$data);
  159.  
  160.             //Kasih pesan sebelum redirect Buat flashdata pakai session
  161.             $this->session->set_flashdata('massage','<div class="alert alert-success" role="alert">
  162.            Congrats your account has been ceated!
  163.          </div>');
  164.             //setelah database berhasil masuk, kita  redirect ke halaman index auth.
  165.             redirect('auth');
  166.         }
  167.        
  168.     }
  169.  
  170.     public function logout(){
  171.         $this->session->unset_userdata('nim');
  172.         // $this->session->unset_userdata('email');
  173.         $this->session->unset_userdata('role_id');
  174.         //Kasih pesan sebelum redirect Buat flashdata pakai session
  175.         $this->session->set_flashdata('massage','<div class="alert alert-success" role="alert">
  176.        You have been logged out!
  177.      </div>');
  178.         //setelah database berhasil masuk, kita  redirect ke halaman index auth.
  179.         redirect('auth');
  180.     }
  181.  
  182.  
  183.  
  184. public function fbimbing(){
  185.      
  186.     $this->load->helper('url');
  187.     $data['Bimbing'] = 'Halaman Dosen Pembimbing';
  188.     $data['bimbing'] = $this->dosenpem->get_all();
  189.      
  190.     $this->load->view('dbimbing/vheader', $data);
  191.     //$this->load->view('dbimbing/dosenp',$data);
  192.     $this->load->view('dbimbing/index');
  193.     $this->load->view('dbimbing/template/vfooter');  
  194. }
  195. public function search(){
  196.  $this->load->view('dbimbing/vheader', $data);
  197.   $keyword = $this->input->post('keyword');
  198.   $data['bimbings']=$this->dosenpem->get_dosen_keyword($keyword);
  199.   $this->load->view('dbimbing/cari',$data);
  200.           $this->load->view('dbimbing/template/vfooter');
  201. }
  202.  
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement