Cara integrasi helper captcha codeigniter dengan ion auth

gan gw kan mau make captcha helper di codeigniter buat login nah kebetulan gw make library ion auth nah setelah gw oprek2 jadi malah gini gan

ini controllernya

public function login()
	{
		$this->data['title'] = $this->lang->line('login_heading');
		$this->load->helper('captcha');
  		$this->load->library('form_validation');
		$this->form_validation->set_rules('identity', str_replace(':', '', $this->lang->line('login_identity_label')), 'required');
		$this->form_validation->set_rules('password', str_replace(':', '', $this->lang->line('login_password_label')), 'required');
		// $this->form_validation->set_rules('g-recaptcha-response','Captcha','callback_recaptcha');
		$this->form_validation->set_rules('captcha', "Captcha", 'required');
		$userCaptcha = set_value('captcha');
        $word = $this->session->userdata('captchaWord');
        $captcha  = $this->input->post('captcha');
		if ($this->form_validation->run() === TRUE && $captcha==$word)
		{

			if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember))
			{
				//if the login is successful
				//redirect them back to the home page
				$this->session->set_flashdata('message', $this->ion_auth->messages());
				redirect('dashboard', 'refresh');
			}
			else{
				?>
					<script language="JavaScript">
						alert('Oops! Username atau Password tidak sesuai ...');
						document.location='login';
					</script>
				<?php
				}

		}
		else
		{
			$this->load->helper('captcha');
			$vals = array(
				'img_path'  => './captcha/',
				'img_url' => base_url().'captcha/',
				'img_width' => '150',
				'img_height' => 30,
				);
				$captcha = create_captcha($vals);
				$this->session->set_userdata('captchaWord', $captcha['word']);
				$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
				$this->load->view('captcha/index', $captcha);

			$this->data['identity'] = [
				'name' => 'identity',
				'id' => 'identity',
				'type' => 'text',
				'value' => $this->form_validation->set_value('identity'),
			];

			$this->data['password'] = [
				'name' => 'password',
				'id' => 'password',
				'type' => 'password',
			];

			$this->_render_page('auth' . DIRECTORY_SEPARATOR . 'login', $this->data);
		}
	}

dan ini untuk viewnya

<?php echo form_open("auth/login");?>

<p style="text-align:center">
    <?php echo lang('login_identity_label', 'identity');?><br>
    <?php echo form_input($identity);?>
  </p>

  <p style="text-align:center">
    <?php echo lang('login_password_label', 'password');?><br>
    <?php echo form_input($password);?>
  </p>
  <?php echo $image; ?>

 <p>
   <label for="name">Captcha:
     <input id="captcha" name="captcha" type="text" />
   </label>
 </p>

  <p style="text-align:center">
    <?php echo lang('login_remember_label', 'remember');?>
    <?php echo form_checkbox('remember', '1', FALSE, 'id="remember"');?>
  </p>
  <p style="text-align:center">
  <br>
  <center><p><?php echo form_submit('submit', lang('login_submit_btn'));?></p></center>

<?php echo form_close();?>

sorry gan kodenya panjang hehehe

avatar MRifai
@MRifai

18 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban