Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]ion_auth and HMVC - need help please
#1

[eluser]Cgull[/eluser]
Hello,

I am developing a site where I need different login views for admin side and frontend side.

I created a module from ion_auth but things don't work right.

The problem is, nothing displays on the homepage view where the login_block view should appear.

I have these files:

applicaiton/core/MY_Controller that extends MX_Controller.

Then I have application/libraries/Frontend_Controller that extends My_Controller.

In application/modules/controllers/auth/auth.php
The auth controller also extends MX_Controller, should it not?

For the admin login:
Code:
function login()
{
  if($this->ion_auth->logged_in())
  {
    $user = $this->ion_auth->get_user($this->input->post('identity'));
    $data['message'] = 'Hello ' . $user->first_name . ',';
  }
  else
  {
    if(isset($_POST['submitLogin']))
    {
//validate form input
$this->form_validation->set_rules('identity', 'Identity', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
  
if ($this->form_validation->run() == true)
{
   $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());
     $user = $this->ion_auth->get_user($this->input->post('identity'));
     $data['message'] = 'Hello ' . $user->first_name;

     if($this->ion_auth->is_admin())
  redirect('admin');
     else
  redirect('/');
   }
   else
   {
     //if the login was un-successful
     //redirect them back to the login page
     $this->session->set_flashdata('message', $this->ion_auth->errors());
     $data['error'] = $this->ion_auth->errors();
         }
       }
       else
       {
  //the user is not logging in so display the login page
  //set the flash data error message if there is one
  $data['error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
       }
     }// End if submitted and no spam
  
     $data['identity'] = array('name' => 'identity',
     'id' => 'identity',
     'type' => 'text',
     'value' => $this->form_validation->set_value('identity'),
     'class' => 'input-medium phone',
     'placeholder' => 'Cellphone'
    );
     $data['password'] = array('name' => 'password',
     'id' => 'password',
     'type' => 'password',
     'class' => 'input-medium',
     'placeholder' => 'password'
    );
     }
     $this->load->view('login', $data);
   }

For the frontend login I have the same code but I am calling a different view called login_block.
The login_block view file:
Code:
<div id="login_form">
&lt;?php
  $attr = array('class'=>'form-inline', 'id'=>'loginForm');
  $send = array('class'=>'btn btn-inverse', 'name'=>'signin', 'value'=>'Sign In');
  echo form_open(site_url('auth/login_block', $attr));
?&gt;
<div >
  <img src="&lt;?php echo site_url('assets/img/login.gif'); ?&gt;" alt="Login" />
</div>
<div  left; font-size:11px; font-weight:bold;padding-top:25px;margin-right:45px">LOGIN</div>

<div left">
  &lt;?php echo form_label('Cellphone', 'cellphone', array('class'=>'login-label')); ?&gt;
</div>
<div class="span2"  padding-top:10px">&lt;?php echo form_input('identity', set_value('identity', ''), 'placeholder="cellphone no" class="span2 phone" id="cellphone"'); ?&gt;</div>

<div left; margin-left:10px">&lt;?php echo form_label('Password', 'password', array('class'=>'login-label')); ?&gt;</div>
<div class="span2"  padding-top:10px">&lt;?php echo form_password('password', '', 'placeholder="password" class="span2" id="password"'); ?&gt;</div>
<div class="span1" >&lt;?php echo form_submit($send); ?&gt;</div>
&lt;?php echo form_close(); ?&gt;
<div class="clearfix"></div>
</div>
[removed]
$(function()
{      
  var options = { target: '#login_form' };    // target element(s) to be updated with server response

  // bind form using 'ajaxForm'
  $('#loginForm').ajaxForm(options);
});
[removed]

In my homepage view I am calling the login_block view like this:
Code:
&lt;?php Modules::run('auth/login_block'); ?&gt;

Why don't I see the login_block view on the homepage?

Thank you
#2

[eluser]Cgull[/eluser]
Found the problem, in my homepage template I changed:
Code:
Module::run('auth/login')
to
Code:
echo Module:: run('auth/login')

Duh....




Theme © iAndrew 2016 - Forum software by © MyBB