-1

我是 Codeigniter 的常客,已经到了不得不开始查看库以获取登录/忘记密码的地步,所以我决定使用 Ion Auth。

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

现在,当我以管理员身份登录然后创建新用户时,数据将添加到数据库中,并且页面从“create-user”重定向到欢迎页面。但是,如果我注销并使用这些新详细信息登录,页面会变为空白,并且重新加载栏会变得疯狂!如果有意义,则 url 栏看起来像是进入欢迎页面,但没有加载。

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

我检查了我的数据库,添加用户后,密码已经过哈希处理,但在 salt 列中它被归类为 NULL,而默认帐户已经设置了哈希码?- 这可能与它有关吗?

编辑:我现在已经更改了代码,但是当它没有被触及时仍然没有工作,所以只有代码中的编辑是删除表,而在身份验证控制器中,功能是登录、创建用户和注销。

当 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 配置文件中的一些设置

4

1 回答 1

0

这是 Google Chrome 的一个错误,我必须更新系统和浏览器。此外,为了存储 SALT,我更改了 ion_auth 配置文件中的一些设置

于 2013-02-11T12:36:38.207 回答