Conditions | 6 |
Paths | 6 |
Total Lines | 72 |
Code Lines | 41 |
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'); |
||
127 | public function passkey() { |
||
128 | |||
129 | $ip = $_SERVER['REMOTE_ADDR']; |
||
130 | if ($this->user_model->ip_is_private($ip) === FALSE) { |
||
131 | |||
132 | redirect('authentication/internal'); |
||
133 | |||
134 | } else { |
||
135 | |||
136 | $this->load->helper('form'); |
||
137 | $this->load->library('form_validation'); |
||
138 | |||
139 | // validation rules |
||
140 | $this->form_validation->set_rules('passid', 'PassID', 'required'); |
||
141 | $this->form_validation->set_rules('passkey', 'Passkey', 'required'); |
||
142 | |||
143 | if ($this->form_validation->run() == false) { |
||
144 | |||
145 | $this->load->view('templates/header'); |
||
146 | $this->load->view('templates/passkey'); |
||
147 | $this->load->view('templates/footer'); |
||
148 | } else { |
||
149 | |||
150 | $passid = $this->input->post('passid'); |
||
151 | $passkey = $this->input->post('passkey'); |
||
152 | |||
153 | if ($this->user_model->resolve_passkey($passid, $passkey)) { |
||
154 | |||
155 | $this->user_model->log_passkey($ip, $passid); |
||
156 | $details = $this->user_model->get_passkey_details($passid); |
||
157 | |||
158 | $function = 'passkey_SUCCESSFUL'; |
||
159 | $this->user_model->function_log($function); |
||
160 | |||
161 | if (isset($_COOKIE['CI_PASSKEY']) === FALSE) { |
||
162 | |||
163 | $encrypt_item = array('passkey_array', $passid); |
||
164 | |||
165 | setcookie('CI_PASSKEY', serialize($encrypt_item), time() + (18000), "/"); |
||
166 | redirect($details[0]['url']); |
||
167 | |||
168 | } else { |
||
169 | |||
170 | $current_array = unserialize($_COOKIE['CI_PASSKEY']); |
||
171 | |||
172 | if (!in_array($passid, $current_array)) { |
||
173 | |||
174 | $current_array[] = $passid; |
||
175 | |||
176 | setcookie('CI_PASSKEY', serialize($current_array), time() + (18000), "/"); |
||
177 | redirect($details[0]['url']); |
||
178 | |||
179 | } else { |
||
180 | redirect($details[0]['url']); |
||
181 | } |
||
182 | |||
183 | } |
||
184 | } else { |
||
185 | |||
186 | $function = 'passkey_INCORRECT'; |
||
187 | $this->user_model->function_log($function); |
||
188 | |||
189 | $data = new stdClass(); |
||
190 | $data->error = 'Wrong password please try again.'; |
||
191 | |||
192 | $this->load->view('templates/header'); |
||
193 | $this->load->view('templates/passkey', $data); |
||
194 | $this->load->view('templates/footer'); |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | } |
||
199 | |||
202 | // END controller |