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;
14 private $ldap_user_info = NULL;
16 public function __construct()
18 parent::__construct();
20 $this->lang->load('user');
23 public function index()
28 * Login a user and then redirect it to the last page which must be encoded
31 * @param string $redirect contains the last page URI segments encoded
32 * with helper url_encode_segments.
34 public function login($redirect = '')
36 $this->load->library('form_validation');
37 $this->load->model('users_model');
39 $this->form_validation->set_error_delimiters('<span class="error">',
42 if ($this->form_validation->run('signin') === FALSE)
44 $params = array( 'title' =>
45 $this->lang->line('ui_nav_menu_login')
47 . $this->config->item('site_name'),
48 //'metas' => array('description'=>'')
50 $this->load->library('html_head_params', $params);
55 $this->load->view('html_begin', $this->html_head_params);
56 $this->load->view('header', array('selected_menu' => 'login'));
58 $this->load->view('user/login_view', array(
59 'redirect'=> $redirect
62 $this->load->view('footer');
63 $this->load->view('html_end');
67 if ($this->user_id !== NULL)
69 $this->session->set_userdata(array(
70 'user_id'=> $this->user_id,
71 'username'=> $this->username
74 // Redirect to last page before login.
75 header('Location: '. site_url(urldecode_segments($redirect)));
79 $this->session->set_userdata(array(
80 'username'=> $this->username
83 // Redirect to register page because an user authenticates here
84 // for the first time with LDAP.
86 header('Location: '. site_url(urldecode_segments($redirect)));
92 * Logout user and then redirect it to the last page which must be encoded
95 * @param string $redirect contains the last page URI segments encoded
96 * with helper url_encode_segments.
98 public function logout($redirect = '')
100 $this->session->unset_userdata('user_id');
101 $this->session->unset_userdata('username');
103 header('Location: '. site_url(urldecode_segments($redirect)));
106 public function register($redirect = '')
108 $this->load->library('form_validation');
109 $this->load->model('users_model');
110 $this->load->helper('localization');
111 $this->load->helper('date');
113 $this->form_validation->set_error_delimiters('<span class="error">',
116 if ($this->form_validation->run('register') === FALSE)
118 $params = array('title' =>
119 $this->lang->line('ui_nav_menu_register')
121 . $this->config->item('site_name'),
122 //'metas' => array('description'=>'')
124 $this->load->library('html_head_params', $params);
129 $this->load->view('html_begin', $this->html_head_params);
130 $this->load->view('header', array('selected_menu' => 'register'));
132 $this->load->view('user/register_view', array(
133 'redirect'=> $redirect
136 $this->load->view('footer');
137 $this->load->view('html_end');
141 if ($this->user_id !== NULL)
143 $this->session->set_userdata(array(
144 'user_id'=> $this->user_id,
145 'username'=> $this->username
148 // Redirect to last page before login.
149 header('Location: '. site_url(urldecode_segments($redirect)));
153 $this->session->set_userdata(array(
154 'username'=> $this->username
157 // Redirect to register page because an user authenticates here
158 // for the first time with LDAP.
160 header('Location: '. site_url(urldecode_segments($redirect)));
165 public function _valid_username($username)
167 return (preg_match('/^[a-z0-9\._]+$/', $username) == 1);
170 public function _valid_username_or_email($username)
172 $this->load->helper('email');
174 if (valid_email($username))
177 return $this->_valid_username($username);
180 public function _do_login($username, $field_password)
182 $password = $this->input->post('password');
184 $this->load->model('users_model');
185 $user = $this->users_model->login($username, $password);
187 // Authentication failed
191 // First authentication of a user with LDAP, i.e. the user does not
192 // have an user_id in `users` DB table yet.
193 if ($user['auth_src'] == 'ldap_first_time')
195 $this->ldap_user_info = $user;
196 $this->username = $user['uid'][0];
197 $this->email = $user['mail'][0];
201 // Authentication when the user has an user_id in the DB.
202 $this->username = $user['username'];
203 $this->email = $user['email'];
204 $this->user_id = $user['id'];
210 /* End of file user.php */
211 /* Location: ./application/controllers/user.php */