Welcome Guest, Not a member yet? Register   Sign In
modular extensions and user widget
#1

[eluser]Mantra of Doom[/eluser]
Hi everyone.
I've been using Wiredesignz's Modular Extensions in order to make a user panel at the top of my site. I've run into a couple issues that I just can't seem to solve. I know it's probably because I'm missing something simple. Just for reference, I'm using Ion Auth (v1) to handle user permissions.

1. When the user is not logged in, the widget should display the login form. This works great unless the user types in a bad password or the form doesn't validate. I expect just my partial to redirect to the form with errors in it, but instead I'm just getting my partial as the whole page. Is there any way to force the refresh to happen inside this widget?

2. I extended the model so that I can access the user info from Ion Auth from any controller. I need this info in my user widget, but I also need it throughout my application. If I call my model in my widget and in my page, it will call the same query twice. Is there a better way of doing this without the extra query or am I going to have to live with the duplicate?

Here is my widget code from my user controller
Code:
function cp(){
// If the user is logged in, show the user widget
if( $this->ion_auth->logged_in() ){
  // get the user info from My_Model which has the call to Ion Auth in it. The user info called through $data['user'] with $this->ion_auth->get_user_array();
  $data = $this->player->general();
  
  if( !$data ){
   // no user found, return false just in case.
   return false;
  }
  else{
  // The user is logged in as an admin, so show the admin controls
   if($this->ion_auth->is_admin()){
    $this->load->view('my_admin_links', $data);
   }
  // The user is logged in, but is not an admin, show the user controls
   else{
    $this->load->view('my_links', $data);
   }    
   }
}
// if the user is not logged in, show the login box
else{
  //validate form input
  $this->form_validation->set_rules('username', 'Username', 'required');
  $this->form_validation->set_rules('password', 'Password', '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('username'), $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($this->config->item('base_url'), '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('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
   $data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

   $data['username'] = array('name' => 'username',
      'id' => 'identity',
      'type' => 'text',
      'value' => $this->form_validation->set_value('identity'),
      'class' => 'userlogin',
     );
   $data['password'] = array('name' => 'password',
      'id' => 'password',
      'type' => 'password',
      'class' => 'userlogin',
     );
   $data['submit'] = array('name' => 'submit',
      'value' => 'Login',
      'class' => 'loginbutton',
     );
   $data['remember'] = array('name' => 'remember',
      'value' => 1,
      'checked' => FALSE,
      'class' => 'remembercheck',
     );

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




Theme © iAndrew 2016 - Forum software by © MyBB