2013-07-21 50 views
0

如果用戶單擊頁面上的任何鏈接,我將檢查用戶是否以控制器方法登錄。如果他沒有登錄,我會在屏幕上顯示登錄屏幕模式。
一切正常,直到這一點。
如果用戶輸入錯誤的用戶名密碼。下一頁顯示爲沒有任何CSS的新頁面。
我該如何將結果返回到模態登錄屏幕?
視圖/ index.php的Codeigniter:將Ion Auth屏幕與Bootstrap模塊集成

$('.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'); 
       } 
      });  
     }); 

控制器

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

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

視圖/ 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> 

回答

1

需要改變login()方法在application/controllers/auth.php。 我想你需要轉接呼叫這樣的事情之前添加到login()方法:

$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); 
    } 

並添加js代碼來處理來自login()方法響應。

+0

它不會返回任何Ajax請求的錯誤?你可以在這裏找到'login()'方法https://github.com/benedmunds/CodeIgniter-Ion-Auth/blob/2/controllers/auth.php –

+0

對不起,但我不明白你的評論。 –

+0

我會在哪裏添加它到'login()'方法? –