Login   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 9.61%

Importance

Changes 0
Metric Value
dl 0
loc 109
ccs 5
cts 52
cp 0.0961
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 10 2
B do_login() 0 28 4
B register() 0 27 4
A logout() 0 8 1
1
<?php
2
3
/**
4
 * Login Controller
5
 */
6
class Login extends MY_Controller {
7
8
	/**
9
	 * Constructor
10
	 */
11 1
	public function __construct()
12
	{
13 1
		parent::__construct();
14 1
		$this->page->set_meta(array('name' =>'google-site-verification', 'content' => 'yuoqLwe6b0rP9DhTbOjuQVPRFl7RY2swO6blPPJWdMQ'));
15 1
		$this->page->set_meta(array('name' => 'description', 'content' => 'Free online social task manager'));
16 1
	}
17
18
	// --------------------------------------------------------------------------
19
20
	/**
21
	 * Alias of 'do_login'
22
	 */
23
	public function index()
24
	{
25
		if($this->session->userdata('uid') === FALSE)
26
		{
27
			$this->do_login();
28
			return;
29
		}
30
31
		$this->todo->redirect_303('task/list');
32
	}
33
34
	// --------------------------------------------------------------------------
35
36
	/**
37
	 * Default method of application
38
	 */
39
	public function do_login()
40
	{
41
		$data = [
42
			'err' => array()
43
		];
44
45
		if($this->input->post('login_sub') != FALSE)
46
		{
47
			$res = $this->todo->verify_user();
48
49
			if($res === TRUE)
50
			{
51
				//Redirect to the tasklist or page at before login
52
				$login_referer = $this->session->userdata('login_referer');
53
				$url = ($login_referer !== FALSE) ? $login_referer : 'task/list';
54
55
				//Unset this for now
56
				$this->session->unset_userdata('login_referer');
57
				$this->todo->redirect_303($url);
58
			}
59
			else
60
			{
61
				$data['err'][] = $res;
62
			}
63
		}
64
		$this->page->set_body_id('home');
65
		$this->page->build('login/login', $data);
66
	}
67
68
	// --------------------------------------------------------------------------
69
70
	/**
71
	 * Registration form and submission
72
	 */
73
	public function register()
74
	{
75
		$data = array();
76
		if ($this->input->post('reg_sub') !== FALSE)
77
		{
78
			if($this->form_validation->run('login/register') === TRUE)
79
			{
80
				if ($this->todo->add_reg())
81
				{
82
					//Redirect to index
83
					$this->todo->redirect_303('login');
84
					return;
85
				}
86
				show_error("Error saving registration");
87
			}
88
			else
89
			{
90
				$data['err'] = $this->form_validation->get_error_array();
91
				$this->page->build('login/register', $data);
92
			}
93
		}
94
		else
95
		{
96
			$data['err']='';
97
			$this->page->build('login/register', $data);
98
		}
99
	}
100
101
	// --------------------------------------------------------------------------
102
103
	/**
104
	 * Logout action
105
	 */
106
	public function logout()
107
	{
108
		//Destroy Session
109
		$this->session->sess_destroy();
110
111
		//Redirect to index
112
		$this->todo->redirect_303('login');
113
	}
114
}
115
// End of controllers/login.php