Postingan lainnya
Input data otomatis ke database
gan cara buat input data otomatis ke database gimana ya..? misal di database ada kolom yang defaultnya 0 terus jika pengguna login nambah jadi 1
**Controller**
public function login()
{
$this->data['title'] = $this->lang->line('login_heading');
// validate form input
$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');
if ($this->form_validation->run() === TRUE)
{
// check to see if the user is logging in
// check for "remember me"
$remember = (bool)$this->input->post('remember');
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('auth/index', 'refresh');
}
else
{
// if the login was un-successful
// redirect them back to the login page
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('auth/login', 'refresh'); // use redirects instead of loading views for compatibility with MY_Controller libraries
}
}
else
{
// the user is not logging in so display the login page
// set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$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('user' . DIRECTORY_SEPARATOR . 'form_login', $this->data);
}
}
**Model**
public function login($identity, $password, $remember=FALSE)
{
$this->trigger_events('pre_login');
if (empty($identity) || empty($password))
{
$this->set_error('login_unsuccessful');
return FALSE;
}
$this->trigger_events('extra_where');
$query = $this->db->select($this->identity_column . ', email, id, password, active, last_login')
->where($this->identity_column, $identity)
->limit(1)
->order_by('id', 'desc')
->get($this->tables['users']);
if ($this->is_max_login_attempts_exceeded($identity))
{
// Hash something anyway, just to take up time
$this->hash_password($password);
$this->trigger_events('post_login_unsuccessful');
$this->set_error('login_timeout');
return FALSE;
}
if ($query->num_rows() === 1)
{
$user = $query->row();
if ($this->verify_password($password, $user->password, $identity))
{
if ($user->active == 0)
{
$this->trigger_events('post_login_unsuccessful');
$this->set_error('login_unsuccessful_not_active');
return FALSE;
}
$this->set_session($user);
$this->update_last_login($user->id);
$this->clear_login_attempts($identity);
$this->clear_forgotten_password_code($identity);
if ($this->config->item('remember_users', 'ion_auth'))
{
if ($remember)
{
$this->remember_user($identity);
}
else
{
$this->clear_remember_code($identity);
}
}
// Rehash if needed
$this->rehash_password_if_needed($user->password, $identity, $password);
// Regenerate the session (for security purpose: to avoid session fixation)
$this->session->sess_regenerate(FALSE);
$this->trigger_events(['post_login', 'post_login_successful']);
$this->set_message('login_successful');
return TRUE;
}
}
// Hash something anyway, just to take up time
$this->hash_password($password);
$this->increase_login_attempts($identity);
$this->trigger_events('post_login_unsuccessful');
$this->set_error('login_unsuccessful');
return FALSE;
}
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban