<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Registers extends CI_Controller {
	public function create(){
		$this->load->library("form_validation");
		$this->form_validation->set_rules("username", "Username", "required|trim|min_length[3]|is_unique[users.username]");
		$this->form_validation->set_rules("password1", "Password", "required|matches[password2]|trim|min_length[8]");
		$this->form_validation->set_rules("password2", "Confirm Password", "required|trim|min_length[8]");
		$this->form_validation->set_rules("name", "Name", "min_length[3]|required|trim");
		if($this->form_validation->run() === FALSE){
			$this->load->view('register_login_view');
		}
		else{
			$this->load->model('User');
			$id = $this->User->register($this->input->post('username'),sha1($this->input->post('password1')),$this->input->post('name'));
			$this->session->set_userdata('username',$this->input->post('username'));
			$this->session->set_userdata('id',$id);
			redirect('/travels');
		}
	}

	
}