我创建菜单登录并通过电子邮件验证进行注册。但是,如果电子邮件未通过验证,我仍然希望显示“您的电子邮件尚未验证”消息,我应该在脚本中添加什么...?
前任 :
有效= 1(已验证)
有效= 0(未验证)
控制器:
public function index($param='')
{
if($param == 'error')
$param = 'Incorrect username or password';
$data = array('title'=>'Login',
'message'=>$param,
'isi' => 'login/vlogin',
'base_url'=>base_url());
$this->load->view('layout/wrapper', $data);
}
public function do_login(){
$data = $this->input->post(null,true);
$is_login = $this->db->get_where('user',array(
'email'=>$data['email'],
'password'=>$data['password'],
'active'=> 1
))->row();
if($is_login){
$session_set = array(
'is_login' => true,
'firstname' => $is_login->firstname,
'lastname' => $is_login->lastname,
'jkl' => $is_login->jkl,
'id' => $is_login->id,
'lastlogin' => $is_login->lastlogin
);
$this->db->update('user',array('lastlogin'=>date('Y-m-d H:i:s')),array('id'=>$is_login->id));
$this->session->set_userdata($session_set);
redirect('homepage/homepage/menu');
}else{
redirect('login/login/index/error');
}
}
您必须先检查用户凭据是否正确,然后再检查电子邮件是否经过验证。
因此,您可以尝试以下操作:
public function do_login() {
$data = $this->input->post(null, true);
$user = $this->db->get_where('user', array(
'email'=>$data['email'],
'password'=>$data['password']
))->row();
if ($user) { //User exists
if ($user->active == 1) { //User exists and his email is verified
$session_set = array(
'is_login' => true,
'firstname' => $user->firstname,
'lastname' => $user->lastname,
'jkl' => $user->jkl,
'id' => $user->id,
'lastlogin' => $user->lastlogin
);
$this->db->update('user', array('lastlogin'=>date('Y-m-d H:i:s')), array('id'=>$user->id));
$this->session->set_userdata($session_set);
redirect('homepage/homepage/menu');
} else { //User exists BUT his email is NOT verified
$this->session->set_flashdata('message', 'Your email is not verified yet');
//You have to capture and show the flash message in view
redirect('login/login/index/error');
}
} else { //User does NOT exist at all
$this->session->set_flashdata('message', 'The combination of username and/or password was incorrect. Please, try again.');
//You have to capture and show the flash message in view
redirect('login/login/index/error');
}
}
在您看来,请输入以下内容:
<?php if ($this->session->flashdata('message')) : ?>
<p class="someErrorClass"><?php echo $this->session->flashdata('message'); ?></p>
<?php endif; ?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句