| 34 | | //loads necessary libraries |
|---|
| 35 | | $this->lang->load('freakauth'); |
|---|
| 36 | | $this->load->model('Usermodel'); |
|---|
| 37 | | //lets load the validation class if it hasn't been already loaded |
|---|
| 38 | | //it is needed by the FAL_validation library |
|---|
| 39 | | if ( ! class_exists('CI_Validation')) |
|---|
| 40 | | { |
|---|
| 41 | | $this->load->library('validation'); |
|---|
| 42 | | } |
|---|
| 43 | | $this->load->library('FAL_validation', 'fal_validation'); |
|---|
| 44 | | |
|---|
| 45 | | $this->fal_validation->set_error_delimiters($this->config->item('FAL_error_delimiter_open'), $this->config->item('FAL_error_delimiter_close')); |
|---|
| 46 | | |
|---|
| 47 | | //sets the necessary form fields |
|---|
| 48 | | $fields['user_name'] = $this->lang->line('FAL_user_name_label'); |
|---|
| 49 | | $fields['password'] = $this->lang->line('FAL_user_password_label'); |
|---|
| 50 | | $fields['password_confirm'] = $this->lang->line('FAL_user_password_confirm_label'); |
|---|
| 51 | | $fields['email'] = $this->lang->line('FAL_user_email_label'); |
|---|
| 52 | | $fields['security'] = $this->lang->line('FAL_captcha_label'); |
|---|
| 53 | | |
|---|
| 54 | | //if activated in config, sets the select country box |
|---|
| 55 | | if ($this->config->item('FAL_use_country')) |
|---|
| 56 | | $fields['country_id'] = $this->lang->line('FAL_user_country_label'); |
|---|
| 57 | | |
|---|
| 58 | | //------------------------------------- |
|---|
| 59 | | //ADD MORE FIELDS HERE IF YOU NEED THEM |
|---|
| 60 | | //------------------------------------- |
|---|
| 61 | | |
|---|
| 62 | | $this->fal_validation->set_fields($fields); |
|---|
| | 33 | $this->load->library('FAL_front', 'fal_front'); |
|---|
| 90 | | } |
|---|
| 91 | | |
|---|
| 92 | | // -------------------------------------------------------------------- |
|---|
| 93 | | |
|---|
| 94 | | /** |
|---|
| 95 | | * Handles the post from the login form. |
|---|
| 96 | | * |
|---|
| 97 | | */ |
|---|
| 98 | | function _login() |
|---|
| 99 | | { |
|---|
| 100 | | $rules['user_name'] = $this->config->item('FAL_user_name_field_validation_login'); |
|---|
| 101 | | $rules['password'] = $this->config->item('FAL_user_password_field_validation_login'); |
|---|
| 102 | | $rules['username_password'] = ''; |
|---|
| 103 | | |
|---|
| 104 | | //------------------------------------- |
|---|
| 105 | | //ADD MORE RULES HERE IF YOU NEED THEM |
|---|
| 106 | | //------------------------------------- |
|---|
| 107 | | |
|---|
| 108 | | //do we want chaptcha for login? |
|---|
| 109 | | if ($this->config->item('FAL_use_security_code_login')) |
|---|
| 110 | | { |
|---|
| 111 | | $rules['security'] = $this->config->item('FAL_user_security_code_field_validation'); |
|---|
| 112 | | } |
|---|
| 113 | | |
|---|
| 114 | | $this->fal_validation->set_rules($rules); |
|---|
| 115 | | |
|---|
| 116 | | //let's run the individual validation of username and password |
|---|
| 117 | | $validation_response = $this->fal_validation->run(); |
|---|
| 118 | | |
|---|
| 119 | | //if you change the keys of the validation rules |
|---|
| 120 | | //remember to adjust the following 2 lines |
|---|
| 121 | | //i.e. change $this->fal_validation->user_name to $this->fal_validation->your_user_name_key |
|---|
| 122 | | $username_login = $this->fal_validation->user_name; |
|---|
| 123 | | $password_login = $this->fal_validation->password; |
|---|
| 124 | | |
|---|
| 125 | | //everything went ok, let's log the user in and redirect him to the homepage |
|---|
| 126 | | if ($validation_response==TRUE && $this->fal_validation->login_check($username_login, $password_login) && $this->freakauth_light->login()) |
|---|
| 127 | | { |
|---|
| 128 | | $role= $this->db_session->userdata('role'); |
|---|
| 129 | | |
|---|
| 130 | | switch ($role) |
|---|
| 131 | | { |
|---|
| 132 | | case ('superadmin'): |
|---|
| 133 | | case ('admin'): |
|---|
| 134 | | redirect($this->config->item('FAL_admin_login_success_action'), 'location'); //On success redirect user to default page |
|---|
| 135 | | break; |
|---|
| 136 | | |
|---|
| 137 | | default: |
|---|
| 138 | | redirect($this->config->item('FAL_login_success_action'), 'location'); //On success redirect user to default page |
|---|
| 139 | | break; |
|---|
| 140 | | } |
|---|
| 141 | | } |
|---|
| 142 | | |
|---|
| 143 | | //else display the login form again |
|---|
| 144 | | else |
|---|
| 145 | | { |
|---|
| 146 | | //page title |
|---|
| 147 | | $data['heading'] = $this->lang->line('FAL_login_label'); |
|---|
| 148 | | |
|---|
| 149 | | if ($this->config->item('FAL_use_security_code_login')) |
|---|
| 150 | | { |
|---|
| 151 | | $action='_login'; |
|---|
| 152 | | $this->freakauth_light->captcha_init($action); |
|---|
| 153 | | $data['captcha'] = $this->config->item('FAL_security_code_image'); |
|---|
| 154 | | } |
|---|
| 155 | | $data['page']= $this->config->item('FAL_login_view'); |
|---|
| 156 | | |
|---|
| 157 | | $this->load->view($this->_container, $data); |
|---|
| 158 | | |
|---|
| 159 | | //$this->output->enable_profiler(TRUE); |
|---|
| 160 | | } |
|---|
| 182 | | { |
|---|
| 183 | | //if users are not allowed to register |
|---|
| 184 | | if (!$this->config->item('FAL_allow_user_registration')) |
|---|
| 185 | | { |
|---|
| 186 | | redirect('', 'location'); |
|---|
| 187 | | } |
|---|
| 188 | | //if they are allowed to register |
|---|
| 189 | | else |
|---|
| 190 | | { |
|---|
| 191 | | //set validation rules |
|---|
| 192 | | $rules['user_name'] = $this->config->item('FAL_user_name_field_validation_register'); |
|---|
| 193 | | $rules['password'] = $this->config->item('FAL_user_password_field_validation_register'); |
|---|
| 194 | | $rules['password_confirm'] = $this->config->item('FAL_password_required_confirm_validation')."|matches[".'password'."]"; |
|---|
| 195 | | $rules['email'] = $this->config->item('FAL_user_email_field_validation_register'); |
|---|
| 196 | | |
|---|
| 197 | | //do we also want to know the user country? |
|---|
| 198 | | if ($this->config->item('FAL_use_country')) |
|---|
| 199 | | { |
|---|
| 200 | | $rules['country_id'] = $this->config->item('FAL_user_country_field_validation_register'); |
|---|
| 201 | | } |
|---|
| 202 | | //do we also want to secure the registration with CAPTCHA? |
|---|
| 203 | | if ($this->config->item('FAL_use_security_code_register')) |
|---|
| 204 | | { |
|---|
| 205 | | $rules['security'] = $this->config->item('FAL_user_security_code_field_validation'); |
|---|
| 206 | | } |
|---|
| 207 | | |
|---|
| 208 | | //additionalRegistrationRules($rules); |
|---|
| 209 | | |
|---|
| 210 | | $this->fal_validation->set_rules($rules); |
|---|
| 211 | | |
|---|
| 212 | | //if everything went ok |
|---|
| 213 | | if ($this->fal_validation->run() && $this->freakauth_light->register()) |
|---|
| 214 | | { |
|---|
| 215 | | $data = array( |
|---|
| 216 | | 'heading' => 'Registration', |
|---|
| 217 | | 'page' => $this->config->item('FAL_register_success_view') |
|---|
| 218 | | ); |
|---|
| | 88 | { |
|---|
| | 89 | //displays the view |
|---|
| | 90 | $data['fal'] = $this->fal_front->register(); |
|---|
| | 91 | $this->load->view($this->_container, $data); |
|---|
| 220 | | $this->load->view($this->_container, $data); |
|---|
| 221 | | //$this->output->enable_profiler(TRUE); |
|---|
| 222 | | } |
|---|
| 223 | | |
|---|
| 224 | | //redisplay the register form |
|---|
| 225 | | else |
|---|
| 226 | | { |
|---|
| 227 | | //if we want to know the user country let's populate the select menu |
|---|
| 228 | | if ($this->config->item('FAL_use_country')) |
|---|
| 229 | | { |
|---|
| 230 | | $this->load->model('country'); |
|---|
| 231 | | |
|---|
| 232 | | //SELECT * FROM country |
|---|
| 233 | | $data['countries'] = $this->country->getCountriesForSelect(); |
|---|
| 234 | | } |
|---|
| 235 | | //if we want to secure the registration with CAPTCHA let's generate it |
|---|
| 236 | | if ($this->config->item('FAL_use_security_code_register')) |
|---|
| 237 | | { |
|---|
| 238 | | $action='_register'; |
|---|
| 239 | | $this->freakauth_light->captcha_init($action); |
|---|
| 240 | | $data['captcha'] = $this->config->item('FAL_security_code_image'); |
|---|
| 241 | | } |
|---|
| 242 | | |
|---|
| 243 | | //displays the view |
|---|
| 244 | | $data['heading'] = $this->lang->line('FAL_register_label'); |
|---|
| 245 | | $data['page'] = $this->config->item('FAL_register_view'); |
|---|
| 246 | | |
|---|
| 247 | | $this->load->view($this->_container, $data); |
|---|
| 248 | | |
|---|
| 249 | | //$this->output->enable_profiler(TRUE); |
|---|
| 250 | | |
|---|
| 251 | | //$this->db_session->flashdata_mark(); |
|---|
| 252 | | } |
|---|
| 253 | | } |
|---|
| | 93 | //$this->output->enable_profiler(TRUE); |
|---|
| | 94 | |
|---|
| 264 | | //passes the URI segments to freakauth-ligh [UserTemp id segment(3) and the activation code segment(4)] |
|---|
| 265 | | //if the activation is successfull displays the success page |
|---|
| 266 | | if ($this->freakauth_light->activation($this->uri->segment(3, 0), $this->uri->segment(4, ''))) |
|---|
| 267 | | { |
|---|
| 268 | | $data = array( |
|---|
| 269 | | 'heading' => $this->lang->line('FAL_registration_label'), |
|---|
| 270 | | 'page' => $this->config->item('FAL_register_activation_success_view') |
|---|
| 271 | | ); |
|---|
| 272 | | |
|---|
| 273 | | $this->load->vars($data); |
|---|
| 274 | | |
|---|
| 275 | | $this->load->view($this->_container); |
|---|
| 276 | | } |
|---|
| 277 | | //if activation unsuccessfull redispaly the failure view message |
|---|
| 278 | | else |
|---|
| 279 | | { |
|---|
| 280 | | $data = array( |
|---|
| 281 | | 'heading' => $this->lang->line('FAL_registration_label'), |
|---|
| 282 | | 'page' => $this->config->item('FAL_register_activation_failed_view') |
|---|
| 283 | | ); |
|---|
| 284 | | |
|---|
| 285 | | $this->load->view($this->_container, $data); |
|---|
| 286 | | } |
|---|
| 287 | | |
|---|
| | 105 | $data['fal'] = $this->fal_front->activation(); |
|---|
| | 106 | $this->load->view($this->_container, $data); |
|---|
| 298 | | //set necessary validation rules |
|---|
| 299 | | $rules['email'] = "trim|required|valid_email|xss_clean|email_exists_check"; |
|---|
| 300 | | |
|---|
| 301 | | //do we also want CAPTCHA? |
|---|
| 302 | | if ($this->config->item('FAL_use_security_code_forgot_password')) |
|---|
| 303 | | { |
|---|
| 304 | | $rules['security'] = $this->config->item('FAL_user_security_code_field_validation'); |
|---|
| 305 | | } |
|---|
| 306 | | |
|---|
| 307 | | $this->fal_validation->set_rules($rules); |
|---|
| 308 | | |
|---|
| 309 | | //if it got post data and they validate display the success page |
|---|
| 310 | | if ($this->fal_validation->run() && $this->freakauth_light->forgotten_password()) |
|---|
| 311 | | { |
|---|
| 312 | | $data['heading'] = $this->lang->line('FAL_forgotten_password_label'); |
|---|
| 313 | | $data['page'] = $this->config->item('FAL_forgotten_password_success_view'); |
|---|
| 314 | | |
|---|
| 315 | | $this->load->vars($data); |
|---|
| 316 | | |
|---|
| 317 | | $this->load->view($this->_container); |
|---|
| 318 | | } |
|---|
| 319 | | |
|---|
| 320 | | //else display the initial forgotten password form |
|---|
| 321 | | else |
|---|
| 322 | | { $this->db_session->flashdata_mark(); |
|---|
| 323 | | |
|---|
| 324 | | //do we want captcha |
|---|
| 325 | | if ($this->config->item('FAL_use_security_code_forgot_password')) |
|---|
| 326 | | { |
|---|
| 327 | | $action='_forgot_password'; |
|---|
| 328 | | $this->freakauth_light->captcha_init($action); |
|---|
| 329 | | $data['captcha'] = $this->config->item('FAL_security_code_image'); |
|---|
| 330 | | } |
|---|
| 331 | | |
|---|
| 332 | | //display the form |
|---|
| 333 | | $data['heading'] = $this->lang->line('FAL_forgotten_password_label'); |
|---|
| 334 | | $data['page'] = $this->config->item('FAL_forgotten_password_view'); |
|---|
| 335 | | |
|---|
| 336 | | $this->load->view($this->_container, $data); |
|---|
| 337 | | } |
|---|
| | 117 | $data['fal'] = $this->fal_front->forgotten_password(); |
|---|
| | 118 | $this->load->view($this->_container, $data); |
|---|
| 348 | | //if password has been successfully reset (randomly generate, ins in DB and sent to the user) |
|---|
| 349 | | //display success |
|---|
| 350 | | if ($this->freakauth_light->forgotten_password_reset($this->uri->segment(3, 0), $this->uri->segment(4, ''))) |
|---|
| 351 | | { |
|---|
| 352 | | $data = array( |
|---|
| 353 | | 'heading' => 'Remember password', |
|---|
| 354 | | 'page' => $this->config->item('FAL_forgotten_password_reset_success_view') |
|---|
| 355 | | ); |
|---|
| 356 | | |
|---|
| 357 | | $this->load->vars($data); |
|---|
| 358 | | |
|---|
| 359 | | $this->load->view($this->_container); |
|---|
| 360 | | |
|---|
| 361 | | } |
|---|
| 362 | | //tell the user about the problems and display unsuccess view |
|---|
| 363 | | else |
|---|
| 364 | | { |
|---|
| 365 | | $data = array( |
|---|
| 366 | | 'heading' => 'Remember password', |
|---|
| 367 | | 'page' => $this->config->item('FAL_forgotten_password_reset_failed_view') |
|---|
| 368 | | ); |
|---|
| 369 | | |
|---|
| 370 | | $this->load->view($this->_container, $data); |
|---|
| 371 | | |
|---|
| 372 | | } |
|---|
| 373 | | |
|---|
| | 129 | $data['fal'] = $this->fal_front->forgotten_password_reset(); |
|---|
| | 130 | $this->load->view($this->_container, $data); |
|---|
| 387 | | |
|---|
| 388 | | $rules['user_name'] = $this->config->item('FAL_user_name_field_validation_login'); |
|---|
| 389 | | //old password |
|---|
| 390 | | $rules['password'] = $this->config->item('FAL_user_password_field_validation_login'); |
|---|
| 391 | | //new password |
|---|
| 392 | | $rules['new_password'] = $this->config->item('FAL_password_required_validation'); |
|---|
| 393 | | //new password confirmation |
|---|
| 394 | | $rules['password_confirm'] = 'trim|required|xss_clean|matches[new_password]'; |
|---|
| 395 | | |
|---|
| 396 | | $this->fal_validation->set_rules($rules); |
|---|
| 397 | | |
|---|
| 398 | | //sets the necessary form fields |
|---|
| 399 | | $fields['new_password'] = 'new_password'; |
|---|
| 400 | | |
|---|
| 401 | | $this->fal_validation->set_fields($fields); |
|---|
| 402 | | |
|---|
| 403 | | //if it got post data and they validate display the success page |
|---|
| 404 | | if ($this->fal_validation->run() && $this->freakauth_light->_change_password()) |
|---|
| 405 | | { |
|---|
| 406 | | //set FLASH MESSAGE |
|---|
| 407 | | $msg = $this->lang->line('FAL_change_password_success'); |
|---|
| 408 | | flashMsg($msg); |
|---|
| 409 | | |
|---|
| 410 | | redirect('', 'location'); |
|---|
| 411 | | } |
|---|
| 412 | | |
|---|
| 413 | | //else display the initial change password form |
|---|
| 414 | | else |
|---|
| 415 | | { |
|---|
| 416 | | //page title |
|---|
| 417 | | $data['heading'] = $this->lang->line('FAL_change_password_label'); |
|---|
| 418 | | //page content |
|---|
| 419 | | $data['page'] = $this->config->item('FAL_change_password_view'); |
|---|
| 420 | | |
|---|
| 421 | | //page display |
|---|
| 422 | | $this->load->view($this->_container, $data); |
|---|
| 423 | | } |
|---|
| | 144 | $data['fal'] = $this->fal_front->changepassword(); |
|---|
| | 145 | $this->load->view($this->_container, $data); |
|---|