Completed
Push — master ( 4a1c4b...dec28d )
by Angus
03:08
created

UsernameCheck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 10
cts 16
cp 0.625
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 19 3
1
<?php defined('BASEPATH') or exit('No direct script access allowed');
2
3
class UsernameCheck extends AJAX_Controller {
4 1
	public function __construct() {
5 1
		parent::__construct();
6
7 1
		$this->load->library('Limiter');
8 1
		$this->load->library('form_validation');
9 1
	}
10
11
	/**
12
	 * Used by the signup to do a AJAX username check.
13
	 *
14
	 * REQ_PARAMS: username
15
	 * METHOD:     POST
16
	 * URL:        /ajax/username_check
17
	 */
18 1
	public function index() : void {
19 1
		$this->form_validation->set_rules('username', 'Username', 'required|max_length[100]');
20
21 1
		if($this->form_validation->run() === TRUE) {
22
			if(!$this->limiter->limit('username_check', 25)) {
23
				$is_unique_username = $this->form_validation->is_unique_username($this->input->post('username'));
24
25
				$data = [
26
					'success'    => $is_unique_username,
27
					'csrf_token' => $this->security->get_csrf_hash() //CHECK: Does returning this within the same query make the CSRF pointless?
28
				];
29
				$this->_render_json($data);
30
			} else {
31
				$this->output->set_status_header('429', 'Rate limit reached.'); //rate limited reached
32
			}
33
		} else {
34 1
			$this->output->set_status_header('400', 'Missing/invalid parameters.');
35
		}
36 1
	}
37
}
38