4 * Class User controls video hierarchy and searching
7 * @author Călin-Andrei Burloiu
9 class User extends CI_Controller {
11 private $import = FALSE;
13 public function __construct()
15 parent::__construct();
17 $this->lang->load('user');
18 $this->load->model('users_model');
21 public function index()
26 * Login a user and then redirect it to the last page which must be encoded
29 * @param string $redirect contains the last page URI segments encoded
30 * with helper url_encode_segments.
32 public function login($redirect = '')
34 $this->load->library('form_validation');
36 $this->form_validation->set_error_delimiters('<span class="error">',
39 if ($this->form_validation->run('signin') === FALSE)
41 $params = array( 'title' =>
42 $this->lang->line('ui_nav_menu_login')
44 . $this->config->item('site_name'),
45 //'metas' => array('description'=>'')
47 $this->load->library('html_head_params', $params);
52 $this->load->view('html_begin', $this->html_head_params);
53 $this->load->view('header', array('selected_menu' => 'login'));
55 $main_params['content'] = $this->load->view('user/login_view',
56 array('redirect'=> $redirect), TRUE);
57 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
58 $this->load->view('main', $main_params);
60 $this->load->view('footer');
61 $this->load->view('html_end');
67 // Redirect to last page before login.
68 header('Location: '. site_url(urldecode_segments($redirect)));
72 // Redirect to account page because an user authenticates here
73 // for the first time with external authentication. The page
74 // will display imported data.
75 header('Location: '. site_url('user/account'));
81 * Logout user and then redirect it to the last page which must be encoded
84 * @param string $redirect contains the last page URI segments encoded
85 * with helper url_encode_segments.
87 public function logout($redirect = '')
89 $this->session->unset_userdata('user_id');
90 $this->session->unset_userdata('username');
92 header('Location: '. site_url(urldecode_segments($redirect)));
95 public function register($redirect = '')
97 $this->load->library('form_validation');
98 $this->load->helper('localization');
99 $this->load->helper('date');
101 $this->form_validation->set_error_delimiters('<span class="error">',
104 if ($this->form_validation->run('register') === FALSE)
106 // Edit account data if logged in, otherwise register.
107 if ($user_id = $this->session->userdata('user_id'))
109 $userdata = $this->users_model->get_userdata($user_id);
116 $params = array('title' =>
117 $this->lang->line('ui_nav_menu_register')
119 . $this->config->item('site_name'),
120 //'metas' => array('description'=>'')
122 $this->load->library('html_head_params', $params);
127 $this->load->view('html_begin', $this->html_head_params);
128 $this->load->view('header', array('selected_menu' => 'register'));
130 $main_params['content'] = $this->load->view('user/register_view',
131 array('userdata'=> $userdata, 'redirect'=> $redirect),
133 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
134 $this->load->view('main', $main_params);
136 $this->load->view('footer');
137 $this->load->view('html_end');
141 $user_id = $this->input->post('user-id');
142 $data['email'] = $this->input->post('email');
143 $data['first_name'] = $this->input->post('first-name');
144 $data['last_name'] = $this->input->post('last-name');
145 $data['birth_date'] = $this->input->post('birth-date');
146 $data['country'] = $this->input->post('country');
147 $data['locality'] = $this->input->post('locality');
148 $data['ui_lang'] = $this->input->post('ui-lang');
149 $data['time_zone'] = $this->input->post('time-zone');
154 $password = $this->input->post('new-password');
156 $data['password'] = $this->input->post('new-password');
158 $this->users_model->set_userdata($user_id, $data);
163 $data['username'] = $this->input->post('username');
164 $data['password'] = $this->input->post('password');
166 $this->users_model->register($data);
169 // Redirect to last page before login.
170 header('Location: '. site_url(urldecode_segments($redirect)));
174 public function account($redirect = '')
176 $this->register($redirect);
179 public function _valid_username($username)
181 return (preg_match('/^[a-z0-9\._]+$/', $username) === 1);
184 public function _valid_username_or_email($username)
186 $this->load->helper('email');
188 if (valid_email($username))
191 return $this->_valid_username($username);
194 public function _valid_date($date)
199 return (preg_match('/[\d]{4}-[\d]{2}-[\d]{2}/', $date) === 1);
202 public function _valid_old_password($old_password, $field_username)
207 $username= $this->input->post($field_username);
209 if ($this->users_model->login($username, $old_password))
215 public function _change_password_cond($param)
217 $old = $this->input->post('old-password');
218 $new = $this->input->post('new-password');
219 $newc = $this->input->post('new-password-confirmation');
221 return (!$old && !$new && !$newc)
222 || ($old && $new && $newc);
225 public function _required_by_register($param)
227 $user_id = $this->input->post('user-id');
229 if (! $user_id && ! $param)
235 public function _do_login($username, $field_password)
237 $password = $this->input->post($field_password);
239 $user = $this->users_model->login($username, $password);
241 // Authentication failed.
245 // Authentication successful: set session with user data.
246 $this->session->set_userdata(array(
247 'user_id'=> $user['id'],
248 'username'=> $user['username'],
249 'auth_src'=> $user['auth_src']
251 $this->import = $user['import'];
256 /* End of file user.php */
257 /* Location: ./application/controllers/user.php */