|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RssApp\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use RssApp\Components\Registry; |
|
9
|
|
|
use RssApp\Components\Response\ErrorJson; |
|
10
|
|
|
use RssApp\Components\Response\SuccessJson; |
|
11
|
|
|
use RssApp\Components\Textcha; |
|
12
|
|
|
use RssApp\Components\User; |
|
13
|
|
|
use RssApp\Controller; |
|
14
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
15
|
|
|
|
|
16
|
|
|
class RegistrationController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @Route("/register", methods={"GET"}) |
|
20
|
|
|
*/ |
|
21
|
|
|
public function registerAction() |
|
22
|
|
|
{ |
|
23
|
|
|
User::clearExpiredConfirmations(); |
|
24
|
|
|
|
|
25
|
|
|
$qb = Registry::get('em')->createQueryBuilder(); |
|
26
|
|
|
try { |
|
27
|
|
|
$userCount = $qb->select('COUNT(u)') |
|
28
|
|
|
->from('RssApp:User', 'u') |
|
29
|
|
|
->getQuery() |
|
30
|
|
|
->getSingleScalarResult(); |
|
31
|
|
|
} catch (Exception $e) { |
|
32
|
|
|
dump($e); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return $this->render([ |
|
36
|
|
|
'registrationsEnabled' => (bool) (getenv('ENABLE_REGISTRATION') === 'true'), |
|
37
|
|
|
'availableAccounts' => ((int) getenv('REG_MAX_USERS') - $userCount), |
|
38
|
|
|
'captchaQuestion' => Textcha::getQuestion() |
|
39
|
|
|
]); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @Route("/register", methods={"POST"}) |
|
44
|
|
|
*/ |
|
45
|
|
|
public function registerSubmitAction() |
|
46
|
|
|
{ |
|
47
|
|
|
$params = Registry::get('request')->getParsedBody(); |
|
48
|
|
|
|
|
49
|
|
|
if (User::usernameExists($params['username'])) { |
|
50
|
|
|
return new ErrorJson($params, Registry::get('trans')->trans('Sorry, this username is already taken.')); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return new SuccessJson(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @Route("/register-feed", methods={"GET"}) |
|
58
|
|
|
*/ |
|
59
|
|
|
public function registerFeedAction() |
|
60
|
|
|
{ |
|
61
|
|
|
User::clearExpiredConfirmations(); |
|
62
|
|
|
|
|
63
|
|
|
$qb = Registry::get('em')->createQueryBuilder(); |
|
64
|
|
|
$userCount = (int) $qb->select('COUNT(u)') |
|
65
|
|
|
->from('RssApp:User', 'u') |
|
66
|
|
|
->getQuery() |
|
67
|
|
|
->getSingleScalarResult(); |
|
68
|
|
|
|
|
69
|
|
|
return $this->render([ |
|
70
|
|
|
'availableAccounts' => ((int) getenv('REG_MAX_USERS') - $userCount) |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @Route("/username-check/{username}", methods={"GET"}) |
|
76
|
|
|
*/ |
|
77
|
|
|
public function usernameCheckAction(string $username) |
|
78
|
|
|
{ |
|
79
|
|
|
if (User::usernameExists($username)) { |
|
80
|
|
|
return new ErrorJson([], Registry::get('trans')->trans('Sorry, this username is already taken.')); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return new SuccessJson([], Registry::get('trans')->trans('This username is available.')); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|