Question

If user clicks on any link on page, I check if user is logged in in the controller method. If he is not logged then I show a Login Screen Modal onscreen.
Everything works fine till this point.
If user give wrong user name password. Next page appears as a new page without any CSS.
How would I return the result back to modal login screen?
view/index.php

$('.index-product img').click(function() {
          var product = $('<div id="modal-productDetail" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>');           
            $.ajax({
              url: "<?php echo site_url('gallery/openProductDetail');?>",
              type: 'POST',
              success: function(msg) {
                product.html(msg);
                product.modal('show');
              }
             });     
      });

Controller

function openProductDetail()
    {
        if (!$this->ion_auth->logged_in())
        {
            redirect('auth/login');
        } else {

            $this->load->view('modal/productdetail');
        }
    }

view/login.php

<div class="modal-header">
    <h4 id="myModalLabel">Login To Your Account</h4>
  </div>
  <div id="loginModal" class="modal-body">
    <div class="row">
      <?php echo form_open("auth/login");?>
      <div class="span3">
        <ul class="unstyled" id="emailLogin">
          <li><small class="muted">Login with your email</small></li>
          <?php echo form_open("auth/login");?>
          <li>
            <input name="identity" value="" id="identity" type="text" placeholder="Email Address"/>
            <span class="help-block" id="emailError" style="display:none;"></span>
          </li>
          <li>
            <input name="password" value="" id="password" type="password" placeholder="Password"/>
            <span class="help-block" id="passwordError" style="display:none;"></span>
          </li>
          <li>
            <input style="display:none;" name="remember" value="1" id="remember" type="checkbox">
          </li>
          <li>
            <a class="text-info" id="accountProblem" href="auth/forgot_password">Account problem?</a>
            <input class="loginButton" type="submit"  name="submit" value="Login">
            <?php echo form_close();?>
          </li>
          <li>
            <div id="infoMessage"><?php echo $message;?></div>
          </li>
        </ul>
      </div>
    </div>
  </div>
Was it helpful?

Solution

You need change login() method in application/controllers/auth.php. I'm think you need add to login() method before redirect call something like this:

    $location = '';
    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());
            $data = $this->ion_auth->messages();
            $location = '/';
        }
        else
        {
            $this->session->set_flashdata('message', $this->ion_auth->errors());
            $data = $this->ion_auth->errors();
            $location = 'auth/login';
        }
    }
    else
    {
        $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

        $this->data['identity'] = array('name' => 'identity',
            'id' => 'identity',
            'type' => 'text',
            'value' => $this->form_validation->set_value('identity'),
        );
        $this->data['password'] = array('name' => 'password',
            'id' => 'password',
            'type' => 'password',
        );

        $data = $this->data;
    }

    if($this->input->is_ajax_request())
    {
        echo json_encode(array('data' => $data));
    }
    else
    {
        ($location) ? redirect($location, 'refresh') : $this->_render_page('auth/login', $data);
    }

And add js code to handle response from login() method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top