我已经作出了注册和登录应用与笨3.笨用户注册:分流登录失败在2个条件的条件当有人填充<em>登记表</em>并将其提交到覆盖“帐户无效”情况下
成功时,“用户”表中的“活动”列中接收值0,作为可见图像中的波纹管:
用户将能够前激活他们的帐户小号。IGN在
在Signin.php控制器我有signin()
功能:
public function signin()
{
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
if ($this->form_validation->run())
{
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->load->model('Usermodel');
$current_user = $this->Usermodel->user_login($email, $password, $active);
// Set the current user's data
if ($current_user) {
$this->session->set_userdata(
array(
'user_id' => $current_user->id,
'user_email' => $current_user->email,
'user_first_name' => $current_user->fname,
'is_logged_in' => TRUE
)
);
redirect('home');
} else {
$this->session->set_flashdata("signin_failure", "Incorrect email or password");
redirect('signin');
}
}
else
{
$this->load->view('signin');
}
}
我想要的,而不是在代码行$this->session->set_flashdata("signin_failure", "Incorrect email or password");
以上,以便能够“分裂”登录失败条件在2:不正确的电子邮件或密码和帐户未被激活。
if (condition here) {
$this->session->set_flashdata("signin_failure", "Your account has not been activated");
} else {
$this->session->set_flashdata("signin_failure", "Incorrect email or password");
}
我问题:我应该怎么放,而不是condition here
在上面的代码?
更具体地说:我怎么说的:如果“活动”列中的值是0做$this->session->set_flashdata("signin_failure", "Your account has not been activated");
?
的USER_LOGIN()内部函数的的usermodel:
public function user_login($email, $password, $active) {
$query = $this->db->get_where('users', ['email' => $email, 'password' => md5($password), 'active' => 1]);
return $query->row();
}
UPDATE:
我想出了这一点:
public function signin()
{
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
if ($this->form_validation->run())
{
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->load->model('Usermodel');
$current_user = $this->Usermodel->user_login($email, $password);
// If we find a user
if ($current_user) {
// If the user found is active
if ($current_user->active == 1) {
$this->session->set_userdata(
array(
'user_id' => $current_user->id,
'user_email' => $current_user->email,
'user_first_name' => $current_user->fname,
'user_active' => $current_user->active,
'is_logged_in' => TRUE
)
);
redirect('home');
} else {
// If the user found is NOT active
$this->session->set_flashdata("signin_failure", "Your account has not been activated");
redirect('signin');
}
} else {
// If we do NOT find a user
$this->session->set_flashdata("signin_failure", "Incorrect email or password");
redirect('signin');
}
}
else
{
$this->load->view('signin');
}
}
但在它的一个缺陷,因为即使当电子邮件地址和密码是否正确,但用户不活跃,该消息是:“不正确的电子邮件或密码”而不是“您的帐户尚未激活”。
将if($ current_user-> active == 1)'改为'if($ current_user ['active'] == 1)'因为函数返回的结果是数组而非对象。 –
我刚刚做了,它给出了这个错误:'不能使用stdClass类型的对象作为数组'。 –
使用'return $ query-> row_array();'在模型函数 –