Ion Auth&;Codeigniter:新用户登录时循环重定向


Ion Auth & Codeigniter: Looping redirect when new user login

我是Codeigniter的常客,现在我不得不开始查看库中的登录/忘记密码,所以我决定使用Ion Auth。

我设置了这个-工作正常,尝试了已经设置的管理员帐户,它很好。

现在,当我以管理员身份登录并创建新用户时,数据会添加到数据库中,页面会从"创建用户"重定向到欢迎页面。但是,如果我注销并使用这些新的详细信息登录,页面就会变为空白,重新加载栏就会变得疯狂!url栏看起来像是进入了欢迎页面,如果这是有意义的,但没有加载任何内容。

我还检查了firebug上的控制台和php日志错误,但什么都没有。

我已经检查了我的数据库,当添加用户时,密码已经被散列,但在salt列中,它被归类为NULL,而已经设置的默认帐户有散列代码?-这和它有关系吗?

EDIT:我现在已经修改了代码,但当它没有被触摸时,这仍然不起作用,所以代码中的编辑只是删除表,而在auth控制器中,函数是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);
        }
    }
}

解决方案:这是谷歌Chrome的一个错误,我不得不更新系统和brwser。同样为了存储SALT,我在我的_auth配置文件中更改了一些设置

这是Google Chrome的一个错误,我不得不更新系统和浏览器。同样为了存储SALT,我在我的_auth配置文件中更改了一些设置