97 $error = $this->translator->translate(
'registration:noname');
108 $results->fail(
'email', $email, $ex->getMessage());
114 $results->pass(
'password', $password);
116 $results->fail(
'password', $password, $ex->getMessage());
122 $results->pass(
'username', $username);
124 $results->fail(
'username', $username, $ex->getMessage());
177 $allow_multiple_emails = (bool)
elgg_extract(
'allow_multiple_emails', $params,
false);
178 $validated = (bool)
elgg_extract(
'validated', $params,
true);
183 $constructor = \ElggUser::class;
192 $user =
new $constructor();
203 if (!
$user->save()) {
211 $user->setNotificationSetting(
'email',
true);
214 $user->setValidationStatus(
true,
'on_create');
233 if (
elgg_strlen($username) < $this->config->minusername) {
234 $msg = $this->translator->translate(
'registration:usernametooshort', [$this->config->minusername]);
239 if (
strlen($username) > 128) {
240 $msg = $this->translator->translate(
'registration:usernametoolong', [128]);
249 if (preg_match_all(
'/[^\p{L}\p{M}\p{Nd}._-]+/iu', $username, $invalid_chars)) {
255 $blacklist2 =
'\'/\\
"*& ?#%^(){}[]~?<>;|¬`@+=,:'; 257 $blacklist2 = $this->events->triggerResults( 258 'username:character_blacklist', 260 ['blacklist' => $blacklist2], 264 for ($n = 0; $n < elgg_strlen($blacklist2); $n++) { 265 if (elgg_strpos($username, $blacklist2[$n]) !== false) { 266 $msg = $this->translator->translate('registration:invalidchars', [$blacklist2[$n], $blacklist2]); 267 $msg = htmlspecialchars($msg, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); 268 throw new RegistrationException($msg); 272 $result = $this->events->triggerResults( 273 'registeruser:validate:username', 275 ['username' => $username], 280 throw new RegistrationException($this->translator->translate('registration:usernamenotvalid')); 283 if ($assert_unregistered) { 284 $exists = elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, function () use ($username) { 285 return elgg_get_user_by_username($username); 288 if ($exists instanceof \ElggUser) { 289 throw new RegistrationException($this->translator->translate('registration:userexists')); 303 public function assertValidPassword(string|array $password): void { 305 if (is_array($password)) { 306 list($password, $password2) = $password; 308 if (empty($password) || empty($password2)) { 309 throw new RegistrationException(elgg_echo('RegistrationException:EmptyPassword')); 312 if (strcmp($password, $password2) != 0) { 313 throw new RegistrationException(elgg_echo('RegistrationException:PasswordMismatch')); 317 $result = $this->events->triggerResults( 318 'registeruser:validate:password', 320 ['password' => $password], 325 throw new RegistrationException($this->translator->translate('registration:passwordnotvalid')); 338 public function assertCurrentPassword(\ElggUser $user, string $password): void { 339 if (!$this->passwords->verify($password, $user->password_hash)) { 340 throw new RegistrationException($this->translator->translate('LoginException:PasswordFailure')); 353 public function assertValidEmail(string $address, bool $assert_unregistered = false): void { 354 if (!$this->isValidEmail($address)) { 355 throw new RegistrationException($this->translator->translate('registration:notemail')); 358 $result = $this->events->triggerResults( 359 'registeruser:validate:email', 361 ['email' => $address], 366 throw new RegistrationException($this->translator->translate('registration:emailnotvalid')); 369 if ($assert_unregistered) { 370 $exists = elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, function () use ($address) { 371 return elgg_get_user_by_email($address); 374 if ($exists instanceof \ElggUser) { 375 throw new RegistrationException($this->translator->translate('registration:dupeemail')); 387 public function isValidEmail(string $address): bool { 388 return filter_var($address, FILTER_VALIDATE_EMAIL) === $address; 400 public function requestNewEmailValidation(\ElggUser $user, string $email): bool { 401 if (!$this->isValidEmail($email)) { 402 throw new InvalidArgumentException($this->translator->translate('registration:notemail')); 405 $site = elgg_get_site_entity(); 407 $user->new_email = $email; 409 $url = elgg_generate_url('account:email:confirm', [ 410 'guid' => $user->guid, 412 $url = elgg_http_get_signed_url($url, '+1 hour'); 414 $notification = Email::factory([ 416 'to' => new Address($email, $user->getDisplayName()), 417 'subject' => $this->translator->translate('email:request:email:subject', [], $user->getLanguage()), 418 'body' => $this->translator->translate('email:request:email:body', [ 419 $site->getDisplayName(), 421 ], $user->getLanguage()), 424 return $this->email->send($notification); 435 public function registerAuthenticationFailure(\ElggUser $user): void { 436 $fails = (int) $user->authentication_failures; 439 $user->authentication_failures = $fails; 440 $user->{"authentication_failure_{$fails}
"} = time(); 451 public function resetAuthenticationFailures(\ElggUser $user): void { 452 $fails = (int) $user->authentication_failures; 457 for ($n = 1; $n <= $fails; $n++) { 458 unset($user->{"authentication_failure_{$n}
"}); 461 unset($user->authentication_failures); 474 public function isAuthenticationFailureLimitReached(\ElggUser $user, int $limit = null, int $lifetime = null): bool { 475 $limit = $limit ?? $this->config->authentication_failures_limit; 476 $lifetime = $lifetime ?? $this->config->authentication_failures_lifetime; 478 $fails = (int) $user->authentication_failures; 479 if (empty($fails) || $fails < $limit) { 484 $min_time = time() - $lifetime; 485 for ($n = $fails; $n > 0; $n--) { 486 $failure_timestamp = $user->{"authentication_failure_{$n}
"}; 487 if ($failure_timestamp > $min_time) { 491 if ($failure_count === $limit) {
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
elgg_get_entity_class(string $type, string $subtype)
Return the class name registered as a constructor for an entity of a given type and subtype...
$params
Saves global plugin settings.
__construct(Config $config, Translator $translator, PasswordService $passwords, EventsService $events, EmailService $email, PasswordGeneratorService $password_generator)
Constructor.
Elgg registration action.
if(!$user||!$user->canDelete()) $name
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Represents a set of validated parameters.
validateAccountData(string $username, string|array $password, string $name, string $email, bool $allow_multiple_emails=false)
Validate registration details to ensure they can be used to register a new user account.
assertValidEmail(string $address, bool $assert_unregistered=false)
Simple validation of a email.
assertValidUsername(string $username, bool $assert_unregistered=false)
Simple function which ensures that a username contains only valid characters.
Could not register a new user for whatever reason.
assertValidPassword(string|array $password)
Simple validation of a password.
elgg_strlen()
Wrapper function for mb_strlen().
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
if(!$user||!$user->canEdit()) $password
const ELGG_SHOW_DISABLED_ENTITIES
Password generator service.
assertValidAccountData(string $username, string|array $password, string $name, string $email, bool $allow_multiple_emails=false)
Assert that given registration details are valid and can be used to register the user.