1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RssApp\Controller; |
4
|
|
|
|
5
|
|
|
use RssApp\Components\Registry; |
6
|
|
|
use RssApp\Components\User; |
7
|
|
|
use RssApp\Controller; |
8
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
9
|
|
|
use Zend\Diactoros\Response\RedirectResponse; |
10
|
|
|
|
11
|
|
|
class SecurityController extends Controller |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @Route("/login", methods={"GET"}) |
16
|
|
|
*/ |
17
|
|
|
public function loginAction() |
18
|
|
|
{ |
19
|
|
|
return $this->render(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @Route("/login", methods={"POST"}) |
24
|
|
|
*/ |
25
|
|
|
public function loginSubmitAction() |
26
|
|
|
{ |
27
|
|
|
$request = Registry::get('request'); |
28
|
|
|
$params = $request->getQueryParams(); |
29
|
|
|
|
30
|
|
|
if (array_key_exists('redirect', $params)) { |
31
|
|
|
return new RedirectResponse($params['redirect']); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return new RedirectResponse('/home'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @Route("/logout", methods={"GET"}) |
39
|
|
|
*/ |
40
|
|
|
public function logoutAction() |
41
|
|
|
{ |
42
|
|
|
return new RedirectResponse('/login'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @Route("/register", methods={"GET"}) |
47
|
|
|
*/ |
48
|
|
|
public function registerAction() |
49
|
|
|
{ |
50
|
|
|
User::clearExpiredConfirmations(); |
51
|
|
|
|
52
|
|
|
$qb = Registry::get('em')->createQueryBuilder(); |
53
|
|
|
$userCount = (int) $qb->select('COUNT(u)') |
54
|
|
|
->from('RssApp:User', 'u') |
55
|
|
|
->getQuery() |
56
|
|
|
->getSingleScalarResult(); |
57
|
|
|
|
58
|
|
|
return $this->render([ |
59
|
|
|
'registrationsEnabled' => (bool) (getenv('ENABLE_REGISTRATION') === 'true'), |
60
|
|
|
'availableAccounts' => ((int) getenv('REG_MAX_USERS') - $userCount) |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @Route("/register-feed", methods={"GET"}) |
66
|
|
|
*/ |
67
|
|
|
public function registerFeedAction() |
68
|
|
|
{ |
69
|
|
|
User::clearExpiredConfirmations(); |
70
|
|
|
|
71
|
|
|
$qb = Registry::get('em')->createQueryBuilder(); |
72
|
|
|
$userCount = (int) $qb->select('COUNT(u)') |
73
|
|
|
->from('RssApp:User', 'u') |
74
|
|
|
->getQuery() |
75
|
|
|
->getSingleScalarResult(); |
76
|
|
|
|
77
|
|
|
return $this->render([ |
78
|
|
|
'availableAccounts' => ((int) getenv('REG_MAX_USERS') - $userCount) |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @Route("/username-check/{username}", methods={"GET"}) |
84
|
|
|
*/ |
85
|
|
|
public function usernameCheckAction(string $username) |
86
|
|
|
{ |
87
|
|
|
$qb = Registry::get('em')->createQueryBuilder(); |
88
|
|
|
$checkCount = $qb->select('COUNT(u)') |
89
|
|
|
->from('RssApp:User', 'u') |
90
|
|
|
->where('u.login = :login') |
91
|
|
|
->setParameter(':login', strtolower(trim($username))) |
92
|
|
|
->getQuery() |
93
|
|
|
->getSingleScalarResult(); |
94
|
|
|
|
95
|
|
|
return $this->render([ |
96
|
|
|
'checkCount' => (int) $checkCount |
97
|
|
|
]); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|