4 * Class User controls video hierarchy and searching
7 * @author Călin-Andrei Burloiu
9 class User extends CI_Controller {
11 private $username = NULL;
12 private $email = NULL;
13 private $user_id = NULL;
15 public function __construct()
17 parent::__construct();
19 $this->lang->load('user');
22 public function index()
26 public function login()
28 $this->load->library('form_validation');
29 $this->load->model('users_model');
31 $username = $this->input->post('username');
32 $password = $this->input->post('password');
34 $form_validation_config = array(
37 'label'=>'lang:user_username_or_email',
38 'rules'=>'trim|required|min_length[5]|max_length[32]'
39 . '|strtolower|callback__valid_username'
40 . '|callback__do_login[password]'
44 'label'=>'lang:user_password',
45 'rules'=>'required|min_length[5]|max_length[32]'
48 $this->form_validation->set_rules($form_validation_config);
49 $this->form_validation->set_error_delimiters('<span class="error">',
52 if ($this->form_validation->run() === FALSE)
54 $params = array( 'title' => $this->config->item('site_name'),
59 //'metas' => array('description'=>'')
61 $this->load->library('html_head_params', $params);
66 $this->load->view('html_begin', $this->html_head_params);
67 $this->load->view('header', array('selected_menu' => 'login'));
69 $this->load->view('user/login_view', array());
71 $this->load->view('footer');
72 $this->load->view('html_end');
76 if ($this->user_id !== NULL)
78 $this->session->set_userdata(array(
79 'user_id'=> $this->user_id,
80 'username'=> $this->username
84 header('Location: '. site_url());
89 public function _valid_username($username)
91 $this->load->helper('email');
93 if (valid_email($username))
96 return (preg_match('/^[a-z0-9\._]+$/', $username) == 1);
99 public function _do_login($username, $field_password)
101 $password = $this->input->post('password');
103 $this->load->model('users_model');
104 $res_login = $this->users_model->login($username, $password);
106 // First authentication of a user with LDAP, i.e. the user does not
107 // have an user_id in `users` DB table yet.
108 if ($res_login === TRUE)
110 // Authentication failed
111 else if ($res_login === FALSE)
114 // Authentication when the user has an user_id in the DB.
115 $this->username = $res_login['username'];
116 $this->email = $res_login['email'];
117 $this->user_id = $res_login['id'];
123 /* End of file user.php */
124 /* Location: ./application/controllers/user.php */