私は Codeigniter を頻繁に使用していますが、ログイン/パスワードを忘れた場合にライブラリを調べなければならなくなったので、Ion Auth を使用することにしました。
私はこれを設定しました - 正常に動作し、すでに設定されている管理者アカウントを試してみましたが、問題ありません。
管理者としてログインして新しいユーザーを作成すると、データがデータベースに追加され、ページが「create-user」からウェルカム ページにリダイレクトされます。しかし、ログアウトしてこれらの新しい詳細でログインすると、ページが空白になり、リロードバーが狂ってしまいます! URL バーは、意味がある場合はウェルカム ページに移動するように見えますが、何も読み込まれません。
また、コンソールのfirebugとphpログエラーを確認しましたが、何もありませんでした。
データベースを確認したところ、ユーザーが追加されたときにパスワードがハッシュされましたが、salt 列では NULL として分類されていますが、既定のアカウントには既に設定されているハッシュ コードがありますか? ――これは何か関係あるのでしょうか?
編集:コードを変更しましたが、触れていないときはまだ機能しなかったため、コードの編集のみがテーブルの削除であり、認証コントローラーの関数は login、create_user、および logout です。
そして、admin@admin.com ユーザーがログインすると、他の「新しい」アカウントだけでページが読み込まれます。
ありがとう!
//log the user in
function login() {
$this->data['title'] = "Login";
$this->form_validation->set_rules('identity', 'Identity', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == true) {
//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());
redirect('/', 'refresh');
}else{
//if the login was un-successful
//redirect them back to the login page
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('auth/login', 'refresh');
}
}else{
//the user is not logging in so display the login page
$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',
);
$this->_render_page('auth/login', $this->data);
}
}
//log the user out
function logout() {
$this->data['title'] = "Logout";
$logout = $this->ion_auth->logout();
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('auth/login', 'refresh');
}
//create a new user
function create_user() {
$this->data['title'] = "Create User";
$this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean');
$this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');
if ($this->form_validation->run() == true) {
$username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name'));
$email = $this->input->post('email');
$password = $this->input->post('password');
$additional_data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name')
);
}
if ($this->form_validation->run() == true && $this->ion_auth->register($username, $password, $email, $additional_data)) {
//check to see if we are creating the user
//redirect them back to the admin page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth/login", 'refresh');
}else{
//display the create user form
//set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name'),
);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name'),
);
$this->data['email'] = array(
'name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
);
$this->data['password'] = array(
'name' => 'password',
'id' => 'password',
'type' => 'password',
'value' => $this->form_validation->set_value('password'),
);
$this->data['password_confirm'] = array(
'name' => 'password_confirm',
'id' => 'password_confirm',
'type' => 'password',
'value' => $this->form_validation->set_value('password_confirm'),
);
$this->_render_page('auth/create_user', $this->data);
}
}
function _render_page($view, $data=null, $render=false) {
$this->viewdata = (empty($data)) ? $this->data: $data;
$view_html = $this->load->view($view, $this->viewdata, $render);
if (!$render) return $view_html;
}
}
ウェルカム ページ コントローラー
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('ion_auth');
$this->load->library('session');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index() {
if (!$this->ion_auth->logged_in()) {
redirect('auth/login', 'refresh');
}elseif (!$this->ion_auth->is_admin()) {
redirect('/', 'refresh');
}else{
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->_render_page('auth/welcome', $this->data);
}
}
}
解決済み:これは Google Chrome のバグで、システムとブラウザを更新する必要がありました。また、SALTを保存するために、ion_auth構成ファイルの設定をいくつか変更しました