Page 88 - Framework Codeigniter 2
P. 88

www.koder.web.id – Kumpulan tutorial komputer

                24.         $this->load->library('form_validation');
                25.         $this->load->helper('form');
                26.
                27.         $this->form_validation->set_rules('username', 'Username',
                    'trim|required|strip_tags');
                28.         $this->form_validation->set_rules('password', 'Password',
                    'trim|required');
                29.         $this->form_validation->set_rules('token', 'token',
                    'callback_check_login');
                30.
                31.         //$this->output->enable_profiler(1);
                32.         if ($this->form_validation->run() == FALSE)
                33.         {
                34.
                35.
                36.             $this->template->display('member/login');
                37.         }
                38.         else
                39.         {
                40.            redirect('dashboard');
                41.         }
                42.     }
                43.
                44.     function logout()
                45.     {
                46.         $this->access->logout();
                47.         redirect('member/login');
                48.     }
                49.
                50.     function check_login()
                51.     {
                52.
                53.         $username   = $this->input->post('username',TRUE);
                54.         $password   = $this->input->post('password',TRUE);
                55.
                56.         $login = $this->access->login($username, $password);
                57.         if($login)
                58.         {
                59.             return TRUE;
                60.         }
                61.         else
                62.         {
                63.             $this->form_validation->set_message('check_login',
                    'Username atau password anda salah.');
                64.             return FALSE;
                65.         }
                66.     }
                67.
                68.
                69. }


                Pada  controller  member  kita  akan  melakukan  pengecekan  terhadap  inputan  yang  telah  di

                masukkan  user.  Oleh  karena  itu  kita  tetap  menggunakan  library  validation.  Kita  akan
                menggunakan custom validation. Perhatikan baris 29 dan baris 50. Fungsi check_login akan

                                                                                                          83
   83   84   85   86   87   88   89   90   91   92   93