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

时间:2013-02-07 16:02:54

标签: php mysql codeigniter ion-auth

我经常使用Codeigniter,它已经到了我必须开始查看图书馆登录/忘记密码的地步,所以我决定使用Ion Auth。

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

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

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

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

编辑:我现在已经改变了代码,但是当它没有被触及时仍然没有用,所以只有代码编辑才能删除表格,而在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,我在ion_auth配置文件中更改了一些设置

1 个答案:

答案 0 :(得分:0)

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

相关问题