Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Controller
- function add()
- {
- $this->load->helper(array('form', 'url'));
- $this->load->library('form_validation');
- $rules = array(
- array(
- 'field' => 'email',
- 'label' => 'email',
- 'rules' => 'required|valid_email'
- ),
- array(
- 'field' => 'username',
- 'label' => 'username',
- 'rules' => 'trim|required|min_length[5]|max_length[50]|xss_clean'
- ),
- array(
- 'field' => 'password',
- 'label' => 'Password',
- 'rules' => 'required|min_length[5]'
- ),
- array(
- 'field' => 'konfirmasi_password',
- 'label' => 'Konfirmasi Password',
- 'rules' => 'required|matches[konfirmasi_password'
- )
- );
- $this->form_validation->set_rules($rules);
- if ($this->form_validation->run() == FALSE)
- {
- $this->load->view('register_view');
- }
- else
- {
- //echo 'Data berhasil dimasukkan';
- $this->load->model('user_model');
- $hash = $_POST['password'];
- $hash = sha1($hash);
- $data = array('email' => $_POST['email'], 'username' => $_POST['username'], 'password' => $hash,'is_Active'=>$_POST['is_Active'] );
- $this->user_model->insert($data);
- $this->load->helper('url');
- redirect('user');
- }
- function login(){
- $this->load->view('login_view');
- }
- function validate_login() {
- $this->load->model('user_model');
- $this->load->library('session');
- $cek=$this->user_model->validasi();
- if($cek==true ){
- $session=array('username'=>$this->input->post('username'),'is_loged_in'=>true);
- $this->session->set_userdata($session);
- // $this->load->helper('url');
- // redirect ('user/data');
- echo 'bisaaaa';
- }
- else{
- // $this->load->helper('url');
- // redirect('user/login');
- echo 'todak bisaaaa';
- }
- }
- model
- function validasi()
- {
- $this->load->database();
- $username=$this->input->post('username');
- $password=$this->input->post(sha1($_POST['password']));
- $this->db->where('username',$username);
- $this->db->where('password', $password);
- $ambil = $this->db->get('users');
- if($ambil->num_rows == 1)
- {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement