+
+ $this->load->library('form_validation');
+
+ $this->form_validation->set_error_delimiters('<span class="error">',
+ '</span>');
+
+ if ($res_form_validation === FALSE)
+ {
+ $params = array(
+ 'title'=> $this->lang->line('user_title_activation')
+ .' – '
+ . $this->config->item('site_name'),
+ //'metas' => array('description'=>'')
+ );
+ $this->load->library('html_head_params', $params);
+
+ // **
+ // ** LOADING VIEWS
+ // **
+ $this->load->view('html_begin', $this->html_head_params);
+ $this->load->view('header', array());
+
+ // Show form
+ $main_params['content'] =
+ $this->load->view('user/activate_view',
+ array( 'user_id'=> $user_id,
+ 'email'=> $userdata['email']),
+ TRUE);
+
+ $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
+ $this->load->view('main', $main_params);
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+ else
+ {
+ if ($method == 'code')
+ {
+ // A message which tells the user that the
+ // activation was successful.
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));
+ return;
+ }
+ else if ($method == 'resend')
+ {
+ // Redirect to resent message
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_activation_resent'),
+ $this->input->post('email')));
+ return;
+ }
+ }
+ }
+
+ public function recover_password()
+ {
+ $this->load->library('form_validation');
+
+ $this->form_validation->set_error_delimiters('<span class="error">',
+ '</span>');
+
+ if ($this->form_validation->run('recover_password') === FALSE)
+ {
+ $params = array( 'title' =>
+ $this->lang->line(
+ 'user_title_password_recovery')
+ .' – '
+ . $this->config->item('site_name'),
+ //'metas' => array('description'=>'')
+ );
+ $this->load->library('html_head_params', $params);
+
+ // **
+ // ** LOADING VIEWS
+ // **
+ $this->load->view('html_begin', $this->html_head_params);
+ $this->load->view('header', array('selected_menu' =>
+ 'recover_password'));
+
+ $main_params['content'] = $this->load->view(
+ 'user/recover_password_view', array(),
+ TRUE);
+
+ $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
+ $this->load->view('main', $main_params);
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+ else
+ {
+ // Resent message
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_password_recovery_email_sent'),
+ $this->input->post('username'),
+ $this->input->post('email')));
+ return;
+ }
+ }
+
+ public function _format_message($msg, $val = '', $sub = '%s')
+ {
+ return str_replace($sub, $val, $this->lang->line($msg));
+ }
+
+ public function _update_session_userdata($data)
+ {
+ foreach ($data as $key=> $val)
+ $this->session->set_userdata($key, $val);
+ }
+
+ public function _valid_username($username)
+ {
+ return (preg_match('/^[a-z0-9\._]+$/', $username) === 1);
+ }
+
+ public function _valid_username_or_email($username)
+ {
+ $this->load->helper('email');
+
+ if (valid_email($username))
+ return TRUE;
+ else
+ return $this->_valid_username($username);
+ }
+
+ public function _valid_date($date)
+ {
+ if (! $date)
+ return TRUE;
+
+ return (preg_match('/[\d]{4}-[\d]{2}-[\d]{2}/', $date) === 1);
+ }
+
+ public function _postprocess_birth_date($date)
+ {
+ // If the user entered no birth date NULL needs to be inserted into DB.
+ if (! $date)
+ return NULL;
+
+ return $date;
+ }
+
+ public function _valid_old_password($old_password, $field_username)
+ {
+ if (! $old_password)
+ return TRUE;
+
+ $username= $this->input->post($field_username);
+
+ if ($this->users_model->login($username, $old_password))
+ return TRUE;
+
+ return FALSE;
+ }
+
+ public function _change_password_cond($param)
+ {
+ $old = $this->input->post('old-password');
+ $new = $this->input->post('new-password');
+ $newc = $this->input->post('new-password-confirmation');
+
+ return (!$old && !$new && !$newc)
+ || ($old && $new && $newc);
+ }
+
+ public function _required_by_register($param)
+ {
+ $user_id = $this->input->post('user-id');
+
+ if (! $user_id && ! $param)
+ return FALSE;
+
+ return TRUE;
+ }
+
+ public function _valid_activation_code($activation_code)
+ {
+ return (preg_match('/^[a-fA-F0-9]{16}$/', $activation_code) == 1);
+ }
+
+ public function _do_login($username, $field_password)
+ {
+ $password = $this->input->post($field_password);
+
+ $user = $this->users_model->login($username, $password);
+
+ // Authentication failed.
+ if ($user === FALSE)
+ return FALSE;
+
+ // User has not activated the account.
+ if ($user['activation_code'] !== NULL)
+ {
+ $this->activated_account = FALSE;
+ $this->user_id = $user['id'];
+ return TRUE;
+ }
+
+ // Authentication successful: set session with user data.
+ $this->session->set_userdata(array(
+ 'user_id'=> $user['id'],
+ 'username'=> $user['username'],
+ 'auth_src'=> $user['auth_src'],
+ 'time_zone'=> $user['time_zone']
+ ));
+ $this->import = (isset($user['import']) ? $user['import'] : FALSE);
+ return TRUE;
+ }
+
+ public function _do_activate($activation_code)
+ {
+ $user_id = $this->input->post('user-id');
+ if ($user_id === FALSE)
+ return FALSE;
+ $user_id = intval($user_id);
+
+ return $this->users_model->activate_account($user_id,
+ $activation_code);
+ }
+
+ public function _do_resend_activation($email)
+ {
+ $user_id = $this->input->post('user-id');
+ if ($user_id === FALSE)
+ return FALSE;
+ $user_id = intval($user_id);
+
+ $this->users_model->set_userdata($user_id,
+ array('email'=> $email));
+
+ return $this->users_model->send_activation_email($user_id, $email);