Elgg  Version master
RegistrationAllowedGatekeeper.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Router\Middleware;
4 
6 use Elgg\Request;
7 
16 
25  public function __invoke(Request $request): void {
26  if ($this->validateInviteCode($request)) {
27  return;
28  }
29 
31  }
32 
42  protected function validateInviteCode(Request $request): bool {
43  $friend_guid = (int) $request->getParam('friend_guid');
44  $invitecode = $request->getParam('invitecode');
45 
46  if (empty($friend_guid) || empty($invitecode)) {
47  return false;
48  }
49 
50  $friend = get_user($friend_guid);
51  if (!$friend instanceof \ElggUser) {
52  return false;
53  }
54 
55  if (elgg_validate_invite_code($friend->username, $invitecode)) {
56  return true;
57  }
58 
59  throw new RegistrationAllowedGatekeeperException(elgg_echo('RegistrationAllowedGatekeeperException:invalid_invitecode'));
60  }
61 
68  protected function assertRegistrationEnabled(): void {
69  if (_elgg_services()->config->allow_registration) {
70  return;
71  }
72 
74  }
75 }
Request container.
Definition: Request.php:12
Validate that registration is allowed based on one of the following:
validateInviteCode(Request $request)
Validate the optional invite code.
__invoke(Request $request)
Validate input and/or settings to allow access to registration resources.
assertRegistrationEnabled()
Validate if registration is allowed by the site configuration.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
elgg_validate_invite_code(string $username, string $code)
Validate a user's invite code.
Definition: users.php:198
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$request
Definition: livesearch.php:12
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
$invitecode
Definition: register.php:13
$friend_guid
Assembles and outputs the registration page.
Definition: register.php:12