CodeIgniter Forums
Login - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Login (/thread-53115.html)

Pages: 1 2


Login - El Forum - 07-11-2012

[eluser]Felipe Deitos[/eluser]
Hey CroNiX, can u answer me one more thing...

The login form is working and checking everything right...

What i wanna know: I got a menu in my header(view), when the visitor is not logged in he sees 3 itens, and when he is logged he sees 5 itens.

When the user log in, I set inside an array in the userdata:
Code:
'is_logged' => true

With that i can check if the usser "is_logged" or not...
I am doing like this in my header(view):
Code:
<?php if($this->session->userdata('is_logged')){ ?>
<p>Hidden Iten</p>
&lt;?php } ?&gt;

Is this the right way to do it, or there are best ways?







Login - El Forum - 07-12-2012

[eluser]Felipe Deitos[/eluser]
Someonee? any idea?


Login - El Forum - 07-12-2012

[eluser]CroNiX[/eluser]
It's basically what I do. If they are logged in, it shows links to their profile, etc, and if they aren't logged in it just shows the login form.


Login - El Forum - 07-12-2012

[eluser]Felipe Deitos[/eluser]
Thanks for all your answers dude...
I am using that Template that you teached me...

I changed the way i validate de user, because i am storing the lvl(level) of the user in the session...
I dont know if what i am doing are the best pactices, but its working...

controller:
Code:
public function validate_user()
{
  $this->load->model('users_model');
  $data = $this->users_model->validate();
  
  if($data['is_logged'])
  {  
   $this->session->set_userdata($data);
   redirect($this->input->post('current_url'));
  }
  else
  {
   redirect($this->input->post('current_url'));
  }
}

model:
Code:
public function validate()
{
  $this->db->where('user', $this->input->post('user'));
  $this->db->where('password', md5($this->input->post('password')));
  $query = $this->db->get('users');
  
  // return ($query->num_rows == 1);
  
  if($query->num_rows == 1)
  {
   $data = array(
    'user' => $query->row('user'),
    'lvl' => $query->row('lvl'),
    'is_logged' => true
   );
   return ($data);
  }
  else
  {
   $data = array(
    'is_logged' => false
   );
   return ($data);
  }
}

The problem is... as you can see in the controller, if the 'is_logged' = false i just redirect the user to the current_url... i want to pass and error message with it... how can i do that using the Template style that you showed me?

Thanks again for all the help!


Login - El Forum - 07-12-2012

[eluser]CroNiX[/eluser]
Look into session flashdata. You can set a message in your controller when they fail via flashdata just before you redirect, and then in your view check to see if it exists, and if it does, display it (the errors).


Login - El Forum - 07-12-2012

[eluser]Felipe Deitos[/eluser]
This is great... really

Thanks mate!