Registration with CodeIgniter Ion Auth

ⅰ亾dé卋堺 提交于 2019-12-10 12:05:06

问题


I am trying to register a user with Ion Auth, but the register() function does not seem to report any error messages. How does one register with Ion Auth? I've already read various tutorials like this one and this one (and the documentation), but they do not seem to be working.

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;
}

来源:https://stackoverflow.com/questions/20938227/registration-with-codeigniter-ion-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!