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 |