注册CodeIgniter Ion Auth

时间:2014-01-05 19:40:10

标签: php codeigniter ion-auth

我正在尝试使用Ion Auth注册用户,但register()函数似乎没有报告任何错误消息。如何注册Ion Auth?我已经阅读了各种教程,例如this onethis one(以及documentation),但它们似乎没有用。

function register()
{
    // do not allow registration if logged in
    if ($this->ion_auth->logged_in())
    {
        redirect('/');
    }

    $this->load->helper(array('form', 'url'));
    $this->load->library('form_validation');

    $this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback_email_check');
    $this->form_validation->set_rules('email2', 'Email Confirmation', 'trim|required|valid_email|matches[email]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|md5');

    if ($this->form_validation->run() == FALSE)
    {
        $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

        $this->load->view('header');
        $this->load->view('register', $this->data);
        $this->load->view('footer');
    }
    else
    {
        $username = $this->input->post('email');
        $password = $this->input->post('password');
        $email = $username;

        $additional_data = array(
            'first_name' => $this->input->post('name'),
            'last_name' => '',
        );

        if (!$this->ion_auth->email_check($email))
        {
            $group_name = 'users';
            $uId = $this->ion_auth->register($username, $password, $email, $additional_data, $group_name);

            if ($uId == FALSE)
            {
                $this->session->set_flashdata('message', $this->ion_auth->errors());
                redirect("home/register", 'refresh');
            }
            else
            {
                redirect('/'); // registration success
            }
        }
    }
}

function email_check($str)
{
    if ($this->ion_auth->email_check($str))
    {
        $this->form_validation->set_message('email_check', 'This email is already registered.');
        return FALSE;
    }

    return TRUE;
}

0 个答案:

没有答案