function login() { //This method will have the credentials validation $this->load->library('form_validation'); $this->form_validation->set_rules('inputEmail', 'inputEmail', 'trim|required|xss_clean'); $this->form_validation->set_rules('inputPassword', 'inputPassword', 'trim|required|xss_clean'); if ($this->form_validation->run() == FALSE) { //Field validation failed. User redirected to create_user page redirect('welcome', 'refresh'); } else { //Log in the user $login = login_utility($this->input->post('inputEmail'), $this->input->post('inputPassword')); //Go to private area if ($login) { redirect('home', 'refresh'); } else { redirect('welcome/index/error', 'refresh'); } } }
/** * Create a new user. * The user is automatically logged in. */ function create() { //This method will have the credentials validation $this->load->library('form_validation'); $this->form_validation->set_rules('inputFirstName', 'inputFirstName', 'trim|required|xss_clean'); $this->form_validation->set_rules('inputSurname', 'inputSurname', 'trim|required|xss_clean'); $this->form_validation->set_rules('inputPassword', 'inputPassword', 'trim|required|xss_clean'); $this->form_validation->set_rules('inputRegion', 'inputRegion', 'xss_clean'); $this->form_validation->set_rules('inputEmail', 'inputEmail', 'trim|required|xss_clean'); if ($this->form_validation->run() == FALSE) { //Field validation failed. User redirected to create_user page redirect('create_user', 'refresh'); } else { //Create new user $firstname = $this->input->post('inputFirstName'); $surname = $this->input->post('inputSurname'); $password = $this->input->post('inputPassword'); $birthdate = $this->input->post('inputYear') . '-' . $this->input->post('inputMonth') . '-' . $this->input->post('inputDay'); $region = $this->input->post('inputRegion'); $email = $this->input->post('inputEmail'); //query the database $result = $this->user->create_user($firstname, $surname, $password, $birthdate, $region, $email); //Go to private area if ($result) { login_utility($email = $this->input->post('inputEmail'), $password = $this->input->post('inputPassword')); redirect('home', 'refresh'); } else { redirect('welcome', 'refresh'); } } }