如果用户点击页面上的任何链接,我会检查用户是否以控制器方法登录。如果他没有登录,那么我会在屏幕上显示登录屏幕模式
到目前为止,一切正常
如果用户提供错误的用户名密码。下一页显示为没有任何CSS的新页面
如何将结果返回到模态登录界面?
查看/ 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');
}
});
});
控制器
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>
答案 0 :(得分: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()
方法的响应。