Bannip73

Auth

Nov 10th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Auth extends CI_Controller {
  5.  
  6.     /**
  7.      * Index Page for this controller.
  8.      *
  9.      * Maps to the following URL
  10.      *      http://example.com/index.php/welcome
  11.      *  - or -
  12.      *      http://example.com/index.php/welcome/index
  13.      *  - or -
  14.      * Since this controller is set as the default controller in
  15.      * config/routes.php, it's displayed at http://example.com/
  16.      *
  17.      * So any other public methods not prefixed with an underscore will
  18.      * map to /index.php/welcome/<method_name>
  19.      * @see https://codeigniter.com/user_guide/general/urls.html
  20.      */
  21.     public function index()
  22.     {
  23.         $this->load->view('auth/login');
  24.     }
  25.  
  26.     public function register()
  27.     {
  28.         $this->load->view('auth/register');
  29.     }
  30.  
  31.     public function reg_action()
  32.     {
  33.         $fullname = $this->input->post('fullname');
  34.         $username = $this->input->post('username');
  35.         $password = $this->input->post('password');
  36.         $repassword = $this->input->post('repassword');
  37.  
  38.         if ($password != $repassword) {
  39.             echo "password tidak sama";
  40.         }else {
  41.  
  42.             $data = array(
  43.                 'fullname' => $fullname,
  44.                 'username' => $username,
  45.                 'password' => md5($password)
  46.             );
  47.             $result = $this->model->simpan('users', $data);
  48.             if ($result > 0) {
  49.                 redirect(base_url().'administrator');
  50.             }else {
  51.                 redirect(base_url().'auth?pesan=gagal');
  52.             }
  53.  
  54.         }
  55.     }
  56.     public function login_action()
  57.     {
  58.         $username = $this->input->post('username');
  59.         $password = $this->input->post('password');
  60.         $check_login_r = $this->model->getLogin($username, $password)->num_rows();
  61.         if ($check_login_r > 0) {
  62.             $datauser = $this->model->getLogin($username, $password)->row_array();
  63.             $sessions = array(
  64.                 'userid' => $datauser['id_user'],
  65.                 'nameuser' => $datauser['username'],
  66.                 'namefull' => $datauser['fullname'],
  67.                 'status' => 'ok'
  68.             );
  69.             $this->session->set_userdata($sessions);
  70.             redirect("administrator");
  71.         }else {
  72.             redirect(base_url().'auth?pesan=gagal');
  73.             $this->index();
  74.         }
  75.     }
  76.  
  77.     public function logout_action()
  78.     {
  79.         $this->session->sess_destroy();
  80.         redirect('auth');
  81.     }
  82. }
  83.  
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment