forked from midgardproject/midgardmvc_core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
authentication.php
72 lines (64 loc) · 2 KB
/
authentication.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @package midgardmvc_core
* @author The Midgard Project, http://www.midgard-project.org
* @copyright The Midgard Project, http://www.midgard-project.org
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
*/
/**
* Comet listeners controller
*
* @package midgardmvc_core
*/
class midgardmvc_core_controllers_authentication
{
public function __construct()
{
$this->configuration = midgardmvc_core::get_instance()->configuration;
}
public function get_logout(array $args)
{
midgardmvc_core::get_instance()->authentication->logout();
midgardmvc_core::get_instance()->head->relocate('/');
}
public function get_login(array $args)
{
if (!isset($this->data['redirect_url']))
{
$this->data['redirect_url'] = '/';
if (isset($_GET['redirect']))
{
$this->data['redirect_url'] = $_GET['redirect'];
}
}
if (midgardmvc_core::get_instance()->authentication->is_user())
{
midgardmvc_core::get_instance()->head->relocate($this->data['redirect_url']);
}
$exception_data = array();
$exception_data['message'] = midgardmvc_core::get_instance()->i18n->get
(
'please enter your username and password', 'midgardmvc_core'
);
midgardmvc_core::get_instance()->context->midgardmvc_core_exceptionhandler = $exception_data;
}
public function post_login(array $args)
{
if (isset($_POST['redirect']))
{
$this->data['redirect_url'] = $_POST['redirect'];
}
if ( isset($_POST['username'])
&& isset($_POST['password']))
{
$tokens = array
(
'login' => $_POST['username'],
'password' => $_POST['password'],
);
midgardmvc_core::get_instance()->authentication->login($tokens);
}
$this->get_login($args);
}
}
?>