|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Log-in page controller class file |
|
4
|
|
|
* |
|
5
|
|
|
* @package EBloodBank |
|
6
|
|
|
* @subpackage Controllers |
|
7
|
|
|
* @since 1.0 |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace EBloodBank\Controllers; |
|
10
|
|
|
|
|
11
|
|
|
use EBloodBank as EBB; |
|
12
|
|
|
use EBloodBank\Notices; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Log-in page controller class |
|
16
|
|
|
* |
|
17
|
|
|
* @since 1.0 |
|
18
|
|
|
*/ |
|
19
|
|
|
class Login extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @return void |
|
23
|
|
|
* @since 1.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __invoke() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->doActions(); |
|
28
|
|
|
$this->addNotices(); |
|
29
|
|
|
$view = $this->viewFactory->forgeView('login'); |
|
30
|
|
|
$view(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return void |
|
35
|
|
|
* @since 1.0 |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function doActions() |
|
38
|
|
|
{ |
|
39
|
|
|
if ('logout' === filter_input(INPUT_GET, 'action')) { |
|
40
|
|
|
$this->doLogoutAction(); |
|
41
|
|
|
} elseif ('login' === filter_input(INPUT_POST, 'action')) { |
|
42
|
|
|
$this->doLoginAction(); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return void |
|
48
|
|
|
* @since 1.0 |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function addNotices() |
|
51
|
|
|
{ |
|
52
|
|
|
if (filter_has_var(INPUT_GET, 'flag-loggedout')) { |
|
53
|
|
|
Notices::addNotice('loggedout', __('You are now logged out.'), 'info'); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return void |
|
59
|
|
|
* @since 1.0 |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function doLoginAction() |
|
62
|
|
|
{ |
|
63
|
|
|
$userEmail = filter_input(INPUT_POST, 'user_email'); |
|
64
|
|
|
$userPass = filter_input(INPUT_POST, 'user_pass'); |
|
65
|
|
|
|
|
66
|
|
|
if (empty($userEmail) || empty($userPass)) { |
|
67
|
|
|
Notices::addNotice('empty_login_details', __('Please enter your login details.'), 'warning'); |
|
68
|
|
|
return; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$user = $this->getUserRepository()->findOneBy(['email' => $userEmail, 'status' => 'any']); |
|
72
|
|
|
|
|
73
|
|
|
if (empty($user) || ! password_verify($userPass, $user->get('pass'))) { |
|
74
|
|
|
Notices::addNotice('wrong_login_details', __('No match for user e-mail and/or password.'), 'warning'); |
|
75
|
|
|
return; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ($user->isPending()) { |
|
79
|
|
|
Notices::addNotice('account_pending_moderation', __('Your account is pending moderation.'), 'warning'); |
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$segment = $this->getSession()->getSegment('EBloodBank'); |
|
84
|
|
|
$segment->set('user_id', (int) $user->get('id')); |
|
85
|
|
|
$this->getSession()->regenerateId(); |
|
86
|
|
|
|
|
87
|
|
|
EBB\redirect(EBB\getHomeURL()); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return void |
|
92
|
|
|
* @since 1.0 |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function doLogoutAction() |
|
95
|
|
|
{ |
|
96
|
|
|
if ($this->hasAuthenticatedUser()) { |
|
97
|
|
|
$this->getSession()->destroy(); |
|
98
|
|
|
$this->getSession()->start(); |
|
99
|
|
|
$this->getSession()->regenerateId(); |
|
100
|
|
|
EBB\redirect( |
|
|
|
|
|
|
101
|
|
|
EBB\addQueryArgs( |
|
|
|
|
|
|
102
|
|
|
EBB\getLoginURL(), |
|
|
|
|
|
|
103
|
|
|
['flag-loggedout' => true] |
|
104
|
|
|
) |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|