我已經作出了註冊和登錄應用與笨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();'在模型函數 –