Welcome Guest, Not a member yet? Register   Sign In
Using 1 method for authentication and form callback HELP
#1

[eluser]Unknown[/eluser]
I would like to consolidate my validate method and my login method so my users only see http://mysite.com/user/login. Also, the form validation callback is not working.

Can someone please help me clean up this code?

Thank you.


Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {

function __construct() {
  parent::__construct();
  $this->load->model('user_model');
}

function login() {
  $this->load->view('login_view', $data);
}

function validate() {
  $username=$this->input->post('username');
  $password=$this->input->post('password');
  
  $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|max_length[16]|callback_login_check');
  $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[16]|callback_login_check');
  
  if ($this->form_validation->run()) {
   if($this->user_model->check_user($username, $password)) {
    $data=array(
      'username'=>$username,
      'is_logged_in'=>TRUE,
      'user_id'=>$this->user_model->get_user_id($username)
    );
    $this->session->set_userdata($data);
    redirect('home');
   } else {
    $this->form_validation->set_message('login_check', 'Invalid username/password combination!');
    $this->login();
   }
  } else {
  $this->form_validation->set_message('login_check', 'Invalid username/password combination!');
  $this->login();
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB