[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">
<?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));
?>
<div >
<img src="<?php echo site_url('assets/img/login.gif'); ?>" alt="Login" />
</div>
<div left; font-size:11px; font-weight:bold;padding-top:25px;margin-right:45px">LOGIN</div>
<div left">
<?php echo form_label('Cellphone', 'cellphone', array('class'=>'login-label')); ?>
</div>
<div class="span2" padding-top:10px"><?php echo form_input('identity', set_value('identity', ''), 'placeholder="cellphone no" class="span2 phone" id="cellphone"'); ?></div>
<div left; margin-left:10px"><?php echo form_label('Password', 'password', array('class'=>'login-label')); ?></div>
<div class="span2" padding-top:10px"><?php echo form_password('password', '', 'placeholder="password" class="span2" id="password"'); ?></div>
<div class="span1" ><?php echo form_submit($send); ?></div>
<?php echo form_close(); ?>
<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:
<?php Modules::run('auth/login_block'); ?>
Why don't I see the login_block view on the homepage?
Thank you