| Conditions | 7 |
| Paths | 7 |
| Total Lines | 69 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php defined('BASEPATH') OR exit('No direct script access allowed'); |
||
| 15 | public function external_login() { |
||
| 16 | |||
| 17 | $ip = $_SERVER['REMOTE_ADDR']; |
||
| 18 | if ($this->user_model->ip_is_private($ip) === TRUE) { |
||
| 19 | |||
| 20 | redirect('/'); |
||
| 21 | } else { |
||
| 22 | |||
| 23 | if (isset($_SESSION['external_login']) === TRUE) { |
||
| 24 | |||
| 25 | redirect('/'); |
||
| 26 | } else { |
||
| 27 | |||
| 28 | $uid = $_SESSION['uid']; |
||
| 29 | if ($this->user_model->external_login_blocked($uid) === TRUE) { |
||
| 30 | |||
| 31 | redirect('/authentication/user-lockout'); |
||
| 32 | } else { |
||
| 33 | |||
| 34 | $this->load->helper('form'); |
||
| 35 | $this->load->library('form_validation'); |
||
| 36 | |||
| 37 | // validation rules |
||
| 38 | $this->form_validation->set_rules('password', 'Password', 'required'); |
||
| 39 | |||
| 40 | if ($this->form_validation->run() == false) { |
||
| 41 | |||
| 42 | $this->load->view('templates/header'); |
||
| 43 | $this->load->view('templates/ldap'); |
||
| 44 | $this->load->view('templates/footer'); |
||
| 45 | } else { |
||
| 46 | |||
| 47 | $username = $_SESSION['username']; |
||
| 48 | $password = $this->input->post('password'); |
||
| 49 | |||
| 50 | if ($this->user_model->resolve_user_login($username, $password)) { |
||
| 51 | |||
| 52 | $this->session->set_userdata('external_login', TRUE); |
||
| 53 | redirect($_SESSION['last_url']); |
||
| 54 | } else { |
||
| 55 | |||
| 56 | if ($this->user_model->external_login_blocked($uid) === TRUE) { |
||
| 57 | |||
| 58 | redirect('/authentication/user-lockout'); |
||
| 59 | |||
| 60 | $function = 'external_login_LOCKOUT'; |
||
| 61 | $this->user_model->function_log($function); |
||
| 62 | |||
| 63 | } else { |
||
| 64 | |||
| 65 | $function = 'external_login_PASSWORD_INCORRECT'; |
||
| 66 | $this->user_model->function_log($function); |
||
| 67 | |||
| 68 | $data = new stdClass(); |
||
| 69 | $data->error = 'Wrong password please try again.'; |
||
| 70 | |||
| 71 | // loose an attempt |
||
| 72 | $this->user_model->external_login_fail($uid); |
||
| 73 | |||
| 74 | $this->load->view('templates/header'); |
||
| 75 | $this->load->view('templates/ldap', $data); |
||
| 76 | $this->load->view('templates/footer'); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 202 | // END controller |