forked from mikegioia/phalcon-boilerplate
/
AuthController.php
53 lines (44 loc) · 1.21 KB
/
AuthController.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
<?php
namespace Controllers;
class AuthController extends \Base\Controller
{
public function beforeExecuteRoute()
{
$this->checkLoggedIn = FALSE;
return parent::beforeExecuteRoute();
}
/**
* Accepts an email and password, attempts to log user in
* and create a session. Returns a session ID.
*/
public function loginAction()
{
$email = $this->request->getPost( 'email' );
$password = $this->request->getPost( 'password' );
// try to log in with credentials
//
$this->redirect = 'dashboard';
$action = new \Actions\Users\Auth();
$loggedIn = $action->login(
array(
'email' => $email,
'password' => $password
));
if ( ! $loggedIn )
{
$this->redirect = 'login';
}
}
/**
* Kill the session and login cookie
*/
public function logoutAction()
{
$action = new \Actions\Users\Auth();
$action->destroyToken();
$action->destroySession( FALSE );
$this->cookies->get( 'token' )->delete();
$this->redirect = 'login';
$this->addMessage( "You've been logged out" );
}
}